Repository navigation
fix(cli): refuse saved history only when another CLI account ran the session - #202428
Conversation
…session Co-authored-by: obviyus <[email protected]>
|
🦞👀 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: blocked before merge. What this changesThis PR replaces transcript coverage tracking with a session-level CLI account check for saved-history replay. Example: After Gemini records GOAL_TOKEN aurora-7 and DEPLOY_REGION QUARTZ-ZETA-41, the chat switches to Claude CLI.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep open: this maintainer-authored PR addresses demonstrated context loss, but the remaining test and ratchet migrations need completion before merge. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherCLI preparation resolves the selected account, checks private session metadata, and supplies eligible saved conversation history to the native CLI execution path. flowchart TD
A[Chat turn] --> B[Resolve CLI account]
B --> C[History admission]
D[Session account metadata] --> C
C --> D
C --> E[Prepare conversation context]
F[Saved transcript] --> E
E --> G[Native CLI execution]
Technical reviewBest possible solution: Keep the single admission owner and complete the existing test, baseline, documentation, and stored-state compatibility work. Do we have a high-confidence way to reproduce the issue? Current-main source shows why other-runtime history is refused, and the supplied real-Gateway comparison demonstrates that failure on the pinned base; no target code was executed during this review. Is this the best way to solve the issue? The existing session-entry owner can hold the account decision without per-write coverage machinery, and the maintainer-authored proposal explains the changed privacy contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2e3fd02ff122. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1223, Tests -2102, Docs +6, Generated 0. Total -3319 across 75 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 20, 2026, 5:54 AM ET / 10:54 UTC. |
…utover Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
… ran Co-authored-by: obviyus <[email protected]>
…y-account-check # Conflicts: # docs/.generated/config-baseline.sha256
|
Maintainer override: the only red required job on head
All other checks pass, and the local review of this exact head is clean ( |
…y-account-check # Conflicts: # src/agents/cli-runner/history-boundary.test.ts
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
…y-account-check # Conflicts: # config/session-identity-allowlist.txt # src/agents/cli-runner/execute-node-claude.ts # src/agents/cli-runner/execute-plugin.ts # src/agents/cli-runner/execute-process.ts # src/agents/cli-runner/execute.ts # src/agents/cli-runner/history-boundary.test.ts # src/agents/cli-runner/history-boundary.ts
Co-authored-by: obviyus <[email protected]>
…y-account-check # Conflicts: # docs/.generated/config-baseline.sha256
|
Maintainer override for head
These jobs run on this PR only because it touches shared session/runner files, so the changed-scope lanes select these suites. The The local review of this exact head is clean ( |
|
Landed as 5ec2039.
|
…session (openclaw#202428) ## Problem A fresh Claude CLI session only received a chat's saved history when OpenClaw could prove that every stored row was written by an earlier `claude-cli` run under the same account. Any row it could not attribute, such as turns written by Gemini or Codex, turns from a native Claude login without the attestation opt-in, legacy rows or imports, made the whole chat `auth-unknown` and refused for good. As a result, switching an existing chat from another model to Claude dropped all context. The Gateway logged `cli session history refused across auth boundary: reason=auth-unknown`, and the new Claude session got only the current message. The rest of OpenClaw already replays the full conversation to Gemini, OpenAI and Codex on every switch without any such check. The case openclaw#140294 actually guards against still matters: account A's history must not be replayed into a session for account B. Enforcing it took per-row coverage watermarks, a CLI history writer carried through every transcript write path, owner probes over `SharedArrayBuffer` in the SQLite workers, native-login rechecks at spawn, prompt send and prompt-hook time, refresh-due handling, a compaction coverage commit and a terminal write context. All of that existed only to keep the proof alive. ## Solution The session now records the first identified CLI account that runs it. That is a fingerprint of a resolved API key or token, a named OAuth account, or an attested native login. The account is checked once, when a turn is prepared: - **No account recorded yet:** history replays. This includes turns from other runtimes and from an unidentified login. The first identified account is recorded. - **Same account as recorded:** history replays. - **Different or unidentified account after one was recorded:** that turn runs without saved history and the session is marked `mixed`. Every later CLI turn in the session also runs without saved history, including a switch back to the original account. `/new` (a new session id) starts clean. `admitCliHistoryAccount` is the single owner of this decision. Everything that existed only to keep the coverage proof alive is deleted: the writer async context, coverage advance in all worker and actor write paths, owner probes, the `cliHistory` patch guard, the compaction coverage commit, the native-login recheck hooks (`assertReadable`, `assertPrivateInputCurrent`, `bindExecutionEnv`, `settleNativeLogin`, the refresh-due handling), the node dispatch readable hook, and the CLI-only terminal write context (`bindAgentRunTerminalWriteContext`, `runInAgentRunWriteContext`, `clearAgentRunTerminalWriteContext`). **Stored data:** no schema change. Existing `known` records keep their account fingerprint, which is derived the same way as before. Old `unknown` records mean "no proof", so they are treated as no account recorded. The new `mixed` state is never read as `known` by older binaries, so a downgrade fails closed. **Accepted edge case:** if a chat runs on an unidentified login first and an identified account second, the unidentified turns replay to that account. These are the same session's own turns, and every other runtime already replays them. ## Impact - Switching a chat from Gemini or Codex to `claude-cli` now carries its history into the fresh Claude session. - Native Claude logins without the attestation opt-in now recover history in chats that no other identified account has run. - An account change still keeps the earlier account's history out of the prompt. The transcript itself is untouched, and Claude can still read it through `sessions_history` when tool policy allows. - Production code: **+455 −1,678 (net −1,223)**. Tests: net −2,102. Docs updated in `docs/gateway/cli-backends.md` and the anthropic plugin help text. ## Evidence **Live E2E.** Each side ran on an isolated scratch Gateway with a real Gemini model and a real `claude-cli` (Claude Code 2.x) on an Anthropic API-key profile pinned with `sessions.patch` `anthropic/claude-sonnet-4-6@anthropic:manual`. **Journey 1:** 10 Gemini turns that set `GOAL_TOKEN aurora-7` and `DEPLOY_REGION QUARTZ-ZETA-41`, then a switch to Claude asking for both values without using tools. | | base `1740e1e9be50` | head | |---|---|---| | Claude answer | `NOT_IN_CONTEXT` | `GOAL_TOKEN: aurora-7 \| DEPLOY_REGION: QUARTZ-ZETA-41` | | first Claude prompt | current message only, refused (`auth-unknown`) | `<conversation_history>` envelope, 30,874 chars, both facts, no tool calls | **Journey 2:** key A stores `SECRET_A`, then the session switches to a different key B, then back to A. - **Base and head:** key B's fresh session received no history; head logged `refused ... auth-unknown`, and B's prompt was 95 characters with no `SECRET_A`. - **Back on key A:** the run resumed A's own native Claude session, which already held the secret. Nothing was replayed. **Tests:** - New: `history-boundary.test.ts`, which covers other-runtime replay, the A→B→A no-laundering case, an unidentified login after a recorded account, `/new`, and named versus identity-less OAuth. Also `prepare-native-history.test.ts`, which covers an unidentified native login. - Red on base: the other-runtime replay case was run against the base checkout and failed (no reseed prompt). - Green: `tsgo:core`, `tsgo:extensions`, `check:test-types`, oxlint, oxfmt, the line-cap ratchet and `config:docs:check`. Touched directories pass under `ocx test`: `src/agents/cli-runner`, `src/config/sessions`, `src/agents/sessions`, `src/infra/outbound`, `extensions/anthropic`, `src/auto-reply/reply`, `src/agents/command`, plus the Gateway lifecycle and fallback transcript tests. Related: openclaw#140294 (the original boundary), openclaw#202341 (unified context handoff; these changes are independent). Co-authored-by: Ayaan Zaidi <[email protected]>
* fix: keep agent temporary files in owned scratch * fix: preserve sandbox temp access and queued isolation custody (cherry picked from commit f91bc99) Release adaptation: keep the staged #202815 Git shim implementation and independently assert both Git shim execution and writable owned temp in its merged Docker/Podman fixture. Use the beta.3 isolated custody configuration (896f33d52174), not ambient sandbox inventory. Companions: #193677 scratch expiry owner is present (99ba844); #202815 is present-equivalent (7d33d1a). #202122 is independent Git/scratch clone reclamation, #202428 is CLI history ownership, #202644 is host file-write authority, and #202874 is workspace cleanup scheduling; none prerequisite. Other later same-path commits concern separate template, sandbox, prompt, sharing, or run-lifecycle policy; see the lane companion audit. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a4070bc5b669308210b62a0b80b92c16af768b34)
Problem
A fresh Claude CLI session only received a chat's saved history when OpenClaw could prove that every stored row was written by an earlier
claude-clirun under the same account. Any row it could not attribute, such as turns written by Gemini or Codex, turns from a native Claude login without the attestation opt-in, legacy rows or imports, made the whole chatauth-unknownand refused for good.As a result, switching an existing chat from another model to Claude dropped all context. The Gateway logged
cli session history refused across auth boundary: reason=auth-unknown, and the new Claude session got only the current message. The rest of OpenClaw already replays the full conversation to Gemini, OpenAI and Codex on every switch without any such check.The case #140294 actually guards against still matters: account A's history must not be replayed into a session for account B. Enforcing it took per-row coverage watermarks, a CLI history writer carried through every transcript write path, owner probes over
SharedArrayBufferin the SQLite workers, native-login rechecks at spawn, prompt send and prompt-hook time, refresh-due handling, a compaction coverage commit and a terminal write context. All of that existed only to keep the proof alive.Solution
The session now records the first identified CLI account that runs it. That is a fingerprint of a resolved API key or token, a named OAuth account, or an attested native login. The account is checked once, when a turn is prepared:
mixed. Every later CLI turn in the session also runs without saved history, including a switch back to the original account./new(a new session id) starts clean.admitCliHistoryAccountis the single owner of this decision. Everything that existed only to keep the coverage proof alive is deleted: the writer async context, coverage advance in all worker and actor write paths, owner probes, thecliHistorypatch guard, the compaction coverage commit, the native-login recheck hooks (assertReadable,assertPrivateInputCurrent,bindExecutionEnv,settleNativeLogin, the refresh-due handling), the node dispatch readable hook, and the CLI-only terminal write context (bindAgentRunTerminalWriteContext,runInAgentRunWriteContext,clearAgentRunTerminalWriteContext).Stored data: no schema change. Existing
knownrecords keep their account fingerprint, which is derived the same way as before. Oldunknownrecords mean "no proof", so they are treated as no account recorded. The newmixedstate is never read asknownby older binaries, so a downgrade fails closed.Accepted edge case: if a chat runs on an unidentified login first and an identified account second, the unidentified turns replay to that account. These are the same session's own turns, and every other runtime already replays them.
Impact
claude-clinow carries its history into the fresh Claude session.sessions_historywhen tool policy allows.docs/gateway/cli-backends.mdand the anthropic plugin help text.Evidence
Live E2E. Each side ran on an isolated scratch Gateway with a real Gemini model and a real
claude-cli(Claude Code 2.x) on an Anthropic API-key profile pinned withsessions.patchanthropic/claude-sonnet-4-6@anthropic:manual.Journey 1: 10 Gemini turns that set
GOAL_TOKEN aurora-7andDEPLOY_REGION QUARTZ-ZETA-41, then a switch to Claude asking for both values without using tools.04d1dd10d05eNOT_IN_CONTEXTGOAL_TOKEN: aurora-7 | DEPLOY_REGION: QUARTZ-ZETA-41auth-unknown)<conversation_history>envelope, 30,874 chars, both facts, no tool callsJourney 2: key A stores
SECRET_A, then the session switches to a different key B, then back to A.refused ... auth-unknown, and B's prompt was 95 characters with noSECRET_A.Tests:
history-boundary.test.ts, which covers other-runtime replay, the A→B→A no-laundering case, an unidentified login after a recorded account,/new, and named versus identity-less OAuth. Alsoprepare-native-history.test.ts, which covers an unidentified native login.tsgo:core,tsgo:extensions,check:test-types, oxlint, oxfmt, the line-cap ratchet andconfig:docs:check. Touched directories pass underocx test:src/agents/cli-runner,src/config/sessions,src/agents/sessions,src/infra/outbound,extensions/anthropic,src/auto-reply/reply,src/agents/command, plus the Gateway lifecycle and fallback transcript tests.Related: #140294 (the original boundary), #202341 (unified context handoff; these changes are independent).