Skip to content

fix(platform): wait for sandbox room instead of failing the run - #4099

Merged
yannickmonney merged 31 commits into
mainfrom
fix/sandbox-capacity-waits
Oct 3, 2026
Merged

yannickmonney merged 31 commits into
mainfrom
fix/sandbox-capacity-waits

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Why

With sandbox capacity full, work failed instead of waiting. The spawner answers 429 when its host is at capacity (and, with the spawner PR, short of memory or of disk space on the workspaces' disk); nothing on the platform matched it, so a task run burned its three immediate retries on the same refusal and failed, an automation's agent step failed the run, and a crawl errored. An automation's agent step also failed outright when the organization's workflow sessions were all in use, where a task run parks. And a worker drained at most five live agent turns at once: starts and 90 s drive windows ran as batches awaited whole.

Lands after #4098 (spawner), which adds the host_memory and host_disk refusals this one also waits on (any 429 is a wait here, so neither needs code of its own; the admin guide names both); the session-cap 429 exists on main already. The runtime half is #4097.

What changes

  • No room is a wait, not a failure (capacity_refusal.ts): an organization budget refusal or a spawner 429 parks a task run (woken on a release edge, or by the watchdog, which now wakes up to four parked runs per organization a tick); an automation's agent step settles as sandbox_capacity and is re-kicked once the refusal's retry hint has passed, spending no attempt and no execution of the run-wide guard, and ends after two hours with a reason that says it waited that long for room (start_failed on the wire, so the OpenAPI enum does not move); a render becomes the capacity wait the crawl already polls through.
  • A waiting run keeps its standing workspace. A refused create made nothing, so its failure path no longer destroys (for an id with no compute that deleted the preserved workspace); parking frees the agent's slot back to stopped without waking a turn. Proven on real Postgres.
  • Room waits stay out of the harness-turn metrics (awaiting_room, counted as no outcome); the answered-question resume path treats a room refusal as the same wait.
  • A render whose destroy failed keeps its live row for the watchdog's release pass, and a definitive gone settles it at once instead of holding one of the organization's two render slots.
  • Agent starts and drive windows run as independent slots, drives at least 16 at once per worker (idle poll every 10 s; inserts wake them); a drive window holds no database connection while it waits on the stream. Docs (EN/DE/FR) describe the per-queue slots and the room-wait bound.

Hardening after a contention review

  • Fair wakes. The watchdog wakes per organization (every organization with a parked run, oldest park first), and every release edge also wakes the oldest parked run of the other organizations, so host room freed anywhere reaches every tenant. Automation room waits back off with jitter from the refusal's retry hint up to 2 minutes.
  • A refused create leaves nothing to collect. A 429-refused row is settled with destroyed_at_ms, so the cleanup pass never destroys the id (a preserved standing workspace included), and the render lane no longer runs a destroy on a 429.
  • Waits stay out of the numbers. External-turn metrics and harness health leave out awaiting_room/awaiting_human in SQL, before the 5,000-row cap.
  • No wake at automation teardown. A workflow's teardown only marks its rows stopped; the host room frees later, when the spawner stops the released compute, and a host-parked task run now has its own timed wake, so no extra edge is added there.
  • No duplicate drive chains. Recovery re-attaches a silent turn only when no drive job of that exec is queued or recently started.
  • Answered questions survive a wait. A wait's start time ends once a start launches, and a resume refused for room keeps the asking conversation and its answer.
  • Come back when the host says. With fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098's first-come line, a 429 names the start's place: an automation step re-kicks at that hint (and at most a second more) instead of backing off, a task run the host refused is parked with one task.agent_park_wake job at the hint (it restarts that run once, and does nothing if it was woken otherwise), and a crawl's render polls at the hint (5–60 s). An organization's own budget and an older host keep the earlier pacing.
  • Waiting leaves no rows behind. The sandbox watchdog deletes awaiting_room op rows an hour after they ended (each session's newest kept; never one that minted a key) and failed session rows a day after they were collected (a start at the front of the line asks every few seconds), in bounded batches; migration 0148 adds the partial index the op sweep uses.
  • Agent slots per worker are settable. AGENT_START_SLOTS (default WORKER_CONCURRENCY, at least 8) and AGENT_DRIVE_SLOTS (at least 16) per lane; the env reference says a worker drains about 2.5 × drive slots live turns per lane. The first 90 s window stays in the start job: handing it to a drive job would close the exec stream at once and lean on the replay ring from the first second.
  • The run says it waits. A waiting step parks as room:<node>; the run list, timeline and agent log say "Waiting for a sandbox slot" (en/de/fr). REST contract 3.14.0 (waitingFor: room).

Verification

  • New tests: capacity_refusal.test.ts, classifyWorkflowStartFailure, retry plan/resume for sandbox_capacity and its two-hour bound, the wire mapping, the metrics outcome, render capacity and failed-destroy, watchdog wakes, worker slots; real-Postgres lane checkTaskAgentRuns 19/19 including the new park-frees-the-slot check. Touched suites green; platform typecheck and lint clean; full server suite green except two timing-sensitive files that fail only under machine load and pass in isolation on this branch and on main.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review of PR #4099 at 493583378a182d3b883bb8f206c0e0be2621e276: changes required (3 MEDIUM).

MEDIUM 1: with #4095 now on main, a pending Destroy turns into an automation "wait for room".

  • Where: capacity_refusal.ts:32-34,42-56 reads any QUOTA_EXCEEDED as organization room, and the start catch uses it (agent_host.ts:1240-1259,1593). fix(platform): refuse new work in a sandbox being destroyed #4095's SandboxDestroyPendingError extends SandboxQuotaError, and quotaAsAppError (agent-turn-shim.ts:67-70) flattens it to AppError{code:'QUOTA_EXCEEDED'} with nothing to tell it apart.
  • What happens: while an administrator's Destroy ladder runs, which can be 15–30 min, a workflow step is refused at resume.
    • It settles sandbox_capacity with the false reason "the organization's workflow sessions are all in use".
    • It is re-kicked about every 15 s for up to 2 h.
    • Once the Destroy settles, it runs mid-run in an empty workspace, without the earlier nodes' files.
  • The docs now disagree: in EN, DE and FR sandboxes.md, fix(platform): refuse new work in a sandbox being destroyed #4095's line says the step "fails with the reason", while fix(platform): wait for sandbox room instead of failing the run #4099's line 105 says it waits. fix(platform): refuse new work in a sandbox being destroyed #4095's SET-B30 register row says the step fails.
  • Fix: carry a marker through quotaAsAppError (data.reason: 'destroy_pending' or a distinct code), decide the lane's semantics, and align the docs.
  • Test: classifyWorkflowStartFailure on a shim-shaped destroy-pending AppError, plus a stepper case.

MEDIUM 2: when an answered question's resume is refused for room, the operator's answer is lost.

  • The lost answer:
    • agent_host.ts:2177-2202 settles sandbox_capacity under the asking exec's cursor.
    • workflowAgentRetryResume (agent_retry.ts:117-125, from stepper.ts:1281) then resumes parked.resumedFrom with the stale resumeReason.
    • Answered asks are folded into the prompt only when there is no resume (agent_host.ts:1509-1539).
    • So the re-kick resumes the old conversation with "do not ask again what was answered", and the answer is never delivered.
    • On main, this case settled resume_failed, which re-kicks fresh with the answers folded in.
  • The stale wait stamp: waitingForRoomSince survives launch and retarget, because the cursor is spread (automations/shim.ts:508,804). If an earlier wait began more than 2 h ago, agent_retry.ts:240 fails the run at once with "waited 120 minutes…" without waiting at all.
  • Fix:
    • re-schedule the answered-ask resume after retryAtMs instead of re-kicking it;
    • clear waitingForRoomSince in stampAgentTurnLaunch;
    • add tests for both.

MEDIUM 3: room-wait re-kicks still count as failures.

  • Harness health: every refused start settles its op failed (agent_host.ts:2515). /harness-health (routes.ts:284-321) counts status='failed', so a step waiting 30 min (about 100 ops) turns on the Providers page's "Recently failing" badge.
  • Metrics: the metrics query takes the newest 5000 ops (routes.ts:193) before dropping parked in JS (:212). Long waits push real turns out of that window, and capped stays false.
  • The PR's own claim: this contradicts the PR's claim that waits stay out of the metrics. Its tests cover only classifyOutcome.
  • Fix: filter awaiting_room in SQL for both queries.

LOW

  • A compute-less active workflow row is kept for up to 2 h. During a host-scope wait, hibernateAutomationScopedSession(onlyIdle) never stops a live run's row (idle-release.ts:91-95). The row holds a workflow slot, the usage reads at-limit, and the reconcile can heal it to destroyed. 536dc7e fixed this for the task lane only.
  • COLLECT can still delete the workspace of a run refused with 429. It does so after 10 min (watchdogs.ts:540-575) when the run isn't retried in time: more than 20 parked runs at 4 wakes per tick. Suggest stamping such rows.
  • Fairness and docs:
    • "Tried again at least every two minutes" is false beyond 4 parked runs per organization (watchdogs.ts:137-147).
    • A re-park resets waiting_for_capacity_at_ms, which sends the oldest runs to the back.
    • Automation re-kicks every 10–30 s, and crawl polls, out-compete parked task runs, which wait up to 2 min.
    • execution-logs.md doesn't mention room waits.
  • UX and accessibility: an automation waiting for room shows no wait status. Its log alternates between "The agent is starting up…" and "The agent produced no log for this run." for up to 2 h.

Checked and correct:

  • Every spawner 429 is answered before createSession.
  • SandboxQuotaError is the only QUOTA_EXCEEDED thrower.
  • Wakes are single-winner (FOR UPDATE SKIP LOCKED), and parked runs are bounded by park_deadline.
  • Agent-turn queues have retryLimit 0.
  • The 2 h bound and the execution-guard bypass work as described.
  • There are no new i18n keys, and the EN/DE/FR paragraphs agree with each other, apart from fix(platform): refuse new work in a sandbox being destroyed #4095's line above.

Repairs go through the manager. I'll re-review the next exact head.

@yannickmonney
yannickmonney force-pushed the fix/sandbox-capacity-waits branch from 4935833 to 69452b5 Compare October 3, 2026 00:15
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent re-review of PR #4099 at 85419e8ceb0a3295557d2e9b3559acc809c6fdca: changes required.

  • The previous MEDIUM 1 (a pending Destroy treated as a room wait) is not fixed (reproduced at unit level).

  • The previous MEDIUM 2 and MEDIUM 3 are fixed and pinned.

  • Held together with fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, TALE-483 run bf5d1620-07c5-4697-853c-9de9c9dc8b0a. That is a manual child of TALE-359, distinct from the implementer: the shared principal, no agent update dashboard ui (#508) #2 run.

  • Base:

  • Merge: git merge-tree is clean against main, fix(sandbox): end the processes an exec leaves behind #4097 and fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098.

  • Three-way composition [source]:

    • No manual totals go stale: readme.md 1082 boxes is untouched, automation.md has no count header, and there are 572 rows with no ID collisions.
    • The contract goes 3.13.0 → 3.14.0 only here.
  • CI at this head: all attempt 1, all complete.

    • Build 37081569001, CLI 37081568909 and Checks 37081568977. Backend integration actually ran (job 111085160898, success), and Unit, UI, Type check and Lint passed.
    • Commitlint 37081568975, E2E 37081569031 and SAST 37081568970.
    • Totals: 58 success, 12 skipped, Trivy neutral.
    • The skips are Attach to release, 6 Candidate gate, 2 fork-PR jobs, and the AI gateway, UI docs and Web container tests.
  • Local run [local]: vitest --project server on 11 changed backend test files gives 186/201. All 15 failures are render_fetch.test.ts "render worker — output budget in bytes", and they fail identically on main 358f69107 here (15/30): environment-only, not this PR.

  • Tags below: [local] = executed here; [source] = read, not run.

MEDIUM 1 (previous): a pending Destroy still becomes an automation "wait for room". NOT FIXED, reproduced at unit level [local].

  • Where:
    • agent-turn-shim.ts:67-71 still flattens every SandboxQuotaError to AppError{code:'QUOTA_EXCEEDED', message}. That includes fix(platform): refuse new work in a sandbox being destroyed #4095's SandboxDestroyPendingError (sessions.ts:76).
    • capacity_refusal.ts:55-56,65-79 has no marker.
    • It is used at agent_host.ts:1261-1269 (start) and :2219-2242 (answered-ask resume).
  • Probe: an untracked vitest, removed afterwards.
    • Input: classifyWorkflowStartFailure(new AppError({code:'QUOTA_EXCEEDED', message:<#4095's destroy-pending message>}), now).
    • Result: {failureCode:'sandbox_capacity', reason:"the agent turn is waiting for sandbox room: the organization's workflow sessions are all in use", retryAfterMs:15000}.
    • fix(platform): refuse new work in a sandbox being destroyed #4095's comment (sessions.ts:64-75), EN/DE/FR sandboxes.md:68 and SET-B30 say the step fails with the reason.
  • Effect:
    • For the 15–30 min the Destroy ladder runs, the step now shows "Waiting for a sandbox slot" in the UI with a false reason.
    • Once the Destroy settles, it runs in a fresh workspace without the earlier nodes' files.
    • On main the step failed with the real reason.
  • The test pins the opposite: capacity_refusal.test.ts:46 asserts "every QUOTA_EXCEEDED shape is organization room".
  • Fix: carry a marker through quotaAsAppError (data.reason:'destroy_pending' or a distinct code), map it to start_failed with the Destroy message, and align the docs.
  • Tests: the shim-shaped error through classifyWorkflowStartFailure, plus a stepper case.

Disposition of the previous review

  • M1: NOT FIXED (above).
  • M2a, an answer refused for room is lost: FIXED [source + local].
    • agent_host.ts:2244-2257 records undeliveredAskId; agent_retry.ts:178-188 resumes the asking conversation; agent_host.ts:1528-1563 opens it with answerResumePrompt.
    • Pinned by agent_retry.test.ts:318, stepper.agent-retry.test.ts:440 and agent_host.context_window.test.ts:473,502, which all passed locally.
  • M2b, a stale waitingForRoomSince: FIXED by another route.
    • roomWaitSince ignores a stamp older than launchedAt (agent_retry.ts:283-291,334-345; stepper.ts:1048-1052).
    • Pinned by agent_retry.test.ts:376,412 and stepper.agent-retry.test.ts:409, which passed locally.
  • M3, room waits counted as failures: FIXED.
    • routes.ts:199-204 filters before the LIMIT; harness health filters at :316-321; external-turn-outcome.ts:28-31.
    • routes.test.ts:443,463 are mock-only. The real-Postgres check checkMetricsSurface ran in CI Backend integration.
  • LOW, a compute-less active workflow row kept up to 2 h: NOT FIXED (shim.ts:668-672 onlyIdle; idle-release.ts:87-96).
  • LOW, COLLECT deletes the workspace of a 429-refused run: FIXED (agent_session.ts:144-156, pinned by integration Lane 3e).
  • LOW, the "tried again at least every two minutes" docs: FIXED.
  • LOW, a re-park resets waiting_for_capacity_at_ms: NOT FIXED (agent-turn-shim.ts:392).
  • LOW, automation re-kicks out-compete parked task runs: PARTIAL. The backoff now grows to at most 2 min with jitter, and with fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098 the task lane gets a queue wake.
  • LOW, execution-logs.md doesn't mention room waits: NOT FIXED.
  • LOW, UX: no wait status for an automation: FIXED (run list badge, run page alert, log and timeline text). Pinned by agent-execution-log.test.tsx:120-146 and run-view.test.ts:230. Residuals are listed below.
  • INFO, "no code dependency on fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098": CHANGED. This PR now reads fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098's 429 body and falls back cleanly without it. sandboxes.md:105,107 describe a line that only fix(sandbox): free idle compute, bound helpers, admit by memory and disk #4098 adds.

New LOWs [source, review agents; not run]

  • Park-wake chains multiply after a re-park. agent-turn-shim.ts:406-416 adds a wake with no singleton key or park stamp; agent-runs.ts:845-853.
  • The re-attach fence ignores a held start job (hypothesis): recovery.ts:37-55, reattach.ts:174-189.
  • Migration 0148 blocks writes while its index builds. It runs a plain CREATE INDEX inside the boot transaction on app.sandbox_session_ops.
  • A two-agent run shows the old strings on the other row. The non-current agent row still alternates between them (run-step-timeline.tsx:121-127,226), if a refused start leaves an op row.
  • Screen readers in the task dialog:
    • the waiting text sits inside aria-hidden (agent-execution-log.tsx:336-347);
    • the collapsed line isn't role="status";
    • the waiting step's icon is announced "Running".
  • Zero backoff on Retry-After: 0: with no queue body, the step re-kicks at once (agent_retry.ts:91-104). No current spawner sends this.
  • Nits: env.ts:20 names agentQueueSlots, which doesn't exist; .env.example:116 says "at least 8 regardless".

Composition with #4098 [source]

Browser check: the user flow changed (the Waiting badge, alert and log). A local EN/DE/FR browser and accessibility check is owed before acceptance. I didn't run one this time, because the verdict is already changes-required on backend grounds.

Checked and correct [source]

  • Room-wait ops carry nothing billable.
  • The retention sweep is scoped correctly:
    • it needs status<>'running', no minted key, more than 1 h, and a newer op on the same session;
    • the newest op is kept, and the asking op is never swept;
    • it never touches COLLECT's candidates.
  • Migration numbering: 0148 follows main's 0147.
  • The 429 values are clamped.
  • Slot settings are validated as integers 1–256, and an invalid value fails boot.
  • Wakes are single-winner (FOR UPDATE SKIP LOCKED), in per-organization rounds.
  • i18n: runs.waiting.room exists in EN, DE and FR.

Repairs go through the manager. I'll re-review the next exact head together with #4098.

@yannickmonney
yannickmonney force-pushed the fix/sandbox-capacity-waits branch from 85419e8 to 397085a Compare October 3, 2026 01:52
When the sandbox spawner was at capacity or short of memory it answered 429,
and nothing on the platform matched it: a task run failed its start and
burned its three immediate retries on the same refusal, an automation's agent
step did the same and failed the run, and a crawl errored. An automation's
agent step also failed outright when the organization's workflow sessions were
all in use, where a task run parks.

Any start refused for want of room, the organization's session budget or the
host's capacity, now waits: a task run parks for capacity like a full budget
(woken on a release edge or by the two-minute watchdog), an automation's agent
step settles as sandbox_capacity and is re-kicked once the refusal's retry
hint has passed without spending an attempt (bounded by the node's execution
guard, reported as start_failed on the wire), and a render becomes the
capacity wait the crawl already polls through.
A crawl batch settled its session row destroyed even when the destroy itself
failed, which hid the row from the watchdog's release pass while the
container ran on, outside the render budget. The row now stays live after a
failed destroy, the state the release pass reaches.
Agent turn starts and their 90 s drive windows ran as pg-boss batches of
WORKER_CONCURRENCY (5), each fetched whole and awaited whole: one slow start
held every start behind it, and a worker drained at most five live turns at
once while the others waited, their output piling up in the sandbox's replay
ring and their heartbeats going stale. The four agent queues now run as
independent slots like the website scan, and the drive queues run at least
16 at once whatever WORKER_CONCURRENCY says; a drive window holds no
database connection while it waits on the stream.
Review finding: a project agent's stopped standing workspace was resumed
(row flipped to active) before the host refused the create with a 429, the
row's release was refused because the run was still queued, and the run
parked with the row active and no compute. The reconcile then healed the row
to destroyed, and the next refused create's failure path asked the spawner to
destroy the id, which for an id with no compute deletes the preserved
workspace.

A create the spawner refused for want of room made nothing, so its failure
path no longer destroys. Parking a run now frees the agent's slot back to
stopped, quietly: waking the next parked run would only send it into the
same refusal. Proven on real Postgres in the task-agent-runs lane.
Each sandbox_capacity re-kick charged the run-wide 100-execution guard, so a
long wait failed the run with a sentence that still said it was waiting, or
left a later forEach node without budget, blaming the author. A wait for room
now charges no execution and ends after two hours, with a reason that says
the step waited that long for room.
Every refused start of an automation's agent step settled its op row failed,
so a step waiting twenty minutes for room added about a hundred failed
harness turns to the metrics during the very squeeze it waited out. Such a
start now settles with result status awaiting_room, counted as no outcome
like a turn parked on a question. The answered-question resume path treats a
room refusal as the same wait instead of spending a retry on it.
Room on the shared sandbox host frees when any organization's sessions end,
which wakes nothing in another organization, and the watchdog woke one
parked run per organization every two minutes: twenty parked runs took about
forty minutes to start. It now wakes up to four per organization a tick.

Sixteen drive slots polling every two seconds cost a worker eight empty
fetches a second; drive windows are enqueued with no delay, so the insert
notification wakes them and the idle poll is now every ten seconds.
A destroy that answered badly (a timed-out request whose removal still
finished, a passing 502) kept the render row live until the release pass's
ten-minute horizon, holding one of the organization's two render slots. A
definitive gone now settles the row at once; an unknown answer still leaves
it to the release pass.
A run parked for host room can only be woken by a release edge of its
own organization or by the two-minute watchdog. The watchdog picked its
organizations from the fifty oldest parked rows, so one organization's
backlog kept every other organization off the list for hours, and a
quiet organization's runs could reach their park deadline while the
host had room.

The watchdog now lists the organizations with a parked run directly,
the longest-waiting first, and wakes a few runs of each. Every release
edge wakes its own organization's oldest parked run and also the oldest
parked run of the other organizations, since room freed on the shared
host is room any tenant may be waiting for.
An agent step waiting for room started again as soon as the refusal's
retry hint passed, for up to two hours. A full host answers every
waiter with the same hint, so the waiters stayed in lockstep: a burst of
creates every ten seconds that the spawner refused together, with a new
session row and op row each time.

Each start of a waiting step now waits at least the hint and then a
random part of a window that doubles with each refusal in a row, up to
two minutes. The refusal carries its hint, and the step's cursor counts
the refusals of the current wait. The two-hour bound is unchanged.
An agent step that waited for sandbox room and then ran kept the wait's
start time on its cursor. When the agent asked a question and the resume
after the answer found no room, the stepper read that old start time:
past two hours, it failed the run on its first refusal and discarded the
answer and the run's work.

A wait that began before the attempt's last launch is over, so the
retry plan now starts a new wait, with its own clock and refusal count,
in that case.
When an operator answered an agent step's question and the resume found
no sandbox room, the refusal settled without the asking turn's
conversation. The re-kick then started the node over in a new
conversation, and the agent's work before the question was redone.

The refused resume now settles with the asking conversation and the
question whose answer it could not deliver. The re-kick resumes that
conversation and opens it with the answer, as the resume would have;
a further refusal carries both on. Without a conversation handle, the
fresh start still folds every answer into its prompt.
A create the sandbox host refused for want of room left its row failed
with no collected stamp. Ten minutes later the watchdog's COLLECT pass
destroyed the session id when no newer row carried it; for a standing
workspace whose last row the reconcile had healed to destroyed, that
destroy deleted the preserved workspace the agent lane had just spared.
The render lane also ran a full destroy round trip on every refused
poll of a scan.

A 429 made nothing under the id, so both lanes now settle the row
failed and collected at once, and the render lane skips its destroy.
Each start of an automation step that waits for sandbox room settles an
op row, a few hundred an hour per waiting step. The external-turn
metrics read the newest 5000 ops and only then skipped the waits, so a
long wait could crowd every real turn out of the page, and the capped
flag, computed after the skip, hid it. The harness-health read counted
every refused start as a failed harness turn and showed the harness as
recently failing.

Both reads now leave out the ops that are no outcome, a question park
or a room wait, in SQL, and the metrics report the cap the read hit.
The parked-run wake's unit locks read its claim as one statement, and
the claim scope built from nested query fragments split it in two, so
they failed. The scope now rides the statement as a parameter, and the
locks pin what a release edge does: the organization's oldest parked
run is claimed first, then the oldest of every other organization, a
failed first claim still lets the second run, and the turn job names
the woken run's own organization.
A drive chain bumps its op's heartbeat only when a window ends. On a
busy worker a live turn's next window can wait for a slot longer than
the four-minute staleness bound, so the task and automation re-attach
sweeps took it for a dead chain and enqueued a second drive beside the
first, and another on each later sweep.

Before claiming a silent turn, both sweeps now check pg-boss for a
drive job of that exec that is queued, or running and started inside
the staleness bound, and leave the turn to that chain. A running job
that started earlier, with the op silent since, belongs to a worker
that died with it: drive jobs carry no heartbeat and expire only after
twelve hours, so it does not hold the re-attach off.
While an agent step waited for room, its run said "Agent working" and
its agent log alternated between "The agent is starting up in the
sandbox" and "The agent produced no log", for up to two hours, with
nothing saying the run was waiting.

A room wait now parks under its own detail, `room:<node>`, and the run
read model answers `waitingFor: room` for it. The run's reason line,
the step timeline and the agent log say "Waiting for a sandbox slot",
the words the task card uses, in every locale. The launch of the
waiting start turns the park back into an agent at work. The REST
contract gains the value as 3.13.0.
The sandboxes page promised that a waiting task run is tried at least
every two minutes. The watchdog tries a few waiting runs of each
organization per two-minute tick, so a run behind others waited longer,
and the page said nothing of the release edges that do most of the
waking.

The page now says what happens: a waiting task run starts again when
any session on the deployment ends, and every two minutes Tale tries a
few waiting runs of each organization; an automation's agent step
waits a growing pause of up to about two minutes between tries and
shows Waiting for a sandbox slot meanwhile. The API reference and the
automation concepts name the new `room` waiting kind.
The ledger row for waits on sandbox room described one wake per
organization, a fixed retry hint and a refused create left for the
collect pass. It now names what the automated checks hold: release
edges and the watchdog reach every organization, an automation step's
wait backs off and ends with a launched start, a refused answered
question keeps its conversation, the run parks as waiting for room,
refused creates leave nothing to collect, waits stay out of the turn
metrics and harness health, and re-attach leaves a live chain alone.
The kick holds a re-kicked start until the time the stepper asks for,
but never longer than a broker cooldown, one minute. A step waiting for
sandbox room backs off up to two minutes between starts, so every pause
past a minute was cut to a minute and the backoff stopped growing there.

The hold now reaches two minutes, the longest pause of a room wait;
that still keeps a held start well inside the stalled-turn sweep's
four-minute window for the op row the kick writes.
…s up

The spawner now keeps a first-come line for host room, and its 429 says
where a refused create stands (queue: { position, waiting }) and when
that place comes up. A waiter that asks later loses its turn to the
ones behind it, so the platform comes back exactly then:

- an automation step's re-kick waits the place's hint and at most a
  second more, instead of its own doubling backoff;
- a task run the host refused is parked with one task.agent_park_wake
  job at the hint, which restarts that run once and does nothing if it
  was woken otherwise or is delivered twice;
- a crawl's render polls at the hint, between 5 s and 60 s.

An organization's own budget and a host without the field keep the
pacing they had. The admin docs say that room goes to the longest
waiter when the deployment is full.
Every start of an automation step the sandbox refused writes an op row
that settles awaiting_room, and every create the spawner refused leaves
a failed session row; a step waiting an hour wrote dozens of each, and
nothing ever deleted them. The sandbox watchdog now removes awaiting_room
op rows an hour after they ended, keeping each session's newest (the run
view reads it) and any row that minted a gateway key, and failed session
rows a week after they were collected, in bounded batches.

Migration 0148 adds a partial index over the awaiting_room op rows, so
the sweep does not scan the whole op table every five minutes.
A worker ran agent turn starts with WORKER_CONCURRENCY slots (five by
default), each held through the sandbox create and the turn's first 90 s
window, so a burst of assigned tasks started about three a minute per
lane; its drive windows were fixed at 16, which keeps about 40 live
turns per lane drained before their windows wait past the recovery
horizon.

AGENT_START_SLOTS and AGENT_DRIVE_SLOTS now set both per lane; unset,
starts get WORKER_CONCURRENCY and at least 8, drives at least 16. The
env reference says how many live turns a worker drains per drive slot.
The first window stays in the start job: handing it to a drive job
would close the exec stream at once and lean on the replay ring from
the first second.
The room-wait retention read a DELETE's row count, which only the database driver reports, and kept looping where a statement answers rows; it now returns the deleted ids like the model-endpoint sweep, and the watchdog tests tell its statements from the cleanup and model-endpoint passes they check.
A start at the front of the sandbox host's line asks every few seconds, and each refused attempt leaves a collected failed session row, so a two-hour wait left over a thousand. Nothing reads such a row once it is collected; a day is enough.
The spawner now also refuses new sessions while the disk the workspaces live on is below its floor (429 host_disk); the platform waits on it like on any 429. The admin guide (EN, DE, FR) and the spawner client's comment say so.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Post-merge independent reevaluation of #4099 at a9b386d4a (squash of c8b1c6c26, merged by root at 07:49:27Z without a re-review of that head). Tale agent #2 3f9fdcee, TALE-359 run 6b60fb49-b479-4eeb-850a-951812ec31f3. This is a source reevaluation by one read-only review agent, cross-checked by me; nothing was executed for it.

MEDIUM, still open and now on main: a pending Destroy turns an automation step into a 2-hour "wait for room" that then runs in an empty workspace.

  • The path:
    1. resumeSessionSlot/reserveSessionSlot throw SandboxDestroyPendingError.
    2. quotaAsAppError flattens it to QUOTA_EXCEEDED (agent-turn-shim.ts:67-71).
    3. classifyWorkflowStartFailure → isQuotaExceeded (capacity_refusal.ts:55-56,65-73) reads it as organization room, with the false reason "the organization's workflow sessions are all in use".
    4. The stepper re-kicks for up to 2 h with no attempt spent (stepper.ts:1271-1366).
  • Once the Destroy settles: the step reserves a fresh row and continues mid-run in an empty workspace. The earlier nodes' files and transcripts are gone.
  • Before fix(platform): wait for sandbox room instead of failing the run #4099: the step failed with the Destroy message.
  • Contradictions:
    • sessions.ts:64-75 ("an automation step fails with this reason");
    • EN/DE/FR sandboxes.md:68 against :108 of the same page;
    • the register row automation.md:170.
  • Tests: the unit test capacity_refusal.test.ts:46-60 asserts the misclassification.
  • Fix: carry a marker through quotaAsAppError (for example data.reason: 'destroy_pending'), map it to start_failed with the Destroy text, and keep the task lane's parking.
  • Tests to add: a classifier case, a stepper case, and an integration lane that Destroys a workflow run's session and then kicks the next agent node.

My other findings:

  • Fixed:
    • the operator's answer lost on a refused resume (pinned at agent_retry.test.ts:322,358 and stepper.agent-retry.test.ts:440);
    • the stale waitingForRoomSince (agent_retry.ts:283-291, pinned);
    • room waits in metrics and harness health (routes.ts:199-203,316-320);
    • COLLECT on a 429-refused run;
    • the "every two minutes" docs;
    • the automation wait status in the UI.
  • Not fixed: the compute-less active workflow row, the re-park reset, and TALE-483's LOWs (identical code).
  • Partly fixed: fairness across lanes, and execution-logs.md.

New, LOW:

  • The docs promise disk shortage clears on its own. EN/DE/FR sandboxes.md:105 says a start "needs nothing from you" for disk too, while the spawner notes that stopping idle sessions frees no disk (session-routes.ts:580-582).
  • A front waiter can lose its place in the spawner's line when the worker's start slots are saturated. This is a hypothesis.

Next owner: the manager, for a follow-up issue on the pending-Destroy MEDIUM. It now affects main.

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.

1 participant