Repository navigation
fix: preserve completed Claude tool calls in chat history - #203877
Conversation
OpenClaw-Publication: d3a267f1-3ba5-4fc9-a4dd-3968148f8eb1
|
🦞👀 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 Claude CLI history importer treats a tool result with no error flag as successful. Example: Claude records a successful Bash pwd result containing /tmp without is_error.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete history-status mismatch still present on current main; the focused patch has no identified correctness or security defects. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway imports Claude CLI transcript rows, normalizes their content, and projects tool activity into chat.history responses consumed by chat clients. flowchart LR
A[Claude CLI transcript] --> B[Claude history importer]
B --> C[Normalized messages]
C --> D[History activity projection]
D --> E[chat.history response]
E --> F[Chat clients]
Technical reviewBest possible solution: Keep the normalization in the existing Claude importer so all history consumers receive the correct outcome without changing provider-neutral classification. Do we have a high-confidence way to reproduce the issue? A Claude tool_result without is_error reaches current-main history projection without a known success flag; the added handler regression exercises that exact input, but no target code was run during this read-only review. Is this the best way to solve the issue? This is the smallest complete fix: normalize Claude's omitted success flag at its existing import boundary while preserving explicit failures and the shared renderer's uncertainty contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ee9fb85d0960. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +2, Tests +40, Docs +2. Total +44 across 4 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 22, 2026, 9:09 PM ET / November 23, 2026, 02:09 UTC. |
…ks (#203922) Root cause: src/gateway/chat-display-projection.canvas.ts:207 `extractChatToolResultCanvasPreview` reads the tool result with `readRecord`, which rejects the bare MCP content-block array that the Claude CLI runtime reports as a tool result, and `augmentChatHistoryWithCanvasBlocks` (:288) skips assistant rows, where Claude CLI history coalesces its `tool_result` blocks; so a successful `show_widget` on `agentRuntime: claude-cli` never yields the `type: "canvas"` block live or in `chat.history`. Fixes #203893 Thanks @fonchaves for the detailed report, the captured frames and the root-cause trace. ## Problem On `agentRuntime: claude-cli`, `show_widget` creates the canvas document, but native clients (iOS `OpenClawChatUI`) show no widget: they render inline widgets only from the `canvas` content block, and the Gateway never adds it to the live `chat` final or to `chat.history`. The embedded runtime with the same widget does get the block. - Live: the Claude CLI tool event carries `result: [{type:"text", text:"{...canvas JSON...}"}]` (raw `tool_result.content`). The canvas extractor accepts only a record, so it returns nothing before its text fallback runs. - History: Claude CLI history merges the `tool_result` blocks into the assistant tool-call row (`toolcall` + `tool_result`). The history projection only harvests previews from standalone tool-result rows and passes over assistant rows. ## Fix Both changes are in the existing canvas projection owner; no new block type, extractor, protocol or schema change: - `extractChatToolResultCanvasPreview` treats a bare content-block array as `{ content }`, so it takes the same details/text projection the embedded result shape already uses. - `augmentChatHistoryWithCanvasBlocks` also harvests previews from tool-result blocks inside assistant tool rows and attaches them to the next renderable assistant message, exactly as it already does for standalone tool-result rows. The "Outcome unknown" tool-row status is a separate owner (Claude history `is_error` normalization / activity projection, #203877) and is unchanged here. ## Evidence Built Gateway (`pnpm build` in a secretless `node:24.22.1` container) with `anthropic/claude-sonnet-5-5` on `agentRuntime: claude-cli`, and a stand-in `claude` that emits Claude Code 2.1.330 stream-json (`tool_use` `mcp__openclaw__show_widget`, `tool_result` with the raw MCP content array, text reply) after calling the Gateway's real loopback MCP `tools/call show_widget`, and writes the matching Claude project JSONL. Operator WS client shaped like iOS (`openclaw-ios`, mode `ui`, caps incl. `inline-widgets`, signed device), `chat.send`, live final, `chat.history`. Two runs per side: | case | base 7d0cc1e live / history | fix live / history | |---|---|---| | claude-cli show_widget | `["text"]` / `["text"]` | `["text","canvas"]` / `["text","canvas"]` (same `cv_` id as the tool result) | | claude-cli, no widget | `["text"]` / `["text"]` | `["text"]` / `["text"]` | | embedded runtime show_widget | `["text","canvas"]` / `["text"]` | identical bytes (ids normalized) | | Control UI (web) on claude-cli | 1 rendered widget (from `[embed]` shortcode) | 1 rendered widget (shortcode deduped against the block) | Full receipt: #203922 (comment) Regression tests: one coalesced Claude CLI history case in `chat-display-projection.test.ts`, and the existing live widget snapshot test now feeds one result as the bare Claude CLI array. Both fail on base and pass with the fix. Deltas vs merge base: production +14/-2 (one file), tests +15/-1. ## Merge danger Two-way door: display projection only, no stored state or contract change; a revert fully undoes it. Blast radius: canvas blocks on `chat` finals and `chat.history`/`chat.message.get` for tool results delivered as bare arrays or nested in assistant rows (Claude CLI). The Control UI already dedupes shortcodes against canvas blocks by view id. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…ks (openclaw#203922) Root cause: src/gateway/chat-display-projection.canvas.ts:207 `extractChatToolResultCanvasPreview` reads the tool result with `readRecord`, which rejects the bare MCP content-block array that the Claude CLI runtime reports as a tool result, and `augmentChatHistoryWithCanvasBlocks` (:288) skips assistant rows, where Claude CLI history coalesces its `tool_result` blocks; so a successful `show_widget` on `agentRuntime: claude-cli` never yields the `type: "canvas"` block live or in `chat.history`. Fixes openclaw#203893 Thanks @fonchaves for the detailed report, the captured frames and the root-cause trace. ## Problem On `agentRuntime: claude-cli`, `show_widget` creates the canvas document, but native clients (iOS `OpenClawChatUI`) show no widget: they render inline widgets only from the `canvas` content block, and the Gateway never adds it to the live `chat` final or to `chat.history`. The embedded runtime with the same widget does get the block. - Live: the Claude CLI tool event carries `result: [{type:"text", text:"{...canvas JSON...}"}]` (raw `tool_result.content`). The canvas extractor accepts only a record, so it returns nothing before its text fallback runs. - History: Claude CLI history merges the `tool_result` blocks into the assistant tool-call row (`toolcall` + `tool_result`). The history projection only harvests previews from standalone tool-result rows and passes over assistant rows. ## Fix Both changes are in the existing canvas projection owner; no new block type, extractor, protocol or schema change: - `extractChatToolResultCanvasPreview` treats a bare content-block array as `{ content }`, so it takes the same details/text projection the embedded result shape already uses. - `augmentChatHistoryWithCanvasBlocks` also harvests previews from tool-result blocks inside assistant tool rows and attaches them to the next renderable assistant message, exactly as it already does for standalone tool-result rows. The "Outcome unknown" tool-row status is a separate owner (Claude history `is_error` normalization / activity projection, openclaw#203877) and is unchanged here. ## Evidence Built Gateway (`pnpm build` in a secretless `node:24.22.1` container) with `anthropic/claude-sonnet-5-5` on `agentRuntime: claude-cli`, and a stand-in `claude` that emits Claude Code 2.1.330 stream-json (`tool_use` `mcp__openclaw__show_widget`, `tool_result` with the raw MCP content array, text reply) after calling the Gateway's real loopback MCP `tools/call show_widget`, and writes the matching Claude project JSONL. Operator WS client shaped like iOS (`openclaw-ios`, mode `ui`, caps incl. `inline-widgets`, signed device), `chat.send`, live final, `chat.history`. Two runs per side: | case | base 706c3cf live / history | fix live / history | |---|---|---| | claude-cli show_widget | `["text"]` / `["text"]` | `["text","canvas"]` / `["text","canvas"]` (same `cv_` id as the tool result) | | claude-cli, no widget | `["text"]` / `["text"]` | `["text"]` / `["text"]` | | embedded runtime show_widget | `["text","canvas"]` / `["text"]` | identical bytes (ids normalized) | | Control UI (web) on claude-cli | 1 rendered widget (from `[embed]` shortcode) | 1 rendered widget (shortcode deduped against the block) | Full receipt: openclaw#203922 (comment) Regression tests: one coalesced Claude CLI history case in `chat-display-projection.test.ts`, and the existing live widget snapshot test now feeds one result as the bare Claude CLI array. Both fail on base and pass with the fix. Deltas vs merge base: production +14/-2 (one file), tests +15/-1. ## Merge danger Two-way door: display projection only, no stored state or contract change; a revert fully undoes it. Blast radius: canvas blocks on `chat` finals and `chat.history`/`chat.message.get` for tool results delivered as bare arrays or nested in assistant rows (Claude CLI). The Control UI already dedupes shortcodes against canvas blocks by view id. Co-authored-by: Ayaan Zaidi <[email protected]>
…03877) * fix: preserve completed Claude tool calls in chat history * fix: preserve completed Claude tool calls in chat history OpenClaw-Publication: d3a267f1-3ba5-4fc9-a4dd-3968148f8eb1
Root cause: ui/src/pages/chat/chat-sessions-yield.ts:44 compares raw tool names with `sessions_yield`, which misses the `mcp__openclaw__sessions_yield` name that Claude CLI history keeps. src/gateway/cli-session-history-index-policy.ts `mergeCliHistoryRow` sends native Claude rows to chat.history with no run identity, even though the merge already links each local user turn (`<runId>:user`) to its native prompt. Fixes #206107 Thanks @fubarfu for the report and the clear Codex comparison. ## What changes for users In Claude CLI sessions, Control UI now shows "Waiting for subagents" after `sessions_yield` while the child runs, and "Resumed · … later" after the child wakes the parent, the same as embedded and Codex sessions. The private Yield call no longer shows as a tool row. The "Outcome unknown" rows in the report are already fixed on main by #203877. This PR doesn't touch them. On both main and this branch, tool rows show their real outcome, and a failed tool call shows as failed. ## Why - Claude CLI calls OpenClaw tools over MCP, and its history keeps the bridged name on purpose (`unwrapToolCallForDisplay`). The yield handoff scanner was the one reader that compared raw names, so it never confirmed the yield. It now uses the existing `stripOpenClawMcpToolPrefix`. The paired, completed, non-error and `yielded` receipt checks are unchanged. - The waiting line and the Resumed rule both need the run that handed off. Embedded and Codex rows carry `__openclaw.runId`. Imported Claude rows carried none. The history merge now gives an unmatched native row the run of the local user turn whose native prompt it answers. The only link it uses is the one the merge already has: the prompt's external id matched to the local user row with `<runId>:user`. Synthetic (meta) wake prompts end a turn but stay hidden, so rows of a wake run never inherit the earlier run. The transient prompt anchor is removed at merge, and nothing is stored: the index is the in-memory display projection. There are no schema or transcript changes. ## Evidence Docker (secretless node:24.22.1) Gateway + Control UI built from each SHA. Agent on `claude-cli` with a stand-in `claude` that emits the Claude Code stream-json and project JSONL contract and calls the real OpenClaw MCP server as `mcp__openclaw__session_status`, `mcp__openclaw__sessions_spawn` and `mcp__openclaw__sessions_yield`. Real Chromium. Main and this branch were each run twice, with controls on an embedded-runtime session and a failed claude-cli tool call. Results and screenshots: #206158 (comment) Regressions (each red on main, green here): - `ui/src/pages/chat/chat-sessions-yield.test.ts`: an imported Claude CLI call with its result is confirmed as a pending handoff. - `src/gateway/cli-session-history.test.ts`: native JSONL through the merge gives the turn's run to its tool rows, no run to rows after a meta wake, and no anchor in the output. Co-authored-by: Ayaan Zaidi <[email protected]>
…law#206158) Root cause: ui/src/pages/chat/chat-sessions-yield.ts:44 compares raw tool names with `sessions_yield`, which misses the `mcp__openclaw__sessions_yield` name that Claude CLI history keeps. src/gateway/cli-session-history-index-policy.ts `mergeCliHistoryRow` sends native Claude rows to chat.history with no run identity, even though the merge already links each local user turn (`<runId>:user`) to its native prompt. Fixes openclaw#206107 Thanks @fubarfu for the report and the clear Codex comparison. ## What changes for users In Claude CLI sessions, Control UI now shows "Waiting for subagents" after `sessions_yield` while the child runs, and "Resumed · … later" after the child wakes the parent, the same as embedded and Codex sessions. The private Yield call no longer shows as a tool row. The "Outcome unknown" rows in the report are already fixed on main by openclaw#203877. This PR doesn't touch them. On both main and this branch, tool rows show their real outcome, and a failed tool call shows as failed. ## Why - Claude CLI calls OpenClaw tools over MCP, and its history keeps the bridged name on purpose (`unwrapToolCallForDisplay`). The yield handoff scanner was the one reader that compared raw names, so it never confirmed the yield. It now uses the existing `stripOpenClawMcpToolPrefix`. The paired, completed, non-error and `yielded` receipt checks are unchanged. - The waiting line and the Resumed rule both need the run that handed off. Embedded and Codex rows carry `__openclaw.runId`. Imported Claude rows carried none. The history merge now gives an unmatched native row the run of the local user turn whose native prompt it answers. The only link it uses is the one the merge already has: the prompt's external id matched to the local user row with `<runId>:user`. Synthetic (meta) wake prompts end a turn but stay hidden, so rows of a wake run never inherit the earlier run. The transient prompt anchor is removed at merge, and nothing is stored: the index is the in-memory display projection. There are no schema or transcript changes. ## Evidence Docker (secretless node:24.22.1) Gateway + Control UI built from each SHA. Agent on `claude-cli` with a stand-in `claude` that emits the Claude Code stream-json and project JSONL contract and calls the real OpenClaw MCP server as `mcp__openclaw__session_status`, `mcp__openclaw__sessions_spawn` and `mcp__openclaw__sessions_yield`. Real Chromium. Main and this branch were each run twice, with controls on an embedded-runtime session and a failed claude-cli tool call. Results and screenshots: openclaw#206158 (comment) Regressions (each red on main, green here): - `ui/src/pages/chat/chat-sessions-yield.test.ts`: an imported Claude CLI call with its result is confirmed as a pending handoff. - `src/gateway/cli-session-history.test.ts`: native JSONL through the merge gives the turn's run to its tool rows, no run to rows after a meta wake, and no anchor in the output. Co-authored-by: Ayaan Zaidi <[email protected]>
* fix: preserve completed Claude tool calls in chat history * fix: preserve completed Claude tool calls in chat history OpenClaw-Publication: d3a267f1-3ba5-4fc9-a4dd-3968148f8eb1 (cherry picked from commit a27b4e6) Follow-ups: 49492d7 fix: align Control UI tooling and docs with task card removal (#207747) [not selected for this narrow backport]; cebbb78 fix: keep tagged silent replies out of chat (#207738) [not selected for this narrow backport]; d4e1305 fix: hide desktop Details when there is nothing to show (#205093) [not selected for this narrow backport]; 11b2cf0 fix: keep the selected Review file compact when the tree is open (#203825) [not selected for this narrow backport]; 4be636b feat(ui): offer Add to Home agent when Home sidebar is open (#207773) [not selected for this narrow backport]; f766de4 fix: surface favorites and recommended models in picker search (#201450) [not selected for this narrow backport]; 61a7661 improve(ui): remove suggested-task cards from Control UI (#199167) [not selected for this narrow backport]; 48cc039 fix: keep long process names compact above mobile output (#203767) [not selected for this narrow backport]; 9316f05 fix: show the first message when session naming fails (#205607) [not selected for this narrow backport]; aa4a68f fix(ui): show chat completions as activity rows (#201891) [not selected for this narrow backport]; ec209d0 fix(ui): link selection sessions to their source session (#206509) [not selected for this narrow backport]; 3f475cc fix(ui): keep pre-final assistant text visible after a completed turn (#140835) [not selected for this narrow backport]; 05ec989 fix: keep chat photo previews sharp within their byte limits (#206461) [not selected for this narrow backport]; b3bdfb5 feat(ui): preview CSV chat attachments as tables (#206148) [not selected for this narrow backport]; 6b3ccab fix: show Waiting and Resumed for Claude CLI subagent handoffs (#206158) [not selected for this narrow backport]; 762aa00 fix: keep dictation recording when switching tabs or applications [not selected for this narrow backport]; d3f9fca fix: keep similar subagent names distinct in compact rows (#203777) [not selected for this narrow backport]; 864efbb improve: keep composer error cards on one line (#204337) [not selected for this narrow backport]; d7ed2dd fix: stop replaying Claude progress updates in active chats (#203970) [not selected for this narrow backport]; 269f884 fix: show Claude CLI document uploads only once in chat (#203866) [not selected for this narrow backport]; 4708bac fix(ui): show Linear artwork in chat tool activity (#204414) [not selected for this narrow backport] Co-authored-by: RomneyDa <[email protected]>
…ks (#203922) Root cause: src/gateway/chat-display-projection.canvas.ts:207 `extractChatToolResultCanvasPreview` reads the tool result with `readRecord`, which rejects the bare MCP content-block array that the Claude CLI runtime reports as a tool result, and `augmentChatHistoryWithCanvasBlocks` (:288) skips assistant rows, where Claude CLI history coalesces its `tool_result` blocks; so a successful `show_widget` on `agentRuntime: claude-cli` never yields the `type: "canvas"` block live or in `chat.history`. Fixes #203893 Thanks @fonchaves for the detailed report, the captured frames and the root-cause trace. ## Problem On `agentRuntime: claude-cli`, `show_widget` creates the canvas document, but native clients (iOS `OpenClawChatUI`) show no widget: they render inline widgets only from the `canvas` content block, and the Gateway never adds it to the live `chat` final or to `chat.history`. The embedded runtime with the same widget does get the block. - Live: the Claude CLI tool event carries `result: [{type:"text", text:"{...canvas JSON...}"}]` (raw `tool_result.content`). The canvas extractor accepts only a record, so it returns nothing before its text fallback runs. - History: Claude CLI history merges the `tool_result` blocks into the assistant tool-call row (`toolcall` + `tool_result`). The history projection only harvests previews from standalone tool-result rows and passes over assistant rows. ## Fix Both changes are in the existing canvas projection owner; no new block type, extractor, protocol or schema change: - `extractChatToolResultCanvasPreview` treats a bare content-block array as `{ content }`, so it takes the same details/text projection the embedded result shape already uses. - `augmentChatHistoryWithCanvasBlocks` also harvests previews from tool-result blocks inside assistant tool rows and attaches them to the next renderable assistant message, exactly as it already does for standalone tool-result rows. The "Outcome unknown" tool-row status is a separate owner (Claude history `is_error` normalization / activity projection, #203877) and is unchanged here. ## Evidence Built Gateway (`pnpm build` in a secretless `node:24.22.1` container) with `anthropic/claude-sonnet-5-5` on `agentRuntime: claude-cli`, and a stand-in `claude` that emits Claude Code 2.1.330 stream-json (`tool_use` `mcp__openclaw__show_widget`, `tool_result` with the raw MCP content array, text reply) after calling the Gateway's real loopback MCP `tools/call show_widget`, and writes the matching Claude project JSONL. Operator WS client shaped like iOS (`openclaw-ios`, mode `ui`, caps incl. `inline-widgets`, signed device), `chat.send`, live final, `chat.history`. Two runs per side: | case | base 7d0cc1e live / history | fix live / history | |---|---|---| | claude-cli show_widget | `["text"]` / `["text"]` | `["text","canvas"]` / `["text","canvas"]` (same `cv_` id as the tool result) | | claude-cli, no widget | `["text"]` / `["text"]` | `["text"]` / `["text"]` | | embedded runtime show_widget | `["text","canvas"]` / `["text"]` | identical bytes (ids normalized) | | Control UI (web) on claude-cli | 1 rendered widget (from `[embed]` shortcode) | 1 rendered widget (shortcode deduped against the block) | Full receipt: #203922 (comment) Regression tests: one coalesced Claude CLI history case in `chat-display-projection.test.ts`, and the existing live widget snapshot test now feeds one result as the bare Claude CLI array. Both fail on base and pass with the fix. Deltas vs merge base: production +14/-2 (one file), tests +15/-1. ## Merge danger Two-way door: display projection only, no stored state or contract change; a revert fully undoes it. Blast radius: canvas blocks on `chat` finals and `chat.history`/`chat.message.get` for tool results delivered as bare arrays or nested in assistant rows (Claude CLI). The Control UI already dedupes shortcodes against canvas blocks by view id. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit e4b20b8) Follow-up audit: Apply e4b20b8 before its required visible-answer follow-up 646a2d5. 9fa8d14, b5023a7, and 1948044 trim tests; 79dafa3 fixes local MCP re-auth; 6b3ccab covers handoff labels; a27b4e6 covers Claude activity result status explicitly outside widget projection. Release adaptation: Applied array/coalesced-result projection before the dependent thinking-row follow-up, as specified by the ledger. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Reopening a Claude CLI conversation could show “Commands · Outcome unknown” for commands that had already returned successfully. The same command appeared complete while the conversation was live.
User Impact
Successful calls stay complete after reload. Explicit errors still show as failures, and calls with no recorded result are not marked successful. No command is rerun.
Why This Change Was Made
Claude CLI can omit
is_erroron a successful tool result. The history importer now interprets that omission the same way as live activity. Other providers and the shared activity renderer are unchanged.Evidence
Replaying the affected history changed seven recorded calls from unknown to completed. The browser showed “Ran commands” instead of “Commands · Outcome unknown.”
The public, synthetic
chat.historyexample exercises three calls in the same response:ok→completed,error→failed, andmissing→unpairedCall: true. The case passed in the PR run. No private transcript is included.The only failing test in the PR run checks cross-agent model inheritance during session creation, before chat history is read. A scheduled run on unmodified
mainreported the same case and assertion: expectedundefined, received"default".