Skip to content

Follow-ups from the #4095 review: a Destroy attempt settles a fresh incarnation, expiry overlap, id-only activation #4106

Closed

Description

@yannickmonney

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:

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 markSessionDestroyed is 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 failed after 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:

  1. A Destroy lands during a turn's create.
  2. The delete kills the create, and the host marks the row failed.
  3. The run's auto-retry reserves a fresh row.
  4. 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-258 does, and scope token revocation the same way;
  • or let an active Destroy 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 358f69107 and 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

  1. added
    agent-ready
    on Oct 29, 2026
  2. added a commit that references this issue on Oct 30, 2026
    86345dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions