Skip to content

refactor(api): move team-run orchestration out of the HTTP handlers (#446) - #523

Merged
mkluiver merged 3 commits into
mainfrom
refactor/446-team-orchestration
Nov 26, 2026
Merged

mkluiver merged 3 commits into
mainfrom
refactor/446-team-orchestration

Conversation

@mblaauw

@mblaauw mblaauw commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #446. Draft: merge last. Rebase this after the open PRs that touch the moved code; that is less work than rebasing them onto this.

Summary

A refactor with no behaviour change, in three commits. The full workspace tests pass after each one.

Commit Step Full workspace tests
509b48e Move team-run orchestration, launches, delivery and worker-token issuing out of handlers/ into team_runs.rs, launches.rs, output_delivery.rs and worker_tokens.rs (verbatim, plus paths and pub(crate) on 9 shared helpers) 768 passed, 0 failed
034a932 One background preflight (preflight::evaluate_background → Allowed / Denied / Delayed) for trigger fires, runtime ticks and team steps; each caller keeps its own reaction 768 passed, 0 failed
76a4bf9 Team create and update share validate_team_request (the 179 identical lines) 768 passed, 0 failed

Acceptance criteria:

  • grep -rn "handlers::" crates/orbit-api/src outside handlers/ matches only routes.rs, lib.rs and openapi.rs. openapi.rs has to name the handlers to document them.
  • One function builds the background preflight. The issue counted five copies. Manual execute/rerun and runtime start have an HTTP caller and keep Preflight with the caller's identity; queue starts go through authorize_team_run and the team step.
  • One team validation function.
  • No test changed except import paths.

No changelog fragment: CONTRIBUTING asks for one only for changes users or operators notice. Docs: docs/architecture/agent-teams.md ("where the code lives") and three paths in docs/security/threat-analysis.md. No bugs were found while moving the code.

Testing

  • After every commit: cargo fmt --check, clippy --workspace --all-targets -D warnings, cargo test --workspace on its own database, pnpm api:generate --check (no OpenAPI change), pnpm docs:check

Conflicts with open PRs

PR Conflict How hard
#515 (#393) handlers/teams.rs Move-only (now team_runs.rs)
#517 (#433) handlers/teams.rs Mostly move-only (start_step_with); its background.rs hunks merge clean next to the new preflight match
#502 (#436) background.rs Real: edits the runtime-tick preflight block step 2 rewrote. Its is_transient() retry goes at the start of the Denied arm, and logged(...) goes around the halt and advance writes
#504 (#438) handlers/teams.rs Real but mechanical: name validation changed in both copies; apply it once in validate_team_request
#501 (#399) handlers/worker_launches.rs Move-only (now launches.rs)
#505 (#445) handlers/outputs.rs Move-only (now output_delivery.rs)
#522 (#394) handlers/teams.rs, handlers/worker_launches.rs Move-only

🤖 Generated with Claude Code

mblaauw and others added 3 commits November 25, 2026 20:38
… of handlers (#446)

Background loops called into HTTP handlers (handlers::teams::advance, reconcile_team_outcomes,
fail_team_run_for_execution, worker_launches::*, outputs::deliver_pending) and
dispatcher/team_outcomes/team_workflow imported handler types. The code moves verbatim
into non-handler modules; only paths and a few visibilities change:

- team_runs.rs: TeamDefinition and friends, parse_definition, the repository rules,
  step starts (start_step_with and its helpers), the run state machine (advance, finalize,
  fail_team_run_for_execution, reconcile_team_outcomes) and queue-item starts.
- launches.rs: launcher calls, launch refresh, terminated-launch handling,
  launch_profile_internal and stop_launch_internal.
- output_delivery.rs: sending (webhook, Slack, Mattermost, Telegram) and the delivery queue.
- worker_tokens.rs: IssuedWorkerToken and issue_profile_token.

Outside handlers/, only routes.rs, lib.rs and openapi.rs (route documentation) name
handlers. No behaviour, status code or OpenAPI change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cks and team steps (#446)

The three starts without an HTTP caller each wrote out background_access, Preflight,
authorize_access, require_harness_available and require_hourly_quota (team steps also
the team-use check). preflight::evaluate_background now runs that sequence once and
returns a BackgroundVerdict (Allowed, Denied, Delayed with HarnessUnavailable or
HourlyQuota). Each caller keeps its own reaction: a trigger audits and fails on Denied
and skips the tick on Delayed, a runtime audits and halts or delays, a team step returns
the error. Checks, their order and the errors are unchanged. Request paths (execute,
rerun, runtime start) keep using Preflight with the request identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…446)

create_team and replace_team repeated the same 179 lines, from prepare_mode through the
stored definition builder. validate_team_request now does that once and returns the
definition with the autonomy elevations to audit; the store call and audit entry stay
in each handler. Messages, field paths and the order of checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mkluiver added a commit that referenced this pull request Nov 26, 2026
@mkluiver
mkluiver merged commit 4c418e2 into main Nov 26, 2026
15 checks passed
mkluiver added a commit that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants