Skip to content

fix(exec): keep the exit wake when the session id rotates - #199678

Merged
obviyus merged 1 commit into
mainfrom
fix/exec-wake-session-rotation
Nov 16, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/exec-wake-session-rotation

Conversation

@obviyus

@obviyus obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

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 febd4dcc21c4: 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.

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]>
@clawsweeper

clawsweeper Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Admission rejects the captured destination, leaving only a Gateway warning.
  • After: The completion wakes the successor session with the command result.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and passing head gates support correctness, while the supplied runtime evidence falls short of the repository's real-model requirement.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A conversation waiting for a background command can receive no completion after compaction rotates its session ID.
Reason: Restoring the promised completion wake has clear value, and the collaborator-authored direction preserves reset isolation without adding configuration.

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
Reviewed head: a0e143c6e4dcc224e7261703b6c86c03bddb2b9a

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted real-agent Gateway output showing a completion wake after compaction rotation and a visible withheld notice after reset, as required by root AGENTS.md.
Agent review details

How this fits together

Background 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]
Loading

Technical review

Best 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

  • Captured session-event destination changes intended behavior with a stated reason (753a7a5: Move immediate notifications into ordinary session execution while preserving original destination, permissions, and isolation from reset or replacement; older-name content search encountered an unavailable historical blob.)
  • Completion batching and yielded-run delivery keeps the original intent (597e400: Coalesce compatible completions through the session-event owner while preserving each producer's authority and result.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 597e400 adds src/agents/bash-tools.exec-notify.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 597e400e97d7; files: src/agents/bash-tools.exec-notify.ts)
  • Peter Steinberger: Raw commit 753a7a5 adds src/agents/bash-tools.exec-notify.ts:1 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 753a7a57be10; files: src/agents/bash-tools.exec-notify.ts)

PR surface

Source +121, Tests +61. Total +182 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 122 1 +121
Tests 1 61 0 +61
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 183 1 +182

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: Session rotation can silently lose a background completion wake, with impact limited to conversations awaiting affected commands.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-15T16:37:04.089Z sha a0e143c :: needs maintainer review before merge. :: none

Reviewed November 15, 2026, 12:35 PM ET / 17:35 UTC (Revision 2).

@obviyus
obviyus marked this pull request as ready for review November 15, 2026 17:14
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus
obviyus merged commit 8862ffc into main Nov 16, 2026
235 checks passed
@obviyus
obviyus deleted the fix/exec-wake-session-rotation branch November 16, 2026 03:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant