Repository navigation
fix(agents): prevent next-turn failures after native compaction - #169583
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR waits for pending transcript projection work before starting a durable embedded turn and explains compaction token counts. Example: A gpt-5.4-mini session compacts after two synthetic file reads, then immediately receives a recall request.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes an evidenced foreground-turn failure still present on main, with useful live proof and no actionable defect found. Required CI is still running. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded runner admits queued session turns, waits for maintenance, and hydrates bounded saved history before inference; transcript reconciliation independently publishes the readable SQLite projection. flowchart TD
A[Foreground turn] --> B[Session lane]
B --> C[Deferred maintenance settlement]
C --> D[Projection readiness wait]
D --> E[Global lane admission]
E --> F[Bounded history hydration]
F --> G[Model inference]
Technical reviewBest possible solution: Settle the existing session projection at foreground admission while preserving bounded readers, cancellation, and caller-owned transcript isolation. Do we have a high-confidence way to reproduce the issue? The current-main admission path exposes the reported projection-readiness gap, supported by concrete before-fix CLI failure logs; this read-only review did not execute target code. Is this the best way to solve the issue? The focused barrier reuses the authoritative readiness owner at the existing maintenance checkpoint and avoids inference retries, weaker history guards, or another storage mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dafb31c14dfa. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +86, Docs +7. Total +97 across 3 files. Added test files: 0. View PR surface stats
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 Reviewed October 11, 2026, 11:54 PM ET / October 12, 2026, 03:54 UTC. |
…claw#169583) Related: openclaw#168164 ## What Problem This Solves Fixes the next user turn failing with `Session transcript projection is rebuilding` after provider-native compaction and foreground preemption of session maintenance. ## User Impact The next embedded turn waits for the session's pending transcript projection before reading its saved history. Cancellation remains respected, and detached in-memory transcripts do not wait on unrelated durable state. No configuration, schema, or persisted-format changes. ## Why This Change Was Made The session lane already waits for deferred maintenance, but that work can settle before its independently scheduled transcript projection does. Bounded history hydration then fails closed instead of serving the next turn. Join the existing projection owner at the same pre-global-lane checkpoint; do not retry inference or weaken the history guard. The fail-closed projection guard dates to `9123fde27ed` (openclaw#108851), later extracted by `e227073af94`; the missing foreground barrier predates the native-default change. openclaw#168164 (`5d2c461f092d`) made the API-key compaction path part of the default behavior. This patch does not change the provider's compaction policy. The accompanying request-shape investigation found **no covered-history replay bug** in the reported token growth. Original captures show zero input items before each replayed checkpoint. The mini-model requests had 6, 9, and 8 input items: one checkpoint followed by 5, 8, and 7 later items, respectively. Instructions and tools are still sent, and the model produced new reasoning/tool calls after the inline checkpoint. The docs now explain why token totals alone cannot establish replay duplication. No overlap with Pash/Sarah changes. ## Evidence ### Before Captured on `75b43f6d31e`, public OpenAI Responses API, API-key authentication, `gpt-5.4-mini`, 50,000-token local context and 22,000-token inline threshold. Two synthetic file reads followed immediately by recall: ```text 2026-10-12T08:59:10.261+05:30 [agent/embedded] context-engine compaction failed errorMessage="Session maintenance yielded to a foreground turn" 2026-10-12T08:59:16.125+05:30 [diagnostic] lane task error: lane=main durationMs=98 error="Session transcript projection is rebuilding: f126b9b2-109e-4efc-8ff5-d3e1f471ff8c" errorName=SessionTranscriptProjectionUnavailableError taskKind=turn sessionKey=agent:main:v2b-b-gpt-5.4-mini-1791775686 runId=511762d8-1d3f-4bf4-8ac3-4c740679cc52 ``` Recall CLI exited 1 before inference. Inline-request input grew through 23,318 / 25,799 / 40,603 / 52,261 tokens; explicit compaction consumed 55,953 input tokens. ### After One new isolated live campaign with the same API-key model, limits and synthetic two-file/recall flow reproduced the maintenance-preemption condition, but recall completed: ```text 2026-10-12T09:16:43.495+05:30 [agent/embedded] context-engine compaction failed errorMessage="Session maintenance yielded to a foreground turn" 2026-10-12T09:16:49.874+05:30 Vault code 7291-HERON, courier Isadora, city Hobart. 2026-10-12T09:16:49.876+05:30 [agents/agent-command] [agent] run 53ceae27-6416-4eb2-a68f-c90bd3942337 ended with stopReason=stop ``` Both CLI turns exited 0; recall preserved all 3 planted facts. Explicit compaction consumed 55,074 input tokens; the next user request consumed 18,422 and contained exactly `[compaction, message:user, message:developer]`, with no pre-checkpoint items. The isolated Gateway was stopped and its 0600 credential file deleted. ### Regression and checks - New regression fails before the patch with `SessionTranscriptProjectionUnavailableError: Session transcript projection is rebuilding: foreground-projection`; it passes after the patch using a real SQLite projection rebuild and bounded hydration. - `node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run-orchestrator.projection.test.ts`: 8 passed. Test execution 27.67 s; wrapper wall time 47.59 s. The added case took 3.633 s in that run. - `pnpm tsgo:core` and `pnpm tsgo:test:src`: passed. - Repository `oxfmt`, focused `oxlint`, and `git diff --check`: passed. - One `pnpm build` with the runtime-only declaration-skip flag and shared build cache: exited 0. It reported the existing advisory Control UI chat-boot request count (38 vs 35); this patch does not change UI code. **Merge risk:** two-way door; reverting restores the previous timing behavior. The blast radius is embedded durable-session startup while a transcript projection rebuild is pending. No schema or storage-format changes, no provider request changes, and no ChatGPT V2 changes. Co-authored-by: Ayaan Zaidi <[email protected]>
) Related: #168164 ## What Problem This Solves Fixes the next user turn failing with `Session transcript projection is rebuilding` after provider-native compaction and foreground preemption of session maintenance. ## User Impact The next embedded turn waits for the session's pending transcript projection before reading its saved history. Cancellation remains respected, and detached in-memory transcripts do not wait on unrelated durable state. No configuration, schema, or persisted-format changes. ## Why This Change Was Made The session lane already waits for deferred maintenance, but that work can settle before its independently scheduled transcript projection does. Bounded history hydration then fails closed instead of serving the next turn. Join the existing projection owner at the same pre-global-lane checkpoint; do not retry inference or weaken the history guard. The fail-closed projection guard dates to `7d71d7cf6b3` (#108851), later extracted by `5621979a469`; the missing foreground barrier predates the native-default change. #168164 (`77e2261b573a`) made the API-key compaction path part of the default behavior. This patch does not change the provider's compaction policy. The accompanying request-shape investigation found **no covered-history replay bug** in the reported token growth. Original captures show zero input items before each replayed checkpoint. The mini-model requests had 6, 9, and 8 input items: one checkpoint followed by 5, 8, and 7 later items, respectively. Instructions and tools are still sent, and the model produced new reasoning/tool calls after the inline checkpoint. The docs now explain why token totals alone cannot establish replay duplication. No overlap with Pash/Sarah changes. ## Evidence ### Before Captured on `16d913005f9`, public OpenAI Responses API, API-key authentication, `gpt-5.4-mini`, 50,000-token local context and 22,000-token inline threshold. Two synthetic file reads followed immediately by recall: ```text 2026-10-12T08:59:10.261+05:30 [agent/embedded] context-engine compaction failed errorMessage="Session maintenance yielded to a foreground turn" 2026-10-12T08:59:16.125+05:30 [diagnostic] lane task error: lane=main durationMs=98 error="Session transcript projection is rebuilding: f126b9b2-109e-4efc-8ff5-d3e1f471ff8c" errorName=SessionTranscriptProjectionUnavailableError taskKind=turn sessionKey=agent:main:v2b-b-gpt-5.4-mini-1791775686 runId=511762d8-1d3f-4bf4-8ac3-4c740679cc52 ``` Recall CLI exited 1 before inference. Inline-request input grew through 23,318 / 25,799 / 40,603 / 52,261 tokens; explicit compaction consumed 55,953 input tokens. ### After One new isolated live campaign with the same API-key model, limits and synthetic two-file/recall flow reproduced the maintenance-preemption condition, but recall completed: ```text 2026-10-12T09:16:43.495+05:30 [agent/embedded] context-engine compaction failed errorMessage="Session maintenance yielded to a foreground turn" 2026-10-12T09:16:49.874+05:30 Vault code 7291-HERON, courier Isadora, city Hobart. 2026-10-12T09:16:49.876+05:30 [agents/agent-command] [agent] run 53ceae27-6416-4eb2-a68f-c90bd3942337 ended with stopReason=stop ``` Both CLI turns exited 0; recall preserved all 3 planted facts. Explicit compaction consumed 55,074 input tokens; the next user request consumed 18,422 and contained exactly `[compaction, message:user, message:developer]`, with no pre-checkpoint items. The isolated Gateway was stopped and its 0600 credential file deleted. ### Regression and checks - New regression fails before the patch with `SessionTranscriptProjectionUnavailableError: Session transcript projection is rebuilding: foreground-projection`; it passes after the patch using a real SQLite projection rebuild and bounded hydration. - `node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run-orchestrator.projection.test.ts`: 8 passed. Test execution 27.67 s; wrapper wall time 47.59 s. The added case took 3.633 s in that run. - `pnpm tsgo:core` and `pnpm tsgo:test:src`: passed. - Repository `oxfmt`, focused `oxlint`, and `git diff --check`: passed. - One `pnpm build` with the runtime-only declaration-skip flag and shared build cache: exited 0. It reported the existing advisory Control UI chat-boot request count (38 vs 35); this patch does not change UI code. **Merge risk:** two-way door; reverting restores the previous timing behavior. The blast radius is embedded durable-session startup while a transcript projection rebuild is pending. No schema or storage-format changes, no provider request changes, and no ChatGPT V2 changes. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 50c3948)
) Related: #168164 ## What Problem This Solves Fixes the next user turn failing with `Session transcript projection is rebuilding` after provider-native compaction and foreground preemption of session maintenance. ## User Impact The next embedded turn waits for the session's pending transcript projection before reading its saved history. Cancellation remains respected, and detached in-memory transcripts do not wait on unrelated durable state. No configuration, schema, or persisted-format changes. ## Why This Change Was Made The session lane already waits for deferred maintenance, but that work can settle before its independently scheduled transcript projection does. Bounded history hydration then fails closed instead of serving the next turn. Join the existing projection owner at the same pre-global-lane checkpoint; do not retry inference or weaken the history guard. The fail-closed projection guard dates to `7d71d7cf6b3` (#108851), later extracted by `5621979a469`; the missing foreground barrier predates the native-default change. #168164 (`77e2261b573a`) made the API-key compaction path part of the default behavior. This patch does not change the provider's compaction policy. The accompanying request-shape investigation found **no covered-history replay bug** in the reported token growth. Original captures show zero input items before each replayed checkpoint. The mini-model requests had 6, 9, and 8 input items: one checkpoint followed by 5, 8, and 7 later items, respectively. Instructions and tools are still sent, and the model produced new reasoning/tool calls after the inline checkpoint. The docs now explain why token totals alone cannot establish replay duplication. No overlap with Pash/Sarah changes. ## Evidence ### Before Captured on `16d913005f9`, public OpenAI Responses API, API-key authentication, `gpt-5.4-mini`, 50,000-token local context and 22,000-token inline threshold. Two synthetic file reads followed immediately by recall: ```text 2026-10-12T08:59:10.261+05:30 [agent/embedded] context-engine compaction failed errorMessage="Session maintenance yielded to a foreground turn" 2026-10-12T08:59:16.125+05:30 [diagnostic] lane task error: lane=main durationMs=98 error="Session transcript projection is rebuilding: f126b9b2-109e-4efc-8ff5-d3e1f471ff8c" errorName=SessionTranscriptProjectionUnavailableError taskKind=turn sessionKey=agent:main:v2b-b-gpt-5.4-mini-1791775686 runId=511762d8-1d3f-4bf4-8ac3-4c740679cc52 ``` Recall CLI exited 1 before inference. Inline-request input grew through 23,318 / 25,799 / 40,603 / 52,261 tokens; explicit compaction consumed 55,953 input tokens. ### After One new isolated live campaign with the same API-key model, limits and synthetic two-file/recall flow reproduced the maintenance-preemption condition, but recall completed: ```text 2026-10-12T09:16:43.495+05:30 [agent/embedded] context-engine compaction failed errorMessage="Session maintenance yielded to a foreground turn" 2026-10-12T09:16:49.874+05:30 Vault code 7291-HERON, courier Isadora, city Hobart. 2026-10-12T09:16:49.876+05:30 [agents/agent-command] [agent] run 53ceae27-6416-4eb2-a68f-c90bd3942337 ended with stopReason=stop ``` Both CLI turns exited 0; recall preserved all 3 planted facts. Explicit compaction consumed 55,074 input tokens; the next user request consumed 18,422 and contained exactly `[compaction, message:user, message:developer]`, with no pre-checkpoint items. The isolated Gateway was stopped and its 0600 credential file deleted. ### Regression and checks - New regression fails before the patch with `SessionTranscriptProjectionUnavailableError: Session transcript projection is rebuilding: foreground-projection`; it passes after the patch using a real SQLite projection rebuild and bounded hydration. - `node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run-orchestrator.projection.test.ts`: 8 passed. Test execution 27.67 s; wrapper wall time 47.59 s. The added case took 3.633 s in that run. - `pnpm tsgo:core` and `pnpm tsgo:test:src`: passed. - Repository `oxfmt`, focused `oxlint`, and `git diff --check`: passed. - One `pnpm build` with the runtime-only declaration-skip flag and shared build cache: exited 0. It reported the existing advisory Control UI chat-boot request count (38 vs 35); this patch does not change UI code. **Merge risk:** two-way door; reverting restores the previous timing behavior. The blast radius is embedded durable-session startup while a transcript projection rebuild is pending. No schema or storage-format changes, no provider request changes, and no ChatGPT V2 changes. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 50c3948)
Related: #168164
What Problem This Solves
Fixes the next user turn failing with
Session transcript projection is rebuildingafter provider-native compaction and foreground preemption of session maintenance.User Impact
The next embedded turn waits for the session's pending transcript projection before reading its saved history. Cancellation remains respected, and detached in-memory transcripts do not wait on unrelated durable state. No configuration, schema, or persisted-format changes.
Why This Change Was Made
The session lane already waits for deferred maintenance, but that work can settle before its independently scheduled transcript projection does. Bounded history hydration then fails closed instead of serving the next turn. Join the existing projection owner at the same pre-global-lane checkpoint; do not retry inference or weaken the history guard.
The fail-closed projection guard dates to
7d71d7cf6b3(#108851), later extracted by5621979a469; the missing foreground barrier predates the native-default change. #168164 (77e2261b573a) made the API-key compaction path part of the default behavior. This patch does not change the provider's compaction policy.The accompanying request-shape investigation found no covered-history replay bug in the reported token growth. Original captures show zero input items before each replayed checkpoint. The mini-model requests had 6, 9, and 8 input items: one checkpoint followed by 5, 8, and 7 later items, respectively. Instructions and tools are still sent, and the model produced new reasoning/tool calls after the inline checkpoint. The docs now explain why token totals alone cannot establish replay duplication.
Evidence
Before
Captured on
16d913005f9, public OpenAI Responses API, API-key authentication,gpt-5.4-mini, 50,000-token local context and 22,000-token inline threshold. Two synthetic file reads followed immediately by recall:Recall CLI exited 1 before inference. Inline-request input grew through 23,318 / 25,799 / 40,603 / 52,261 tokens; explicit compaction consumed 55,953 input tokens.
After
One new isolated live campaign with the same API-key model, limits and synthetic two-file/recall flow reproduced the maintenance-preemption condition, but recall completed:
Both CLI turns exited 0; recall preserved all 3 planted facts. Explicit compaction consumed 55,074 input tokens; the next user request consumed 18,422 and contained exactly
[compaction, message:user, message:developer], with no pre-checkpoint items. The isolated Gateway was stopped and its 0600 credential file deleted.Regression and checks
SessionTranscriptProjectionUnavailableError: Session transcript projection is rebuilding: foreground-projection; it passes after the patch using a real SQLite projection rebuild and bounded hydration.node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run-orchestrator.projection.test.ts: 8 passed. Test execution 27.67 s; wrapper wall time 47.59 s. The added case took 3.633 s in that run.pnpm tsgo:coreandpnpm tsgo:test:src: passed.oxfmt, focusedoxlint, andgit diff --check: passed.pnpm buildwith the runtime-only declaration-skip flag and shared build cache: exited 0. It reported the existing advisory Control UI chat-boot request count (38 vs 35); this patch does not change UI code.Merge risk: two-way door; reverting restores the previous timing behavior. The blast radius is embedded durable-session startup while a transcript projection rebuild is pending. No schema or storage-format changes, no provider request changes, and no ChatGPT V2 changes.