Repository navigation
Description
Follow-ups from the independent review of #4095, merged as 358f69107e3725e7e1e30f0c9e0eaf3a2410da74. All three are pre-existing on main: #4095 neither introduced nor fixed them, and its own acceptance (#4091's resumed-work path) holds.
Sources:
- Tale agent update dashboard ui (#508) #2 (TALE-359, run
e32191b4-f2e1-4096-b5cc-419e9ad8ce51), issuecomment-5962968090, and its TALE-476 verdict18ee7870; - the implementer's handoff on TALE-476 (agent optimize rag action #4, repair run
d35a7bb8), which named item 3; - LOW update dashboard ui (#508) #2 of the #4087 review.
The fleet manager (TALE-357, run 9db34124-713b-44a6-adcf-09e59189e226) files this one issue so the three named follow-ups are tracked once (root asked for deduplication). It adds no new investigation. File and line references are from the review, at head adf8c4640.
1. MEDIUM: a Destroy attempt settles a fresh incarnation reserved while it deletes
Three facts combine:
- The pending-Destroy predicate closes a session only while the named row is live (
destroy-schedule.ts:118-119). - The teardown checks the row id once, at its start (
service.ts:133-138). - Its final
markSessionDestroyedis session-wide: it settles every non-destroyed row under the id, and every token (sessions.ts:481-492).
Two writers take the named row out of the live set without either lock:
- the host's by-id
failedafter a failed create (agent_session.ts:157-160→agent-turn-shim.ts:759-771); - the watchdog's expiry (
watchdogs.ts:184-200).
If either happens mid-attempt, a reserve under the same id is admitted, and the attempt then destroys it.
Reproduced locally by the reviewer (real PG16, a probe added temporarily to checkDestroyAdmission, with the attempt gated in its delete):
| Named row during the attempt | Fresh reserve | Rows after |
|---|---|---|
stays stopped (control) |
refused | destroyed |
set failed by id |
admitted | destroyed,destroyed |
set expired |
admitted | destroyed,destroyed |
Likely real path, from source, with timing not measured:
- A Destroy lands during a turn's create.
- The delete kills the create, and the host marks the row
failed. - The run's auto-retry reserves a fresh row.
- The attempt's settle destroys that row and revokes its tokens.
Fix options from the review:
- settle only the named row, as
workspace-cleanup.ts:253-258does, and scope token revocation the same way; - or let an
activeDestroy job close the session id whatever its row's status.
2. LOW: the expiry overlap reopens admission under a live attempt
An attempt that outlives the 900 s expiry of the last try is re-inserted as failed (pg-boss 12.28 failJobsByTimeout) while its handler still runs. Admission then reopens under a live attempt.
Suggested fix: pass the job's signal into the teardown, and check it before the delete and before the settle.
3. INFO, pre-existing: the shim's id-only activation can revive a settled row
agent-turn-shim.ts:759-771 activates by id alone after a fresh create. A Destroy landing during the create can therefore be undone, leaving the row active with a destroyed stamp.
Suggested fix: AND status = 'creating', and fail the start when nothing moves.
Also correct
The ordering comment at the #4095 compare-and-set (sessions.ts, around 427-433) overclaims for items 1 and 2, and it misdescribes two writers (heal and cleanup). Fix it together with the code.
Acceptance
- Deterministic local real-database regressions for 1–3 that fail at
358f69107and pass after the fix. No sleeps as ordering. - Keep fix(platform): refuse new work in a sandbox being destroyed #4095's guarantees:
- the CAS;
- the admission lock on request and resume;
- both lock orders;
- a newer incarnation between attempts;
- organization isolation;
- token and gateway-key cleanup;
- the pending and failed UI state.
- EN/DE/FR docs only if the documented behaviour changes. Synthetic data only, with no production Destroy or fault injection.
- Routing: a cycle backend implementer and a distinct reviewer. The release hold for bug(sandbox): a delayed Destroy retry deletes resumed work #4091 is already satisfied, so this doesn't gate a release.
Activity
fix(platform): keep a sandbox Destroy to its own incarnation