Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

64 lines
2.2 KiB
Python

"""
Function facade for sandbox warming.
Callers decide when to warm and own their product-specific Task linkage, while
products/tasks owns quota checks, warm-pool capacity, Run creation, and workflow
dispatch. The boundary is function-shaped and returns DTOs, so callers do not
instantiate internal service classes or receive ORM models.
"""
from typing import Any
from uuid import UUID
from insights.models.team import Team
from insights.models.user import User
from products.tasks.backend.facade import contracts
from products.tasks.backend.logic.services.warm import SandboxWarmer, WarmResult
from products.tasks.backend.models import Task
__all__ = [
"enforce_warm_quota",
"warm_pool_at_capacity",
"warm_task_run",
]
def _team_and_user(team_id: int, user_id: int) -> tuple[Team, User]:
return Team.objects.get(pk=team_id), User.objects.get(pk=user_id)
def _warm_result_to_dto(result: WarmResult) -> contracts.WarmRunDTO:
return contracts.WarmRunDTO(
task_id=result.run.task_id,
run_id=result.run.id,
run_status=result.run.status,
just_created=result.just_created,
)
def enforce_warm_quota(origin_product: str, team_id: int, user_id: int) -> None:
"""Raise if the team may not warm a sandbox run for the origin product."""
team, user = _team_and_user(team_id, user_id)
SandboxWarmer.enforce_quota(origin_product, team, user)
def warm_pool_at_capacity(origin_product: str, team_id: int, user_id: int) -> bool:
"""Whether the user or organization already holds the max concurrent warm runs."""
team, user = _team_and_user(team_id, user_id)
return SandboxWarmer.at_capacity(origin_product, team, user)
def warm_task_run(
task_id: str | UUID,
team_id: int,
user_id: int,
*,
mode: str = "interactive",
extra_state: dict[str, Any] | None = None,
) -> contracts.WarmRunDTO:
"""Idempotently ensure a task has a warm run and return the run handle as a DTO."""
task = Task.objects.select_related("team").get(id=task_id, team_id=team_id)
user = User.objects.get(pk=user_id)
return _warm_result_to_dto(SandboxWarmer(task, user=user).warm(mode=mode, extra_state=extra_state))