Skip to content

fix(platform): fail a step whose workspace is being destroyed - #4144

Merged
yannickmonney merged 2 commits into
mainfrom
fix/destroy-pending-step-fails-not-waits
Oct 3, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
fix/destroy-pending-step-fails-not-waits

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The defect (#4122, a MEDIUM regression on main since #4099). While an administrator's Destroy of a session is queued, retrying or running, admission refuses the session's next start with SandboxDestroyPendingError (#4095).

  • quotaAsAppError flattened that refusal into the QUOTA_EXCEEDED that a spent budget throws.
  • So classifyWorkflowStartFailure read it as organization room. The step re-kicked for up to two hours with the false reason "the organization's workflow sessions are all in use".
  • Once the Destroy settled, the step reserved a fresh row and continued the run in an empty workspace. The files and transcripts of the earlier steps were gone.

The fix:

  • Marker. SandboxQuotaError carries an optional reason. SandboxDestroyPendingError sets it to destroy_pending, and quotaAsAppError keeps it in the AppError payload (data.reason). The constant and the Destroy sentence now live in core/sandbox/session_constants.ts.
  • Classifier. capacity_refusal.ts reads a quota refusal in all three shapes it arrives in: AppError data, the domain error's own fields, and a wrapped message. It tells destroy_pending apart from a spent budget. sandboxCapacityRefusal no longer returns organization room for it, and the new isDestroyPendingRefusal names it.
  • Automation lane. The start and the answered-ask resume fail at once with the Destroy's own words: the agent turn could not start: An administrator is deleting this sandbox workspace. …. There is no room wait, no retryAtMs, and no undelivered-ask carry-over.
  • Task lane. agent_run_host.ts parks on the refusal explicitly, so its behaviour is unchanged: the run waits until the Destroy settles.

Decision (accepted by the manager, routine). The step settles with a new retry-only node code, sandbox_destroying.

  • It is in NO_RETRY_FAILURE_CODES, so it is never retried or resumed.
  • AGENT_RETRY_ONLY_CODES reports it as start_failed, so Run.failureCode reads start_failed and the OpenAPI enum doesn't move.
  • Plain start_failed would not be enough: it retries three times with no wait between attempts. A retry that lands after the Destroy settled would again continue in an empty workspace.

Docs and register. The code, sessions.ts, EN/DE/FR sandboxes.md and register row automation.md:170 now agree.

  • Destroy row (:68): the step fails at once, without waiting or retrying.
  • Room-wait bullet (:108): a workspace being destroyed is no lack of room.
  • LOW, disk wording (:105): stopping idle work frees no disk space. Tale removes build caches no session uses; otherwise the start waits until workspaces are deleted or the operator frees space.

Finding → commit → test

Finding Commit Test (fails on main 1ba77ed → passes at head)
MEDIUM: Destroy refusal read as organization room f33bdc6 capacity_refusal.test.ts: "reads a pending Destroy as no want of room, in every shape it arrives in"
MEDIUM: false reason and room wait at the start f33bdc6 agent_host.start_gate.test.ts: "fails a start whose workspace an administrator is destroying …"; agent_host.context_window.test.ts: the real start and the answered-ask resume
MEDIUM: stepper re-kicks for 2 h f33bdc6 stepper.agent-retry.test.ts: "fails a step whose workspace an administrator is destroying at once, neither waiting for room nor retrying"; agent_retry.test.ts, failure.test.ts
Marker through quotaAsAppError f33bdc6 agent-turn-shim.destroy-pending.test.ts: both slot verbs on a Destroy-pending row, through the real shim, sessions domain and classifiers
Keep the task lane's parking f33bdc6 agent_run_host.context_window.test.ts: "parks a start whose workspace an administrator is destroying …" (a regression lock: passes on main too)
End to end: an empty-workspace continuation f33bdc6 backend:integration, new lane checkAutomationStepDestroyPending
LOW: disk wording 807a958 docs locale and prose suites

Verification

Unit tests:

  • On main with only the new test files copied in: 12 of the new checks fail; the task-lane lock passes. For example:
    • the classifier returns sandbox_capacity with "the organization's workflow sessions are all in use";
    • the stepper kicks again with notBefore.
  • At head, all eight touched suites pass, 116 tests in total.
  • The 35 test files that import the changed modules pass at head, 374 tests in total.

Real-Postgres lane (local PostgreSQL 16 + pgvector, ITEST_LANES=checkAutomationStepDestroyPending, fresh databases, no object store needed):

  • head (807a95888, clean worktree):
    PASS … first step running=true, destroy=202, pending=true; 1770 ms after the first step ended: run=failed/start_failed "publish: the agent turn could not start: An administrator is deleting this sandbox workspace. …", Destroy still pending then=true; Destroy settled=true, then run=failed, session rows=destroyed (no fresh incarnation), spawner creates=1 execs=1

  • main + the lane:
    FAIL … 1694 ms after the first step ended: run=waiting/- "room:publish", Destroy still pending then=true; Destroy settled=true, then run=success, session rows=destroyed,stopped, spawner creates=2 execs=2

    On main the second step waited for room, then ran in a fresh, empty workspace.

  • The only other local failure is the known knowledge BM25 indexes verified at boot check. pg_search is absent locally; the same check fails on main.

Exact-head CI (807a95888): 51 pass, 11 skipping, 0 fail.

  • Backend integration (job 111223659804) ran the new lane: PASS automation step: a pending Destroy of the run's workspace … 1623 ms after the first step ended: run=failed/start_failed … session rows=destroyed … creates=1 execs=1. Total: 1504/1504 checks passed across 223/223 lanes, with ITEST_REQUIRE_ALL_LANES=1.
  • Unit (job 111223058608) executed the new suites; this was no cache replay. For example: stepper.agent-retry.test.ts (17 tests), agent-turn-shim.destroy-pending.test.ts (4) and capacity_refusal.test.ts (6).
  • Skipped: the fork-PR variants of Validate images and Smoke test, the 4 Candidate gates, the AI gateway, UI docs and Web container tests (none of their paths changed), and Trivy.

Static gates:

  • oxfmt --check and oxlint --type-aware on the changed files;
  • an isolated tsc --noEmit of the changed files, integration-check.ts included;
  • bun run knip:check;
  • bun run lint:manual;
  • the integration-scope, integration-skips and SSRF guards;
  • services/docs locale, prose and link suites.

Recorded, not changed

LOW: a front waiter can lose its place in the spawner's line. I confirmed the mechanism from source; I did not execute it.

  • The spawner drops a waiter that has not asked again within 2 × hint + 15 s. For the front waiter that is 25 s (waitersAhead, QUEUE_FRONT_HINT_MS, QUEUE_LIVE_SLACK_MS in session-routes.ts).
  • The platform's re-kick, or a task run's queued wake, is a job on the start queues. Each worker runs these on AGENT_START_SLOTS one-job slots.
  • A start that launches holds its slot through the session create (runnerd readiness alone is allowed 180 s) and its first 90 s drive window (DRAIN_WINDOW_MS). So under load a due re-kick can wait past 25 s, then rejoin at the back of the line.
  • The effect is fairness and latency, not data. I'd suggest a follow-up, either:
    • measure a waiter's liveness from its hint's due time plus the platform's start latency; or
    • let a start keep its place while it is queued.

Nit, out of scope: a script node that meets a pending Destroy fails, as before, but with the serialized payload as its detail (script_host.ts → ensureWorkflowSession).

Overlap: #4094 edits other lines of the same docs and register files. Whichever merges second resolves the textual conflict.

Closes #4122

While an administrator's Destroy of a session is queued, retrying or
running, its admission refuses the next start (SandboxDestroyPendingError,
#4095). The shims flattened that refusal into the QUOTA_EXCEEDED a spent
budget throws, so since #4099 the automation lane read it as a wait for
room: the step re-kicked for up to two hours with the false reason "the
organization's workflow sessions are all in use", and once the Destroy had
settled it reserved a fresh row and continued the run in an empty
workspace, without the files and transcripts of its earlier steps.

The refusal now carries reason: 'destroy_pending' through quotaAsAppError,
and capacity_refusal reads it apart from a spent budget in every shape a
quota refusal arrives in. An automation step's start, and an answered
question's resume, fail at once with the Destroy's own words under the new
node code sandbox_destroying: never retried, since a retry after the
Destroy would start over in an empty workspace, and reported as
start_failed on the wire (AGENT_RETRY_ONLY_CODES), so the OpenAPI enum does
not move. A task's run still parks on it until the Destroy settles.

Tests: the classifier in every shape, classifyWorkflowStartFailure, the
real hosts' start and answered-ask resume, the stepper (no re-kick, the run
fails start_failed with the reason), the shim's marker on both slot verbs,
the task lane's parking, and the real-Postgres lane
checkAutomationStepDestroyPending: a two-step run whose workspace is
destroyed during its first step fails its second with the Destroy's reason
while the Destroy is pending, and nothing starts in the run once it has
settled. On main the same lane reads the run waiting for room, then
finishing in a fresh incarnation. The Sandboxes guide (EN/DE/FR), the
sessions doc comment and the manual register say the same.
The Sandboxes guide said a start that waits for room needs nothing from
the administrator, disk space included. Stopping idle work frees no disk,
because a stopped workspace keeps its files for its resume
(session-routes.ts): the spawner removes build caches no session uses,
and otherwise the start waits until workspaces are deleted or the
operator frees space. EN/DE/FR now say so; limits, a full deployment and
memory still clear on their own.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4144 at 807a95888b5b7a55f41a1df34c032d60621615ab: accepted, with LOW/INFO follow-ups.

Runtime (mine; real PG 16.14)

Tree checkAutomationStepDestroyPending
head PASS. run=failed/start_failed with "…An administrator is deleting this sandbox workspace…"; session rows=destroyed, no fresh incarnation; spawner creates=1 execs=1, so the second step never ran.
main 1ba77ed61 + the head's integration-check.ts FAIL, which is the #4099 MEDIUM exactly: run=waiting "room:publish", then run=success; session rows=destroyed,stopped; creates=2 execs=2.
local composition: main 9fa2bf23e + #4144 + #4145 passes (29/30 with the bell, RAG and collab lanes; BM25 only)

Source, cross-checked with one read-only reviewer

  • Every caller handles a Destroy-pending refusal before any room wait.
    • The callers are the start (agent_host.ts:1270/1276), the answered-ask resume (:2234/2237) and the task lane (agent_run_host.ts:1479-1480).
    • In each, isDestroyPendingRefusal runs before sandboxCapacityRefusal, and the latter returns null for the marker. A real host refusal and a spent budget behave as before.
  • The resume doesn't lose the answer silently: the ask stays answered, and the run fails with "could not resume after the answer: …".
  • Scoping: the marker is keyed by organization, session id and a live row (plus the row id on resume). Workflow session ids are unique per run, so no step fails for another workspace's Destroy.
  • Wire: sandbox_destroying reads start_failed, AGENT_RETRY_ONLY_CODES is checked for completeness at compile time, and the OpenAPI enum is unchanged. The only UI that switches on codes is the task lane.
  • Mutants: removing the marker from sandboxCapacityRefusal, sandbox_destroying from the no-retry set, the resume check, or the third shape: each is killed by the unit tests.

LOW

  • The wrapped-message shape is a substring match (capacity_refusal.ts:102-105). A message that merely contains QUOTA_EXCEEDED and "reason":"destroy_pending" classifies as a Destroy. That could be a staging error naming a user-uploaded file with such a name (agent_host.ts:1023,1031-1034), and its only effect is a misleading reason.
    • That shape may be dead in 0.5: the ctx shim passes the AppError instance through.
    • Fix: parse the JSON and read code and reason from it.

INFO

  1. Not in Follow-ups from the #4099 review: a pending Destroy turns an automation step into a 2-hour wait, then runs it in an empty workspace #4122's scope, and older than this PR: a Destroy that has already settled still lets the run continue in a fresh, empty workspace. The drive sees the session gone, session_gone is re-kicked at once (stepper.ts:1281), and admission is open again. The docs (sandboxes.md:68) describe that.
    • Follow-up: an incarnation check. When a run that already used its workspace gets a fresh one, fail the step.
  2. The lane can't tell "never retried" from "three instant retries". All three would meet the pending Destroy. The unit tests kill both mutants; asserting !detail.includes('attempts') in the lane would pin it there too.
  3. The step's text reads like a wait ("No new work starts in it until the deletion has finished"), with no hint to start the automation again. It is English-only in DE/FR, like every run detail.
  4. The front-waiter LOW you confirmed is consolidated by the manager into Follow-ups from the #4098 review: an explicit SANDBOX_MAX_SESSIONS still refuses on host memory, the waiter line drops slow askers, disk relief can pause for 6 h #4124's MEDIUM 2.

Docs: EN/DE/FR sandboxes.md :68/:105/:108 agree with each other and with the code. Register row automation.md:170 is accurate.

Whole-PR CI at the exact head (merge ref d1623cc, onto 1ba77ed61)

  • Workflows: all five ran at attempt 1 and succeeded: Checks 37129925629, Build 37129925713, E2E 37129925647, SAST 37129925646 and Commitlint 37129925979.
  • Check runs: 51 success, 10 skipped by design and Trivy neutral.
  • Backend integration (job 111223659804): 1504/1504 across 223/223 lanes.

Merge: squash with --match-head-commit through my gate, which dry-runs first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-ups from the #4099 review: a pending Destroy turns an automation step into a 2-hour wait, then runs it in an empty workspace

1 participant