Skip to content

fix: preserve session forks during parent request preparation - #173489

Merged
obviyus merged 1 commit into
mainfrom
fix/session-fork-snapshot-lifetime
Oct 15, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/session-fork-snapshot-lifetime

Conversation

@obviyus

@obviyus obviyus commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes background session-fork verification failing while the parent prepares its next model request.

User Impact

Advisor can finish a review and its verification across a parent-request preparation boundary instead of failing with a missing prepared-parent error. No configuration or storage migration is required.

Why This Change Was Made

The fork owner removed the current prepared snapshot as soon as another parent request began, before asynchronous payload preparation published its replacement. A review could finish inside that gap while verification found no snapshot.

Keep the last committed snapshot for the same run and transport until atomic replacement. New runs/transports still retire the previous snapshot; reset/delete revocation and existing TTL, count, and byte bounds remain intact. Ordinary run-end disposal already preserves provider resources, so no attempt-stream-settle change is needed.

This independent fork slice was extracted from #173458; steering idempotency and rejected-guidance delivery remain there.

Evidence

  • On baseline 5678421c757, keeps review and verification available while the next parent request is being prepared failed at the verification call with Cache-parity session fork requires a parent turn prepared by this OpenClaw runtime. Send a normal message first.
  • The sibling reset regression proves a pending preparation cannot restore a reset parent.
  • On this extracted branch, 32 focused tests passed across the fork owner and embedded fork integration suites. Changed-file formatting/lint, scoped tsgo, and diff checks passed.
  • The exact fork patch was included in the raw-evidence combined campaign tested at 04a5747760d1e9655b73fac511ddb81fad7a3c97: before 80 PASS / 5 FAIL; after 86 PASS / 0 FAIL / 0 UNPROVED. On shared case/invariant pairs: 59 PASS / 5 FAIL → 64 PASS / 0 FAIL; totals include differing commissioning/channel coverage.
  • The real-clock built-in minutes case completed review, verification, and one hidden delivery after a foreground tool crossed the minute threshold. Actual Codex minutes also passed. Assertions use provider requests, SQLite transcript rows, and tool/event ordering rather than Advisor's log summary.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves the last prepared session-fork snapshot while the same parent run and transport prepare its replacement.

Example: Advisor verifies a review while run fork-parent prepares a request containing Next parent request.

  • Before: Verification fails because the previous snapshot was already removed.
  • After: Verification replays Parent question until the replacement snapshot becomes available.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, worthwhile repair with no actionable finding; independently inspectable behavior evidence remains at the in-process boundary.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor-proof gate; inspectable coverage exercises the production snapshot owner with a synthetic transport, while the reported Gateway minutes campaign lacks linked raw traces.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Background review verification can fail while the parent prepares another model request.
Reason: The collaborator who introduced session forks supplies a narrow repair restoring their existing availability contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current-main session-fork preparation gap, has owner-backed direction, and introduces no actionable defect found in this review.

Priority: P2
Reviewed head: 5912dc932993a10a97f869d53acfc3c505e1432d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported built-in minutes campaign has no linked raw provider-request or event trace demonstrating verification across the preparation boundary.
Agent review details

How this fits together

The embedded runner captures prepared provider requests in bounded process memory; background session forks replay the captured prefix and later publications through the provider transport with current authority checks and tool execution disabled.

flowchart TD
  A[Parent model request] --> B[Session fork wrapper]
  B --> C[Prepared snapshot]
  B --> D[Provider transport]
  E[Background review or verification] --> F[Current authority checks]
  F --> C
  C --> D
  D --> G[Read only answer]
Loading

Technical review

Best possible solution:

Keep snapshot replacement in the existing fork owner while preserving same-run availability, bounded retention, and reset revocation.

Do we have a high-confidence way to reproduce the issue?

Current-main source exposes the missing-snapshot interval, and the added test enters it while payload preparation is suspended; the author reports the corresponding baseline failure, but this review ran no target code.

Is this the best way to solve the issue?

The patch fixes premature retirement at the producer, retains the existing replacement and cleanup mechanisms, and adds no parallel state owner or public API.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b4fb60242fef.

Provenance checked

  • Snapshot retirement before parent preparation changes intended behavior with a stated reason (164bd67: The original comment required retirement before requests so a transport without a payload boundary could not leave an earlier request replayable.)
  • Prepared payload capture and replacement keeps the original intent (cd56410: Release redundant prepared payload references after capture while preserving full-prefix replay across suffix retries and replacement after full-history recovery.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +4, Tests +53. Total +57 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 2 +4
Tests 1 53 0 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 59 2 +57

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The preparation gap interrupts background fork verification with limited blast radius and no demonstrated foreground data loss.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • 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-10-15T21:39:41.405Z sha 5912dc9 :: needs maintainer review before merge. :: none

Reviewed October 15, 2026, 5:50 PM ET / 21:50 UTC (Revision 2).

@obviyus

obviyus commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 4d13205 into main Oct 15, 2026
122 checks passed
@obviyus
obviyus deleted the fix/session-fork-snapshot-lifetime branch October 15, 2026 22:04
obviyus added a commit that referenced this pull request Oct 15, 2026
## What Problem This Solves

Fixes repeated plugin steering reaching the model twice, and rejected native guidance being retained as if it had been delivered.

## User Impact

Plugins can retry steering without injecting the same guidance twice, including after a successor run starts. A native steer rejected before dispatch leaves no guidance in subsequent model context and can be retried after plugin reload. No configuration, schema, or stored-row shape change is required.

## Why This Change Was Made

Transcript idempotency alone did not protect the active-run input queue. The existing run registration now joins pending/accepted admissions after authority validation, and the plugin host checks the durable session/key owner before dispatch. Stored steering receipts replay the original run ID, matching `src/gateway/server-methods/inflight.ts:38-51`; older rows without a receipt return terminal `duplicate`. Rejected queue reservations are released.

Codex previously appended internal guidance before the final physical-send authority check. It now retains preceding tool-result mirroring and inbound user persistence, but appends internal plugin guidance only after native acceptance or accepted-unconfirmed delivery. Accepted history can still be recorded if the plugin is subsequently disposed; session/storage identity guards remain. This prevents rejected guidance from poisoning both replay and same-key retry without adding stored fields.

The independent fork snapshot repair moved to #173489. Advisor cancellation and duplicate-fallback handling are in #173459.

## Evidence

- Baseline `5678421c757`: sequential/concurrent duplicate-key regressions persisted one row but admitted two model-input messages.
- Successor-run regression: before the durable check, the same key was accepted by a later run rather than deduplicated.
- Native regression: before the producer fix, pre-wire disposal left a hidden transcript row, included it in `SessionManager` model context, and caused a reloaded plugin's retry to return `duplicate`. Afterward, rejected guidance is absent from both transcript and context; retry reaches native `turn/steer` once. Accepted-then-disposed guidance still persists once.
- Focused steering, native admission/authority/settlement, recorder, and recorder-persistence tests passed. Changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- The pre-review-fix combined raw-evidence campaign tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`: **80 PASS / 5 FAIL → 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs: **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**. Totals include added successor/channel coverage rather than an identical inventory.
- That campaign proves same-run and successor-run idempotency, abort/overlap handling, display isolation, and built-in/native minutes verification. The later rejected-guidance producer fix is separately covered by the focused native regression above, not claimed as part of that campaign.
- Focused native follow-up tested `0903019c1131cfa29a81b4e192c3353fb65a3def` (integration `998ff42a15f` plus the display fix): **36 PASS / 0 FAIL / 0 UNPROVED**. Live Codex tool-call, minutes, abort, overlap, and same-key within/across runs passed; every accepted steer row preceded its first provider request. A controlled native-transport probe separately proved pre-wire rejection leaves no row or wire request, then same-key retry delivers exactly once. The controlled rejection probe is not claimed as live-daemon fault injection.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 15, 2026
## What Problem This Solves

Fixes Advisor guidance arriving after an aborted run, or remaining queued from a stale review after a new user turn starts.

## User Impact

Aborting work also cancels its in-flight Advisor review and verification. Starting a new user turn drops unfinished advice based on the preceding turn instead of delivering it later. A duplicate steering outcome never creates fallback guidance. Normal run-end fallback remains supported.

## Why This Change Was Made

The lifecycle subscription treated aborted terminal events like ordinary completion, ignoring their `aborted` flag. The controller also retained in-flight reviews when a new user run replaced the previous one. These transitions now cancel the stale review at the owning controller, preventing both active delivery and fallback queueing.

Duplicate keys are terminal no-ops rather than unavailable steering, so the fallback path now leaves them alone.

## Evidence

- Reproduced on `5678421c757`: aborted `end` and `error` events left the review signal active; regression assertions failed with `expected false to be true`.
- Reproduced active delivery followed by another pending review spanning a new user turn; its cancellation assertion failed on the baseline.
- A duplicate-result regression also demonstrated an unwanted fallback queue entry before its repair.
- All 51 Advisor tests passed, including cancellation, duplicate handling, normal run-end fallback, tool settlement, verification, and interval accounting. Combined owner checks covered 127 distinct tests; changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- Final raw-evidence campaign combined this head `1fac8ffa671`, core head `5677912be70` (#173458), and display fix `07c940c6959` (#173460); tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`.
- Executable invariants: **before 80 PASS / 5 FAIL; after 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs improved **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**; totals include different commissioning/channel coverage and the new successor-run case.
- The accepted abort left zero queued notes. The overlapping user turn retained one active correction and zero queued copies. Built-in minutes review completed verification and delivered once. Provider requests, SQLite rows, and events independently establish these outcomes.
- A/B behavior stayed unchanged: Advisor-on 4 tool calls / 2 repeated actions, solved; off 8 / 7, unresolved. Actual Codex tool/minutes and late-snapshot Telegram persistence/display/recipient checks passed. No active-session compaction occurred; that RPC remained refused.
- The fork slice from the tested core revision is now isolated in #173489; #173458 retains steering deduplication and the later native rejected-guidance producer repair.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 4d13205. A session fork's prepared snapshot is now kept until its same-run replacement is ready, so a verify fork started while the next parent request is being prepared no longer fails. Reset/delete still revoke. Proof: two regressions failing before; built-in real-clock minutes review and verify delivered in the raw-evidence campaign; exact-head CI green.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…aw#173489)

## What Problem This Solves

Fixes background session-fork verification failing while the parent prepares its next model request.

## User Impact

Advisor can finish a review and its verification across a parent-request preparation boundary instead of failing with a missing prepared-parent error. No configuration or storage migration is required.

## Why This Change Was Made

The fork owner removed the current prepared snapshot as soon as another parent request began, before asynchronous payload preparation published its replacement. A review could finish inside that gap while verification found no snapshot.

Keep the last committed snapshot for the same run and transport until atomic replacement. New runs/transports still retire the previous snapshot; reset/delete revocation and existing TTL, count, and byte bounds remain intact. Ordinary run-end disposal already preserves provider resources, so no attempt-stream-settle change is needed.

This independent fork slice was extracted from openclaw#173458; steering idempotency and rejected-guidance delivery remain there.

## Evidence

- On baseline `4bf119f2359`, `keeps review and verification available while the next parent request is being prepared` failed at the verification call with `Cache-parity session fork requires a parent turn prepared by this OpenClaw runtime. Send a normal message first.`
- The sibling reset regression proves a pending preparation cannot restore a reset parent.
- On this extracted branch, 32 focused tests passed across the fork owner and embedded fork integration suites. Changed-file formatting/lint, scoped tsgo, and diff checks passed.
- The exact fork patch was included in the raw-evidence combined campaign tested at `04a5747760d1e9655b73fac511ddb81fad7a3c97`: **before 80 PASS / 5 FAIL; after 86 PASS / 0 FAIL / 0 UNPROVED**. On shared case/invariant pairs: **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**; totals include differing commissioning/channel coverage.
- The real-clock built-in minutes case completed review, verification, and one hidden delivery after a foreground tool crossed the minute threshold. Actual Codex minutes also passed. Assertions use provider requests, SQLite transcript rows, and tool/event ordering rather than Advisor's log summary.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…aw#173458)

## What Problem This Solves

Fixes repeated plugin steering reaching the model twice, and rejected native guidance being retained as if it had been delivered.

## User Impact

Plugins can retry steering without injecting the same guidance twice, including after a successor run starts. A native steer rejected before dispatch leaves no guidance in subsequent model context and can be retried after plugin reload. No configuration, schema, or stored-row shape change is required.

## Why This Change Was Made

Transcript idempotency alone did not protect the active-run input queue. The existing run registration now joins pending/accepted admissions after authority validation, and the plugin host checks the durable session/key owner before dispatch. Stored steering receipts replay the original run ID, matching `src/gateway/server-methods/inflight.ts:38-51`; older rows without a receipt return terminal `duplicate`. Rejected queue reservations are released.

Codex previously appended internal guidance before the final physical-send authority check. It now retains preceding tool-result mirroring and inbound user persistence, but appends internal plugin guidance only after native acceptance or accepted-unconfirmed delivery. Accepted history can still be recorded if the plugin is subsequently disposed; session/storage identity guards remain. This prevents rejected guidance from poisoning both replay and same-key retry without adding stored fields.

The independent fork snapshot repair moved to openclaw#173489. Advisor cancellation and duplicate-fallback handling are in openclaw#173459.

## Evidence

- Baseline `4bf119f2359`: sequential/concurrent duplicate-key regressions persisted one row but admitted two model-input messages.
- Successor-run regression: before the durable check, the same key was accepted by a later run rather than deduplicated.
- Native regression: before the producer fix, pre-wire disposal left a hidden transcript row, included it in `SessionManager` model context, and caused a reloaded plugin's retry to return `duplicate`. Afterward, rejected guidance is absent from both transcript and context; retry reaches native `turn/steer` once. Accepted-then-disposed guidance still persists once.
- Focused steering, native admission/authority/settlement, recorder, and recorder-persistence tests passed. Changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- The pre-review-fix combined raw-evidence campaign tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`: **80 PASS / 5 FAIL → 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs: **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**. Totals include added successor/channel coverage rather than an identical inventory.
- That campaign proves same-run and successor-run idempotency, abort/overlap handling, display isolation, and built-in/native minutes verification. The later rejected-guidance producer fix is separately covered by the focused native regression above, not claimed as part of that campaign.
- Focused native follow-up tested `0903019c1131cfa29a81b4e192c3353fb65a3def` (integration `998ff42a15f` plus the display fix): **36 PASS / 0 FAIL / 0 UNPROVED**. Live Codex tool-call, minutes, abort, overlap, and same-key within/across runs passed; every accepted steer row preceded its first provider request. A controlled native-transport probe separately proved pre-wire rejection leaves no row or wire request, then same-key retry delivers exactly once. The controlled rejection probe is not claimed as live-daemon fault injection.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…#173459)

## What Problem This Solves

Fixes Advisor guidance arriving after an aborted run, or remaining queued from a stale review after a new user turn starts.

## User Impact

Aborting work also cancels its in-flight Advisor review and verification. Starting a new user turn drops unfinished advice based on the preceding turn instead of delivering it later. A duplicate steering outcome never creates fallback guidance. Normal run-end fallback remains supported.

## Why This Change Was Made

The lifecycle subscription treated aborted terminal events like ordinary completion, ignoring their `aborted` flag. The controller also retained in-flight reviews when a new user run replaced the previous one. These transitions now cancel the stale review at the owning controller, preventing both active delivery and fallback queueing.

Duplicate keys are terminal no-ops rather than unavailable steering, so the fallback path now leaves them alone.

## Evidence

- Reproduced on `4bf119f2359`: aborted `end` and `error` events left the review signal active; regression assertions failed with `expected false to be true`.
- Reproduced active delivery followed by another pending review spanning a new user turn; its cancellation assertion failed on the baseline.
- A duplicate-result regression also demonstrated an unwanted fallback queue entry before its repair.
- All 51 Advisor tests passed, including cancellation, duplicate handling, normal run-end fallback, tool settlement, verification, and interval accounting. Combined owner checks covered 127 distinct tests; changed-file oxfmt/oxlint, scoped tsgo, Madge (0 cycles), and diff checks passed.
- Final raw-evidence campaign combined this head `1fac8ffa671`, core head `5677912be70` (openclaw#173458), and display fix `07c940c6959` (openclaw#173460); tested integration `04a5747760d1e9655b73fac511ddb81fad7a3c97`.
- Executable invariants: **before 80 PASS / 5 FAIL; after 86 PASS / 0 FAIL / 0 UNPROVED**. Shared case/invariant pairs improved **59 PASS / 5 FAIL → 64 PASS / 0 FAIL**; totals include different commissioning/channel coverage and the new successor-run case.
- The accepted abort left zero queued notes. The overlapping user turn retained one active correction and zero queued copies. Built-in minutes review completed verification and delivered once. Provider requests, SQLite rows, and events independently establish these outcomes.
- A/B behavior stayed unchanged: Advisor-on 4 tool calls / 2 repeated actions, solved; off 8 / 7, unresolved. Actual Codex tool/minutes and late-snapshot Telegram persistence/display/recipient checks passed. No active-session compaction occurred; that RPC remained refused.
- The fork slice from the tested core revision is now isolated in openclaw#173489; openclaw#173458 retains steering deduplication and the later native rejected-guidance producer repair.

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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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