Repository navigation
fix(claude-cli): keep each steered input's own origin and context - #185945
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 changesPreserves each steered Claude input’s private context and provenance instead of discarding context or attributing forwarded input to the operator. Example: A subagent returns “The fixture count is 42.” while its Claude parent is busy.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open for merge: this PR fixes a current Claude steering defect, and the prior test-ratchet blocker is resolved; no actionable patch defects remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe CLI runner admits queued session inputs and passes them to the Anthropic plugin, which writes Claude stream-JSON input and supplies private context through UserPromptSubmit; canonical OpenClaw transcripts retain sender attribution. flowchart LR
A[Queued session input] --> B[Session admission]
B --> C[CLI steering adapter]
C --> D[Claude stream transport]
D --> E[UserPromptSubmit context]
E --> F[Claude parent response]
C --> G[Canonical transcript]
Technical reviewBest possible solution: Merge the focused per-input context repair using the existing admission, transport, and transcript owners. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically drops injected prompt context; the submitted real-Claude before/after report corroborates the busy-parent failure, but no target code was executed during this review. Is this the best way to solve the issue? The patch repairs the producer-to-transport handoff through existing owners, shares provenance classification between initial and steered inputs, and retains native lifecycle and admission checks without adding parallel storage or policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 19327c554138. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests +28, Docs +3. Total +44 across 11 files. Added test files: 0. View PR surface stats
Review metrics
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 HistoryReview history (1 earlier review cycle)
Reviewed October 27, 2026, 9:47 PM ET / October 28, 2026, 01:47 UTC (Revision 2). |
3095894 to
366cb08
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 80cc38d.
Thanks @Marvinthebored for finding this and for the original fix in #185915. The private inbound context part follows in a separate PR. |
…r's message (#186439) Related: #185915, #185945 ## What Problem This Solves Fixes: on Claude CLI sessions, OpenClaw put its own context into the text of the user's message: inbound conversation context, the Git co-author note, queued `System:` events, and the session drift and gap notes. Claude saved that text as the user's prompt. Chat history then imported it as a second user bubble, because the importer's text stripping did not recognize every fragment (the co-author note, for example). ## Why This Change Was Made The plugin transport already has a private channel for host context: the `UserPromptSubmit` hook's `additionalContext`, which #185945 also uses for steered inputs. - `buildCliCurrentPrompt` returns the inbound context fragments and the drift/gap notes as `prependContext` when the session runs on the plugin transport. The rendered prompt holds only the sender's text. Other transports keep the old inline rendering. - Native Claude prompts now hold only what the person typed, and forwarded inputs are synthetic meta rows (#185945). So the importer's prompt-decoration matching has no new input to clean. This PR removes it: - `cli-session-history.prompt-text.ts` (system-event, gap-note, requester-hint and routed-envelope stripping) - the `routed_key` / `undecorated_text` views and the matchers that used them - the display cleanup for unmatched imported rows - History import goes back to the two keys that v2026.10.7 shipped: the text, plus a copy without the drift note. The removed views shipped only on `main` and beta. The history index is an in-memory SQLite table rebuilt on each read, so no stored schema changes. ## User Impact A Claude CLI message shows once in chat history, as the person wrote it. Claude still gets the same context, through the prompt hook. On sessions that ran before this change, rows written by beta builds can show their old context prefix again, as they did on v2026.10.7. ## Evidence **Live, real Claude CLI, Control UI.** Same turns on `main` and on this branch (stacked on #185945): | `main` | this PR | | --- | --- | |  |  | - `main`: the user bubble holds the Git co-author note and the queued `System:` session-creation events above "Reply with exactly the word DONE." - This PR: `chat.history` has one user row per turn, holding only the typed text. Claude's transcript records the same context as `hook_additional_context` on `UserPromptSubmit`. - The busy-parent scenario from #185945 still passes on this branch: the subagent result steered into the running turn reaches the parent, and history shows no extra user rows. **Tests and checks** - `prompt-context.test.ts`, `prepare.durable-context.test.ts`, `prepare.existing-session.test.ts` and `execute.native-history-owner.test.ts` cover the plugin-transport split and the unchanged inline rendering. - All `cli-session-history*`, `session-history*`, `chat-history*cli*`, `strip-inbound-meta` and `cli-runner` suites pass (93 files). - `check:changed` lanes: typecheck, lint and boundaries pass. The dead-export scan flags three exports in files this PR does not touch; `main` has the same failures. Size: +250/−698. Test lines: −240. Credit: @Marvinthebored found this and wrote the private-context change in #185915. This PR is its second part. **Merge danger:** two-way door. A revert restores inline context and the old matchers; nothing persisted changes. Blast radius: Claude CLI prompt rendering on the plugin transport and imported Claude CLI history display. Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#185945) Related: openclaw#185915, openclaw#185746 ## What Problem This Solves Fixes: when a message arrives while a Claude CLI turn is running (for example a subagent's completion while its parent is busy), OpenClaw injects it into that turn. The Claude runtime then dropped that input's private context and never marked it as host input. The parent lost the child's result, and Claude told the model "The user sent a new message". ## Why This Change Was Made The host already prepares each queued input's provenance and `currentInboundContext`. Only the Claude injection path threw them away: - the `UserPromptSubmit` hook returned no context for injected inputs - the native write never set `isSynthetic` Changes: - `CliBackendMessageInjection.queueMessage` takes optional per-input `promptOrigin` and `promptContext`. This is the same contract as the initial prompt. An injected input never inherits the running turn's origin: a person can steer a host turn, and a completion can arrive during a person's turn. - The steering adapter sets them from the input's own transcript provenance and inbound context. - The Claude runtime returns that context from the prompt hook, including on hook reruns, and sends host inputs with `isSynthetic`. - `inter_session` provenance (forwarded messages, subagent completions) is now host input as well as `internal_system`. A message from another session was not typed by this session's operator. - Removed `readClaudeCliInterSessionProvenance`, which read forwarded-message provenance from native prompt text. Forwarded inputs are now synthetic meta rows that the importer never reads. - Local Claude runs always use the plugin transport, and node-placed Claude history is not imported by the Gateway. - So the parser only served transcripts written before this change: those rows now show as plain user rows. The canonical transcript is unchanged: forwarded messages keep their provenance, sender and visibility. ## User Impact A subagent result that arrives while its Claude CLI parent is busy now reaches the parent with its content, and the parent no longer treats it as the user's message. When Claude falls back to another provider, its recent-turns prelude skips forwarded prompts, as it already skips cron and recovery prompts (openclaw#185746). ## Evidence **Live, real Claude CLI (Claude Code 2.1.310).** I ran isolated Gateways on `main` (`30df06f`) and on this branch: - The parent spawns a subagent that must reply with a secret, then runs `sleep 75`, then reports the subagent's reply. - It must not poll or use `subagents`/`sessions_history`. - The subagent finishes during the sleep, so its completion is steered into the running turn. | | Parent's answer | How Claude presented the steered completion to the model | | --- | --- | --- | | `main` | `NO-RESULT` | "The user sent a new message while you were working" | | this PR | the subagent's exact secret | "[MESSAGE FROM NON-USER SOURCE - NOT USER INPUT]", with the completion context | In an earlier run without the polling ban, the `main` parent had to fetch the result itself with `subagents wait` and `sessions_history`. On this branch it already had the result. **Tests** - `execute-plugin.steering.test.ts`: the real Claude stdio transport against a fixture CLI. - Steered `internal_system` and `inter_session` inputs are sent as synthetic; human steering is not. - A steered subagent completion delivers its result ("The fixture count is 42.") through the prompt hook. This fails on `main`. - A recorder failure before native acceptance rejects the input instead of losing it. - `cli-runtime.test.ts`: an injected input's context is returned on the first hook pass and on reruns. - `execute-plugin.test.ts`: the origin comes from provenance kind only. - These suites pass: `cli-session-history.routed-prompts`, `session-history.subagent-visibility`, `chat-history-handler.cli-import`, `cli-session-history*`, `extensions/anthropic/cli-runtime`. - `oxlint` and `oxfmt` are clean. Size: +169/−125. Production is +93/−77; the rest is the steering regression tests (net +28 test lines). The test-line ratchet passes against current `main` without a ceiling change. Credit: @Marvinthebored found this and wrote the original fix and its tests in openclaw#185915. This PR is the first part of that change. **Merge danger:** two-way door. A revert restores the old injection path. Native meta rows already written stay hidden. Blast radius: Claude CLI steered and forwarded inputs, and third-party CLI backends that implement `registerMessageInjection` (the new argument is optional). Co-authored-by: Ayaan Zaidi <[email protected]>
…r's message (openclaw#186439) Related: openclaw#185915, openclaw#185945 ## What Problem This Solves Fixes: on Claude CLI sessions, OpenClaw put its own context into the text of the user's message: inbound conversation context, the Git co-author note, queued `System:` events, and the session drift and gap notes. Claude saved that text as the user's prompt. Chat history then imported it as a second user bubble, because the importer's text stripping did not recognize every fragment (the co-author note, for example). ## Why This Change Was Made The plugin transport already has a private channel for host context: the `UserPromptSubmit` hook's `additionalContext`, which openclaw#185945 also uses for steered inputs. - `buildCliCurrentPrompt` returns the inbound context fragments and the drift/gap notes as `prependContext` when the session runs on the plugin transport. The rendered prompt holds only the sender's text. Other transports keep the old inline rendering. - Native Claude prompts now hold only what the person typed, and forwarded inputs are synthetic meta rows (openclaw#185945). So the importer's prompt-decoration matching has no new input to clean. This PR removes it: - `cli-session-history.prompt-text.ts` (system-event, gap-note, requester-hint and routed-envelope stripping) - the `routed_key` / `undecorated_text` views and the matchers that used them - the display cleanup for unmatched imported rows - History import goes back to the two keys that v2026.10.7 shipped: the text, plus a copy without the drift note. The removed views shipped only on `main` and beta. The history index is an in-memory SQLite table rebuilt on each read, so no stored schema changes. ## User Impact A Claude CLI message shows once in chat history, as the person wrote it. Claude still gets the same context, through the prompt hook. On sessions that ran before this change, rows written by beta builds can show their old context prefix again, as they did on v2026.10.7. ## Evidence **Live, real Claude CLI, Control UI.** Same turns on `main` and on this branch (stacked on openclaw#185945): | `main` | this PR | | --- | --- | |  |  | - `main`: the user bubble holds the Git co-author note and the queued `System:` session-creation events above "Reply with exactly the word DONE." - This PR: `chat.history` has one user row per turn, holding only the typed text. Claude's transcript records the same context as `hook_additional_context` on `UserPromptSubmit`. - The busy-parent scenario from openclaw#185945 still passes on this branch: the subagent result steered into the running turn reaches the parent, and history shows no extra user rows. **Tests and checks** - `prompt-context.test.ts`, `prepare.durable-context.test.ts`, `prepare.existing-session.test.ts` and `execute.native-history-owner.test.ts` cover the plugin-transport split and the unchanged inline rendering. - All `cli-session-history*`, `session-history*`, `chat-history*cli*`, `strip-inbound-meta` and `cli-runner` suites pass (93 files). - `check:changed` lanes: typecheck, lint and boundaries pass. The dead-export scan flags three exports in files this PR does not touch; `main` has the same failures. Size: +250/−698. Test lines: −240. Credit: @Marvinthebored found this and wrote the private-context change in openclaw#185915. This PR is its second part. **Merge danger:** two-way door. A revert restores inline context and the old matchers; nothing persisted changes. Blast radius: Claude CLI prompt rendering on the plugin transport and imported Claude CLI history display. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #185915, #185746
What Problem This Solves
Fixes: when a message arrives while a Claude CLI turn is running (for example a subagent's completion while its parent is busy), OpenClaw injects it into that turn. The Claude runtime then dropped that input's private context and never marked it as host input. The parent lost the child's result, and Claude told the model "The user sent a new message".
Why This Change Was Made
The host already prepares each queued input's provenance and
currentInboundContext. Only the Claude injection path threw them away:UserPromptSubmithook returned no context for injected inputsisSyntheticChanges:
CliBackendMessageInjection.queueMessagetakes optional per-inputpromptOriginandpromptContext. This is the same contract as the initial prompt. An injected input never inherits the running turn's origin: a person can steer a host turn, and a completion can arrive during a person's turn.isSynthetic.inter_sessionprovenance (forwarded messages, subagent completions) is now host input as well asinternal_system. A message from another session was not typed by this session's operator.readClaudeCliInterSessionProvenance, which read forwarded-message provenance from native prompt text. Forwarded inputs are now synthetic meta rows that the importer never reads.The canonical transcript is unchanged: forwarded messages keep their provenance, sender and visibility.
User Impact
A subagent result that arrives while its Claude CLI parent is busy now reaches the parent with its content, and the parent no longer treats it as the user's message. When Claude falls back to another provider, its recent-turns prelude skips forwarded prompts, as it already skips cron and recovery prompts (#185746).
Evidence
Live, real Claude CLI (Claude Code 2.1.310). I ran isolated Gateways on
main(53763ed) and on this branch:sleep 75, then reports the subagent's reply.subagents/sessions_history.mainNO-RESULTIn an earlier run without the polling ban, the
mainparent had to fetch the result itself withsubagents waitandsessions_history. On this branch it already had the result.Tests
execute-plugin.steering.test.ts: the real Claude stdio transport against a fixture CLI.internal_systemandinter_sessioninputs are sent as synthetic; human steering is not.main.cli-runtime.test.ts: an injected input's context is returned on the first hook pass and on reruns.execute-plugin.test.ts: the origin comes from provenance kind only.cli-session-history.routed-prompts,session-history.subagent-visibility,chat-history-handler.cli-import,cli-session-history*,extensions/anthropic/cli-runtime.oxlintandoxfmtare clean.Size: +169/−125. Production is +93/−77; the rest is the steering regression tests (net +28 test lines). The test-line ratchet passes against current
mainwithout a ceiling change.Credit: @Marvinthebored found this and wrote the original fix and its tests in #185915. This PR is the first part of that change.
Merge danger: two-way door. A revert restores the old injection path. Native meta rows already written stay hidden. Blast radius: Claude CLI steered and forwarded inputs, and third-party CLI backends that implement
registerMessageInjection(the new argument is optional).