Repository navigation
fix(exec): keep the exit wake when the session id rotates - #199678
Conversation
A background exec captured the session generation (session id and lifecycle revision) when it started. When compaction or another same-key rotation installed a new session id while the command ran, admission refused the completion with SessionDeliveryGenerationRevokedError and only a log line recorded it. Before admission, the completion now reads the key's current row: - same lifecycle revision: follow the new session id and wake. - new lifecycle revision (reset, /new, rewind, branch switch): withhold the wake and write a visible "Background command result withheld" note to the current transcript. - deleted row: withhold and log. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR follows session ID changes within one lifecycle and records a transcript notice when a reset prevents a background completion wake. Example: A background sleep 25 finishes after compaction changes the conversation's session ID while preserving its lifecycle revision.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a current-main failure that loses background completion wakes after session ID rotation; no concrete correctness or security regression was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherBackground exec completion notifications carry captured conversation identity and authority into ordinary session-event admission, which starts and delivers the follow-up turn. flowchart TD
A[Background command exits] --> B[Exec notification owner]
B --> C[Read current session row]
C --> D[Same lifecycle]
D --> E[Existing event admission]
E --> F[Successor conversation turn]
C --> G[Changed lifecycle]
G --> H[Visible transcript notice]
Technical reviewBest possible solution: Follow physical session rotation within the existing lifecycle, retain admission authority, and record reset suppression through the transcript owner. Do we have a high-confidence way to reproduce the issue? Current main captures the original session ID, compaction can replace that ID without changing the lifecycle, and subsequent admission rejects the stale target; the PR also reports matching red-on-base runs. Is this the best way to solve the issue? The patch repairs destination selection in the existing target owner and reuses transcript-report persistence, with two tests protecting distinct lifecycle outcomes and no unnecessary parallel state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 97dd78cc2cbd. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +121, Tests +61. Total +182 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 15, 2026, 12:35 PM ET / 17:35 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…99678) ## Problem A background exec captures the session generation (session id and lifecycle revision) when it starts. If the session row changes while the command runs, admission refuses the completion with `SessionDeliveryGenerationRevokedError`. The only record is a Gateway log line: `exec: completion delivery failed (...)`. The model and the user get no wake and no notice. ## Paths that change the session row of one key during a run Same conversation, new session id, same lifecycle revision: - Context-engine compaction successor: `src/agents/embedded-agent-runner/compaction-successor.ts:241` patches only `sessionId`. - Embedded runner adoption of a rotated id: `src/agents/embedded-agent-runner/run/session-prompt-state.ts:102-110`. - Agent-command rollover without an automatic reset: `src/agents/agent-command.ts:308-325`. - Cron run session rollover: `src/cron/isolated-agent/run-session-state.ts:459`. New lifecycle revision (the user or a policy started a different conversation state): - `/new`, `/reset`, Gateway reset: `src/gateway/session-reset-service.ts:764-784`; reply path `src/auto-reply/reply/session.ts:610`. - Idle or daily rollover: `src/auto-reply/reply/session.ts:610`, `src/agents/agent-command.ts:311-313`. - Rewind, branch switch and fork: `src/config/sessions/session-message-cut-plan.ts:329`. - A Gateway `agent` request that names a new `sessionId` for an existing key: `src/gateway/server-methods/agent-session-patch.ts:157-162`. Delete removes the row. ## Fix Before admission, the completion reads the current row of its session key (`followSessionEventTargetForHost` in `session-event-target.ts`): - Same lifecycle revision: the target follows the new session id. The wake is delivered. The captured authority, settings and route stay the same. - New lifecycle revision: the wake is withheld. A visible transcript note goes to the current session: `Background command result withheld (<process id>, <exit>): the conversation was reset, rewound or moved to a new session after the command started. Its output stays in process log.` The note is excluded from model context. - Row deleted: the wake is withheld and a warning is logged. No transcript exists to hold a note. If the read fails, the old path runs and admission still checks the captured generation. ### Rewind, switch and fork These paths mint a new lifecycle revision on purpose. Owners of the old revision (workspace custody, transcript writers, lifecycle authority) must stop. A command started before a rewind belongs to the discarded branch. Its result can describe state that the new branch never saw. Thus the completion does not wake the rewound conversation. The user sees the withheld note, and the model can read the output with `process log` if needed. The lifecycle revision stays the only fence; this change does not add a second rule beside it. ## Proof - vitest-source (`ocx test`): two new tests in `src/agents/bash-tools.exec-background-followup.test.ts` use a real background exec, the real session store and real session-event admission (model mocked). - Rotate the session id mid-exec (same lifecycle revision): the wake turn runs on the new session id. Red on the merge base (`Session event was not admitted`), green here. - Reset mid-exec (new lifecycle revision): no wake, and the visible note is in the transcript. Red on the merge base, green here. - All tests in the four touched exec-notify and session-event test files pass. - source (`ocx src`, scratch Gateway, scripted OpenAI-compatible model), compaction successor (same lifecycle): - A test-only context engine returns a compaction successor `sessionTarget` with a new session id (`compaction-successor.ts:241` path). - Turn 1 starts a real `sleep 25` background exec. While it runs, `sessions.compact` moves the key from `64fec7b4…` to `compacted-1c7e…` (base) and from `b153c1ee…` to `compacted-429c…` (this branch). The lifecycle revision stays the same in both runs. - Merge base `2ecdd6a7babb`: `session event execution failed source=exec … error="Session event was not admitted; retry against the current session"`, then `exec: completion delivery failed`. The model gets no wake request. - This branch: the model gets one wake request that carries the command output. The wake turn and its reply are in the transcript of the successor session `compacted-429c…`. - source, forced new lifecycle (Gateway `agent` request with a new `sessionId` for the same key, real `sleep 15` background exec): - Merge base: `SessionDeliveryGenerationRevokedError` in the log, no wake, nothing in the transcript. - This branch: no wake, and the `Background command result withheld (...)` note is in the new session's transcript. - Gates: `tsgo:core`, `check:test-types`, oxlint and oxfmt on changed files, `ocx build --dts`. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
A background exec captures the session generation (session id and lifecycle revision) when it starts. If the session row changes while the command runs, admission refuses the completion with
SessionDeliveryGenerationRevokedError. The only record is a Gateway log line:exec: completion delivery failed (...). The model and the user get no wake and no notice.Paths that change the session row of one key during a run
Same conversation, new session id, same lifecycle revision:
src/agents/embedded-agent-runner/compaction-successor.ts:241patches onlysessionId.src/agents/embedded-agent-runner/run/session-prompt-state.ts:102-110.src/agents/agent-command.ts:308-325.src/cron/isolated-agent/run-session-state.ts:459.New lifecycle revision (the user or a policy started a different conversation state):
/new,/reset, Gateway reset:src/gateway/session-reset-service.ts:764-784; reply pathsrc/auto-reply/reply/session.ts:610.src/auto-reply/reply/session.ts:610,src/agents/agent-command.ts:311-313.src/config/sessions/session-message-cut-plan.ts:329.agentrequest that names a newsessionIdfor an existing key:src/gateway/server-methods/agent-session-patch.ts:157-162.Delete removes the row.
Fix
Before admission, the completion reads the current row of its session key (
followSessionEventTargetForHostinsession-event-target.ts):Background command result withheld (<process id>, <exit>): the conversation was reset, rewound or moved to a new session after the command started. Its output stays in process log.The note is excluded from model context.If the read fails, the old path runs and admission still checks the captured generation.
Rewind, switch and fork
These paths mint a new lifecycle revision on purpose. Owners of the old revision (workspace custody, transcript writers, lifecycle authority) must stop. A command started before a rewind belongs to the discarded branch. Its result can describe state that the new branch never saw. Thus the completion does not wake the rewound conversation. The user sees the withheld note, and the model can read the output with
process logif needed. The lifecycle revision stays the only fence; this change does not add a second rule beside it.Proof
ocx test): two new tests insrc/agents/bash-tools.exec-background-followup.test.tsuse a real background exec, the real session store and real session-event admission (model mocked).Session event was not admitted), green here.ocx src, scratch Gateway, scripted OpenAI-compatible model), compaction successor (same lifecycle):sessionTargetwith a new session id (compaction-successor.ts:241path).sleep 25background exec. While it runs,sessions.compactmoves the key from64fec7b4…tocompacted-1c7e…(base) and fromb153c1ee…tocompacted-429c…(this branch). The lifecycle revision stays the same in both runs.febd4dcc21c4:session event execution failed source=exec … error="Session event was not admitted; retry against the current session", thenexec: completion delivery failed. The model gets no wake request.compacted-429c….agentrequest with a newsessionIdfor the same key, realsleep 15background exec):SessionDeliveryGenerationRevokedErrorin the log, no wake, nothing in the transcript.Background command result withheld (...)note is in the new session's transcript.tsgo:core,check:test-types, oxlint and oxfmt on changed files,ocx build --dts.