Repository navigation
fix(agents): session-less CLI backends forget the conversation until the first compaction - #168244
Conversation
…the first compaction An opted-in sessionMode none backend starts every turn as a fresh process, but preparation gave its uncompacted transcript no reseed reason, so the model only saw the current message. Use the independent history boundary as the gate and give session-less turns their own non-auth reason; account changes still refuse history.
|
🦞👀 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 changesThe PR restores bounded conversation history for opted-in session-less CLI backends before their first compaction. Example: A backend uses sessionMode "none" with reseedFromRawTranscriptWhenUncompacted enabled.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a current stateless-history failure through the existing owner, with no introduced defect found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI preparation combines the current request with eligible transcript history, then execution checks live history authority before sending input to the backend. flowchart TD
U[Current user request] --> P[CLI preparation]
T[Session transcript] --> A[Account and coverage checks]
A --> P
P --> H[Bounded history prompt]
H --> E[Execution authority check]
E --> B[CLI backend input]
Technical reviewBest possible solution: Land the focused stateless repair while keeping the broader report open for intermittent resume and diagnostic behavior. Do we have a high-confidence way to reproduce the issue? Current-main reason selection and loader gating establish the failure; supplied built-CLI captures and the final-head Gateway results demonstrate the corresponding before-and-after behavior. Is this the best way to solve the issue? The change repairs reason selection at its existing owner while preserving opt-in, account authorization, history bounds, and current-turn exclusion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fe265106c397. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests +47, Docs 0. Total +50 across 4 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label 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 HistoryReviewed October 16, 2026, 11:39 PM ET / October 17, 2026, 03:39 UTC (Revision 3). |
…reseed # Conflicts: # docs/gateway/cli-backends.md
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed as 53cfc94. Thanks @masatohoshino for the fix.
|
…the first compaction (openclaw#168244) Related: openclaw#132758 ## What Problem This Solves Fixes: a CLI backend with `sessionMode: "none"` and `reseedFromRawTranscriptWhenUncompacted: true` forgets prior turns until the first compaction. ## User Impact User impact: opted-in session-less CLI backends receive the previous user and assistant exchange on ordinary turns. The independent account boundary still prevents recovery under another account; backends without the opt-in and native-session reuse are unchanged. No new configuration, schema, or protocol is introduced. ## Why This Change Was Made `src/agents/cli-runner/prepare.ts:1474-1478` previously selected no raw-transcript reseed reason for ordinary stateless turns. `src/agents/cli-runner/session-history.ts:682-687` correctly requires an opt-in and a reason before replaying uncompacted durable history, so those turns lost their only continuity. The fix by @masatohoshino assigns the private `stateless` reason at the existing preparation owner, after transcript account authorization. The existing history loader still owns bounds, current-turn exclusion, and compacted-summary selection; there is no second replay path. The contributor's commits are preserved. Main was merged once for takeover and once to include the shared CI repair. The complete change adds 5/removes 2 production lines, adds 47 regression-test lines, and changes one documentation line. The two regression cases cover same-account recovery and changed-account refusal. The issue's separate intermittent `sessionMode: "always"` observation is not claimed fixed. ## Evidence The same Gateway/CLI fixture E2E was run on frozen main `964a9ea2957cdb7a6566daf3d927691ad06a8557` and candidate `0bb3c48750e8316f90563b3290f7a6706dcc78a8`. Only the checkout and recorded SHA changed. Each fresh session seeds the invoice fact, then asks for recall; the fixture records the exact backend stdin and answers from the context it actually receives. | Cell | Before: `964a9ea2957cdb7a6566daf3d927691ad06a8557` | After: `0bb3c48750e8316f90563b3290f7a6706dcc78a8` | | --- | --- | --- | | Stateless fresh session 1 | 831 chars; prior user fact and assistant reply absent; `NO_PRIOR_CONTEXT_168244` | 1311 chars; prior fact and reply present; one history block; `BLUE_FOLDER_168244` | | Stateless fresh session 2 | 831 chars; prior user fact and assistant reply absent; `NO_PRIOR_CONTEXT_168244` | 1311 chars; prior fact and reply present; one history block; `BLUE_FOLDER_168244` | | Control: `sessionMode: "existing"`, no native handle | 1311 chars; prior fact and reply present; `BLUE_FOLDER_168244` | Unchanged: 1311 chars; prior fact and reply present; `BLUE_FOLDER_168244` | | Direct-input control | `BLUE_FOLDER_168244` | `BLUE_FOLDER_168244` | | Gateway health | Initial, after each repeat, and final checks healthy | Initial, after each repeat, and final checks healthy; no plugin errors | The final candidate was rebuilt and the complete core E2E repeated after merging main `43c4becf48da787f2cff77ffb519c03b0b92fc88`, which contains CI repair `01edef4f3f3`. The merge brought only upstream changes, including an upstream `session-history.ts` renderer/type simplification; no PR-authored fix changes were added. Because that owner file changed, old E2E results were not substituted for the final-head rerun. `pnpm install --frozen-lockfile` and the initial build passed; the final-head build also passed. Changed-file `oxfmt --check` and `oxlint` passed before the upstream merge. The local focused test command reached passing existing cases but exceeded its command deadline under host saturation; a narrowed run also exceeded its command deadline during worker preparation. Neither is recorded as a passing suite. **Known pre-existing limitation, outside this fix:** a separate cell forces a real `sessions.compact` through a loopback OpenAI-compatible summarizer, then sends another stateless turn. Frozen main `964a9ea2957cdb7a6566daf3d927691ad06a8557` fails identically in two fresh sessions: compaction succeeds, then the CLI receives 666 chars, zero history blocks, and answers `NO_PRIOR_CONTEXT_168244`. The earlier candidate `f7e886da31390ac06a83cd0a6fd5e91df1fdbf84` has the same result. An untouched `sessionMode: "existing"` session recalled after the other session compacted still receives one history block (1450 chars), answers `BLUE_FOLDER_168244`, and Gateway health remains good. `src/agents/cli-runner/history-boundary.ts:303-312,341-352` detects that the summary rewrite's transcript watermark no longer matches the recorded CLI coverage and writes the boundary as unknown. This is tracked separately rather than weakening the account gate in this change. Retained evidence: `compaction-triage/168244/after-compaction/baseline-repeat-1/observed.json`, `baseline-repeat-2/observed.json`, and `separate-finding.json`. No external model provider or real third-party CLI was called. Final-head [CI run 38995442247](https://github.com/openclaw/openclaw/actions/runs/38995442247) is **green** on `0bb3c48750e8316f90563b3290f7a6706dcc78a8`. The earlier [CI run 38993251384](https://github.com/openclaw/openclaw/actions/runs/38993251384) hit the inherited mock-exports failure also present on [main run 38993173197](https://github.com/openclaw/openclaw/actions/runs/38993173197); the final head includes its upstream repair. Exact-head ClawSweeper review is still pending; [re-review requested](openclaw#168244 (comment)). The contributor's earlier account-change proof remains available: [before](https://raw.githubusercontent.com/masatohoshino/openclaw/proof-assets/20261009-issue-132758/before.txt), [after](https://raw.githubusercontent.com/masatohoshino/openclaw/proof-assets/20261009-issue-132758/after.txt). Merge danger: **two-way door**; reverting fully restores the prior behavior without a migration. Blast radius is opted-in stateless CLI backends before first compaction. An incorrect change could omit or replay conversation context; the existing account-ownership gate and compacted-history selector remain unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
) Related: #132758 ## What Problem This Solves Fixes fresh CLI turns forgetting the conversation after successful Gateway `sessions.compact`, including stateless `sessionMode: "none"` backends. ## User Impact The next fresh CLI turn receives the saved compaction summary and retained recent history once, instead of receiving no history. Unknown or mixed-account history remains ineligible for automatic recovery. No configuration or schema migration is required; this does not relabel already-unknown history as trusted. ## Why This Change Was Made Compaction writes thinking/model bookkeeping before its summary, outside the original CLI writer. The [existing boundary check](https://github.com/openclaw/openclaw/blob/25933024a1e197fa1a503e84b573a47203fc674f/src/agents/cli-runner/history-boundary.ts#L303-L312) then rejects the changed transcript watermark and stores an unknown boundary. The CLI history owner now captures a fully covered source before compaction and re-anchors its unchanged account provenance after successful same-transcript compaction and maintenance. The commit checks the original session, writer, lifecycle, provenance and current transcript watermark. It preserves the exact admitted storage target, including legacy session-store markers. There is no alternative replay path or relaxation of the account check. This restores the documented [CLI recovery contract](https://docs.openclaw.ai/gateway/cli-backends#sessions) and [compaction view](https://docs.openclaw.ai/concepts/compaction#how-it-works): a saved summary plus retained recent messages, not a second copy of raw pre-compaction history. ## Evidence Identical isolated Gateway/CLI E2E cells, with two independent repetitions. The fixture uses a loopback OpenAI-compatible summarizer because the synthetic CLI cannot summarize; no external provider or credentials are involved. | Check | Before: `25933024a1e197fa1a503e84b573a47203fc674f` | After: `eafef138cc674cc8beaa3f93a3b23cc35b4e7250` | | --- | --- | --- | | `sessions.compact` | Successful in both repetitions | Successful in both repetitions | | Next stateless turn | 666-character prompt, zero history blocks; `NO_PRIOR_CONTEXT_168244` | 1,824-character prompt, one history block; `BLUE_FOLDER_168244` | | Compacted view | Missing | Complete saved summary once and the service-selected retained assistant turn once; no raw pre-compaction conversation duplicated alongside it | | Untouched existing-mode control | 1,450 characters, one history block; `BLUE_FOLDER_168244` | Unchanged in both repetitions | | Uncompacted stateless recall | Covered by #168244 | Both independent sessions recalled `BLUE_FOLDER_168244` in each repetition | | Gateway health | Healthy | Healthy after both repetitions | The queued-compaction regression also fails on main `53cfc947f0c6d8c9e2fd8b0a50fb1a5aec89fd17`: a fully covered source stays at sequence 2 instead of the compacted sequence 5. Its foreign-prefix control passes. The candidate's three focused owner suites passed all 49 tests; the five affected regressions passed again after preserving the exact storage-target identity. Direct Oxfmt, Oxlint and whitespace checks passed. The focused tests cover durable and incognito recovery, missing/foreign provenance, writer takeover, cancellation and same-target compaction. ### Authority-chain proof on the exact head Real isolated Gateway + generic stateless CLI backend, two repetitions per cell, repeated on frozen main `53cfc947f0c6d8c9e2fd8b0a50fb1a5aec89fd17` and candidate `eafef138cc674cc8beaa3f93a3b23cc35b4e7250`. Both build stamps match those SHAs. Each run uses a fresh nonsymlinked state directory, an ephemeral loopback port, synthetic credentials and a loopback-only egress guard. | Cell | Frozen main (2/2) | Candidate (2/2) | | --- | --- | --- | | Account A compacts; its next turn is the positive control | 666-character stdin, no summary/history, `NO_PRIOR_CONTEXT_168244` | 1,824-character stdin, saved summary/history, `BLUE_FOLDER_168244` | | Same agent/backend/session is explicitly reassigned to account B using `sessions.patch` (`ctri-none/fixture@ctri-none:account-b`) | B gets 666-character stdin with neither A's folder marker nor A's compaction marker | Identical exclusion: no `BLUE_FOLDER_168244`, no `COMPACTED_ONCE_168244`, no history block; `NO_PRIOR_CONTEXT_168244` | | Live reset/compaction race | Reset queues behind the compaction lifecycle fence, then rotates the lifecycle and clears history provenance | Same ordering; after reset there is no history boundary, no intervening CLI backend call, and the next legitimate turn has neither stale marker | | Retained re-anchor closure guard — **observation-only, not a user path** | Not applicable: main has no re-anchor closure | After real `sessions.reset`, re-invoking the captured production closure rejects with `queued compaction is no longer active`; zero boundary changes and zero CLI backend calls | **Live race ordering:** the synthetic summarizer holds the real `sessions.compact` request after the source boundary is captured. A concurrent real `sessions.reset` remains queued while compaction owns its exclusive lifecycle fence. Releasing the summarizer allows compaction to finish; reset then rotates `lifecycleRevision` (it intentionally preserves this explicit `sessionId`) and removes `cliHistoryBoundary`. The next legitimate CLI turn returns `NO_PRIOR_CONTEXT_168244`, as on main. This is serialization evidence, not a claim that reset interleaves with re-anchoring. **Separate retained-work guard:** an observation-only Node loader retains a reference to the actual production re-anchor closure while returning that same closure unchanged to its normal caller. A fixture-only RPC invokes the retained reference after reset. It fails before any boundary mutation or backend I/O in both repetitions. This is a stale-capability guard check, **not a reproduced user-path race**; no production source or built files were changed. The captured built module's SHA-256 is `b6045a65badfdfebcabe4d9d5cfcadf02e72d37d1651bfcf8b22d668b8844be9`. <details> <summary>Redacted backend-input captures and trace locations</summary> Capture excerpts (synthetic data only; repeated results agree): ```text Account A, candidate: Continue this conversation using the OpenClaw transcript below as prior session history. <conversation_history> ... Compaction summary: ... The invoice remains in BLUE_FOLDER_168244. COMPACTED_ONCE_168244. ... </conversation_history> ... RECALL_168244: Which folder holds the invoice? => BLUE_FOLDER_168244 Account B, both heads (complete 666-character stdin except timestamp): [Sat 2026-10-17 10:11 GMT+5:30] RECALL_168244: Which folder holds the invoice? For the current source conversation, reply normally in your final assistant message; OpenClaw will deliver it through the active source conversation. Commentary is optional progress and may be hidden. Include answers to every still-pending user question, including questions received during ongoing work, in your final response. OpenClaw runtime context: ## Temporal Context Current date: 2026-10-17 Time zone: Asia/Calcutta End OpenClaw runtime context. Current active computer (latest reported app/system input, not message origin): active_node=unknown active_node_identity=unknown => NO_PRIOR_CONTEXT_168244 After reset, retained closure (candidate, both repetitions): {"retained":true,"rejected":true,"error":"Error: queued compaction is no longer active"} boundary before retained invocation == boundary after retained invocation == absent CLI backend calls during compaction/reset/retained invocation: 0 next legitimate CLI turn => NO_PRIOR_CONTEXT_168244 ``` Redacted full stdin and ordering traces are preserved under these local proof-relative paths (not public downloads): - `tmp/cli-history-after-compaction/authority-candidate-final/backend-input.redacted.json` - `tmp/cli-history-after-compaction/authority-candidate-final/trace.redacted.json` - `tmp/cli-history-after-compaction/authority-baseline-final/backend-input.redacted.json` - `tmp/cli-history-after-compaction/authority-baseline-final/trace.redacted.json` - `tmp/cli-history-after-compaction/authority-evidence.json` The actual artifact root is the task's isolated handoff directory; paths above deliberately omit workstation identity. No account-isolation leak, stale boundary mutation, or stale CLI backend invocation was observed. </details> ### Merge danger Two-way code change using the existing private boundary format. Reverting removes preservation for future compactions without requiring a data migration. The blast radius is CLI history recovery after context-engine compaction; an incorrect boundary could withhold or misattribute context, so source coverage, account provenance and current-writer guards remain mandatory. Co-authored-by: Ayaan Zaidi <[email protected]>
- prepare.ts: main's comment lines (openclaw#175226, openclaw#168244) kept; the history gate stays inline on replayableTarget(cliHistoryWriter) as on the branch, so the file does not grow past its line-cap count - cli-runtime.test.ts: main's rewrite (openclaw#174630); the branch's it.for over assertCurrent and assertPrivateInputCurrent and its two private-input tests move into it, and createContext takes ClaudeCliExecuteContext overrides; cli-runtime.test-harness.ts and cli-runtime.private-input.test.ts deleted (the split only kept the old file under the line cap) - history-boundary.test.ts: branch fixture import plus main's prepareCliHistoryCompactionBoundary import (openclaw#175090) - docs/.generated config baseline regenerated with pnpm config:docs:gen - cli-backends.md: main's opaque-login paragraphs (openclaw#174457) now name the attestNativeLogin opt-in
…claw#175090) Related: openclaw#132758 ## What Problem This Solves Fixes fresh CLI turns forgetting the conversation after successful Gateway `sessions.compact`, including stateless `sessionMode: "none"` backends. ## User Impact The next fresh CLI turn receives the saved compaction summary and retained recent history once, instead of receiving no history. Unknown or mixed-account history remains ineligible for automatic recovery. No configuration or schema migration is required; this does not relabel already-unknown history as trusted. ## Why This Change Was Made Compaction writes thinking/model bookkeeping before its summary, outside the original CLI writer. The [existing boundary check](https://github.com/openclaw/openclaw/blob/964a9ea2957cdb7a6566daf3d927691ad06a8557/src/agents/cli-runner/history-boundary.ts#L303-L312) then rejects the changed transcript watermark and stores an unknown boundary. The CLI history owner now captures a fully covered source before compaction and re-anchors its unchanged account provenance after successful same-transcript compaction and maintenance. The commit checks the original session, writer, lifecycle, provenance and current transcript watermark. It preserves the exact admitted storage target, including legacy session-store markers. There is no alternative replay path or relaxation of the account check. This restores the documented [CLI recovery contract](https://docs.openclaw.ai/gateway/cli-backends#sessions) and [compaction view](https://docs.openclaw.ai/concepts/compaction#how-it-works): a saved summary plus retained recent messages, not a second copy of raw pre-compaction history. ## Evidence Identical isolated Gateway/CLI E2E cells, with two independent repetitions. The fixture uses a loopback OpenAI-compatible summarizer because the synthetic CLI cannot summarize; no external provider or credentials are involved. | Check | Before: `964a9ea2957cdb7a6566daf3d927691ad06a8557` | After: `eafef138cc674cc8beaa3f93a3b23cc35b4e7250` | | --- | --- | --- | | `sessions.compact` | Successful in both repetitions | Successful in both repetitions | | Next stateless turn | 666-character prompt, zero history blocks; `NO_PRIOR_CONTEXT_168244` | 1,824-character prompt, one history block; `BLUE_FOLDER_168244` | | Compacted view | Missing | Complete saved summary once and the service-selected retained assistant turn once; no raw pre-compaction conversation duplicated alongside it | | Untouched existing-mode control | 1,450 characters, one history block; `BLUE_FOLDER_168244` | Unchanged in both repetitions | | Uncompacted stateless recall | Covered by openclaw#168244 | Both independent sessions recalled `BLUE_FOLDER_168244` in each repetition | | Gateway health | Healthy | Healthy after both repetitions | The queued-compaction regression also fails on main `e679d022d16fbd0ceac094ee2ecc582125266b58`: a fully covered source stays at sequence 2 instead of the compacted sequence 5. Its foreign-prefix control passes. The candidate's three focused owner suites passed all 49 tests; the five affected regressions passed again after preserving the exact storage-target identity. Direct Oxfmt, Oxlint and whitespace checks passed. The focused tests cover durable and incognito recovery, missing/foreign provenance, writer takeover, cancellation and same-target compaction. ### Authority-chain proof on the exact head Real isolated Gateway + generic stateless CLI backend, two repetitions per cell, repeated on frozen main `e679d022d16fbd0ceac094ee2ecc582125266b58` and candidate `eafef138cc674cc8beaa3f93a3b23cc35b4e7250`. Both build stamps match those SHAs. Each run uses a fresh nonsymlinked state directory, an ephemeral loopback port, synthetic credentials and a loopback-only egress guard. | Cell | Frozen main (2/2) | Candidate (2/2) | | --- | --- | --- | | Account A compacts; its next turn is the positive control | 666-character stdin, no summary/history, `NO_PRIOR_CONTEXT_168244` | 1,824-character stdin, saved summary/history, `BLUE_FOLDER_168244` | | Same agent/backend/session is explicitly reassigned to account B using `sessions.patch` (`ctri-none/fixture@ctri-none:account-b`) | B gets 666-character stdin with neither A's folder marker nor A's compaction marker | Identical exclusion: no `BLUE_FOLDER_168244`, no `COMPACTED_ONCE_168244`, no history block; `NO_PRIOR_CONTEXT_168244` | | Live reset/compaction race | Reset queues behind the compaction lifecycle fence, then rotates the lifecycle and clears history provenance | Same ordering; after reset there is no history boundary, no intervening CLI backend call, and the next legitimate turn has neither stale marker | | Retained re-anchor closure guard — **observation-only, not a user path** | Not applicable: main has no re-anchor closure | After real `sessions.reset`, re-invoking the captured production closure rejects with `queued compaction is no longer active`; zero boundary changes and zero CLI backend calls | **Live race ordering:** the synthetic summarizer holds the real `sessions.compact` request after the source boundary is captured. A concurrent real `sessions.reset` remains queued while compaction owns its exclusive lifecycle fence. Releasing the summarizer allows compaction to finish; reset then rotates `lifecycleRevision` (it intentionally preserves this explicit `sessionId`) and removes `cliHistoryBoundary`. The next legitimate CLI turn returns `NO_PRIOR_CONTEXT_168244`, as on main. This is serialization evidence, not a claim that reset interleaves with re-anchoring. **Separate retained-work guard:** an observation-only Node loader retains a reference to the actual production re-anchor closure while returning that same closure unchanged to its normal caller. A fixture-only RPC invokes the retained reference after reset. It fails before any boundary mutation or backend I/O in both repetitions. This is a stale-capability guard check, **not a reproduced user-path race**; no production source or built files were changed. The captured built module's SHA-256 is `b6045a65badfdfebcabe4d9d5cfcadf02e72d37d1651bfcf8b22d668b8844be9`. <details> <summary>Redacted backend-input captures and trace locations</summary> Capture excerpts (synthetic data only; repeated results agree): ```text Account A, candidate: Continue this conversation using the OpenClaw transcript below as prior session history. <conversation_history> ... Compaction summary: ... The invoice remains in BLUE_FOLDER_168244. COMPACTED_ONCE_168244. ... </conversation_history> ... RECALL_168244: Which folder holds the invoice? => BLUE_FOLDER_168244 Account B, both heads (complete 666-character stdin except timestamp): [Sat 2026-10-17 10:11 GMT+5:30] RECALL_168244: Which folder holds the invoice? For the current source conversation, reply normally in your final assistant message; OpenClaw will deliver it through the active source conversation. Commentary is optional progress and may be hidden. Include answers to every still-pending user question, including questions received during ongoing work, in your final response. OpenClaw runtime context: ## Temporal Context Current date: 2026-10-17 Time zone: Asia/Calcutta End OpenClaw runtime context. Current active computer (latest reported app/system input, not message origin): active_node=unknown active_node_identity=unknown => NO_PRIOR_CONTEXT_168244 After reset, retained closure (candidate, both repetitions): {"retained":true,"rejected":true,"error":"Error: queued compaction is no longer active"} boundary before retained invocation == boundary after retained invocation == absent CLI backend calls during compaction/reset/retained invocation: 0 next legitimate CLI turn => NO_PRIOR_CONTEXT_168244 ``` Redacted full stdin and ordering traces are preserved under these local proof-relative paths (not public downloads): - `tmp/cli-history-after-compaction/authority-candidate-final/backend-input.redacted.json` - `tmp/cli-history-after-compaction/authority-candidate-final/trace.redacted.json` - `tmp/cli-history-after-compaction/authority-baseline-final/backend-input.redacted.json` - `tmp/cli-history-after-compaction/authority-baseline-final/trace.redacted.json` - `tmp/cli-history-after-compaction/authority-evidence.json` The actual artifact root is the task's isolated handoff directory; paths above deliberately omit workstation identity. No account-isolation leak, stale boundary mutation, or stale CLI backend invocation was observed. </details> ### Merge danger Two-way code change using the existing private boundary format. Reverting removes preservation for future compactions without requiring a data migration. The blast radius is CLI history recovery after context-engine compaction; an incorrect boundary could withhold or misattribute context, so source coverage, account provenance and current-writer guards remain mandatory. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #132758
What Problem This Solves
Fixes: a CLI backend with
sessionMode: "none"andreseedFromRawTranscriptWhenUncompacted: trueforgets prior turns until the first compaction.User Impact
User impact: opted-in session-less CLI backends receive the previous user and assistant exchange on ordinary turns. The independent account boundary still prevents recovery under another account; backends without the opt-in and native-session reuse are unchanged. No new configuration, schema, or protocol is introduced.
Why This Change Was Made
src/agents/cli-runner/prepare.ts:1474-1478previously selected no raw-transcript reseed reason for ordinary stateless turns.src/agents/cli-runner/session-history.ts:682-687correctly requires an opt-in and a reason before replaying uncompacted durable history, so those turns lost their only continuity.The fix by @masatohoshino assigns the private
statelessreason at the existing preparation owner, after transcript account authorization. The existing history loader still owns bounds, current-turn exclusion, and compacted-summary selection; there is no second replay path. The contributor's commits are preserved. Main was merged once for takeover and once to include the shared CI repair.The complete change adds 5/removes 2 production lines, adds 47 regression-test lines, and changes one documentation line. The two regression cases cover same-account recovery and changed-account refusal. The issue's separate intermittent
sessionMode: "always"observation is not claimed fixed.Evidence
The same Gateway/CLI fixture E2E was run on frozen main
25933024a1e197fa1a503e84b573a47203fc674fand candidate0bb3c48750e8316f90563b3290f7a6706dcc78a8. Only the checkout and recorded SHA changed. Each fresh session seeds the invoice fact, then asks for recall; the fixture records the exact backend stdin and answers from the context it actually receives.25933024a1e197fa1a503e84b573a47203fc674f0bb3c48750e8316f90563b3290f7a6706dcc78a8NO_PRIOR_CONTEXT_168244BLUE_FOLDER_168244NO_PRIOR_CONTEXT_168244BLUE_FOLDER_168244sessionMode: "existing", no native handleBLUE_FOLDER_168244BLUE_FOLDER_168244BLUE_FOLDER_168244BLUE_FOLDER_168244The final candidate was rebuilt and the complete core E2E repeated after merging main
1acc60d4a153bc0bb637e9ceffd6f22ebfbfc43a, which contains CI repair4513e9e0963. The merge brought only upstream changes, including an upstreamsession-history.tsrenderer/type simplification; no PR-authored fix changes were added. Because that owner file changed, old E2E results were not substituted for the final-head rerun.pnpm install --frozen-lockfileand the initial build passed; the final-head build also passed. Changed-fileoxfmt --checkandoxlintpassed before the upstream merge. The local focused test command reached passing existing cases but exceeded its command deadline under host saturation; a narrowed run also exceeded its command deadline during worker preparation. Neither is recorded as a passing suite.Known pre-existing limitation, outside this fix: a separate cell forces a real
sessions.compactthrough a loopback OpenAI-compatible summarizer, then sends another stateless turn. Frozen main25933024a1e197fa1a503e84b573a47203fc674ffails identically in two fresh sessions: compaction succeeds, then the CLI receives 666 chars, zero history blocks, and answersNO_PRIOR_CONTEXT_168244. The earlier candidatef7e886da31390ac06a83cd0a6fd5e91df1fdbf84has the same result. An untouchedsessionMode: "existing"session recalled after the other session compacted still receives one history block (1450 chars), answersBLUE_FOLDER_168244, and Gateway health remains good.src/agents/cli-runner/history-boundary.ts:303-312,341-352detects that the summary rewrite's transcript watermark no longer matches the recorded CLI coverage and writes the boundary as unknown. This is tracked separately rather than weakening the account gate in this change. Retained evidence:compaction-triage/168244/after-compaction/baseline-repeat-1/observed.json,baseline-repeat-2/observed.json, andseparate-finding.json. No external model provider or real third-party CLI was called.Final-head CI run 38995442247 is green on
0bb3c48750e8316f90563b3290f7a6706dcc78a8. The earlier CI run 38993251384 hit the inherited mock-exports failure also present on main run 38993173197; the final head includes its upstream repair. Exact-head ClawSweeper review is still pending; re-review requested.The contributor's earlier account-change proof remains available: before, after.
Merge danger: two-way door; reverting fully restores the prior behavior without a migration. Blast radius is opted-in stateless CLI backends before first compaction. An incorrect change could omit or replay conversation context; the existing account-ownership gate and compacted-history selector remain unchanged.