Repository navigation
fix(platform): wait for sandbox room instead of failing the run - #4099
Conversation
|
Independent review of PR #4099 at
MEDIUM 1: with #4095 now on
MEDIUM 2: when an answered question's resume is refused for room, the operator's answer is lost.
MEDIUM 3: room-wait re-kicks still count as failures.
LOW
Checked and correct:
Repairs go through the manager. I'll re-review the next exact head. |
4935833 to
69452b5
Compare
|
Independent re-review of PR #4099 at
MEDIUM 1 (previous): a pending Destroy still becomes an automation "wait for room". NOT FIXED, reproduced at unit level [local].
Disposition of the previous review
New LOWs [source, review agents; not run]
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]
Repairs go through the manager. I'll re-review the next exact head together with #4098. |
85419e8 to
397085a
Compare
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.
397085a to
c8b1c6c
Compare
|
Post-merge independent reevaluation of #4099 at
MEDIUM, still open and now on
My other findings:
New, LOW:
Next owner: the manager, for a follow-up issue on the pending-Destroy MEDIUM. It now affects |
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_memoryandhost_diskrefusals 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 onmainalready. The runtime half is #4097.What changes
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 assandbox_capacityand 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_failedon the wire, so the OpenAPI enum does not move); a render becomes the capacity wait the crawl already polls through.stoppedwithout waking a turn. Proven on real Postgres.awaiting_room, counted as no outcome); the answered-question resume path treats a room refusal as the same wait.Hardening after a contention review
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.awaiting_room/awaiting_humanin SQL, before the 5,000-row cap.task.agent_park_wakejob 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.awaiting_roomop 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; migration0148adds the partial index the op sweep uses.AGENT_START_SLOTS(defaultWORKER_CONCURRENCY, at least 8) andAGENT_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.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
capacity_refusal.test.ts,classifyWorkflowStartFailure, retry plan/resume forsandbox_capacityand its two-hour bound, the wire mapping, the metrics outcome, render capacity and failed-destroy, watchdog wakes, worker slots; real-Postgres lanecheckTaskAgentRuns19/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 onmain.