Skip to content

fix: preserve completed Claude tool calls in chat history - #203877

Merged
vyctorbrzezowski merged 2 commits into
mainfrom
openclaw/plaid-barnacle-efa374
Nov 23, 2026
Merged

vyctorbrzezowski merged 2 commits into
mainfrom
openclaw/plaid-barnacle-efa374

Conversation

@vyctorbrzezowski

@vyctorbrzezowski vyctorbrzezowski commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

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_error on 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.history example exercises three calls in the same response: ok → completed, error → failed, and missing → 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 main reported the same case and assertion: expected undefined, received "default".

@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XS labels Nov 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The 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.

  • Before: Reloaded history shows Outcome unknown.
  • After: Reloaded history shows the call completed; explicit errors remain failures and missing results remain unpaired.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and source-correct, but the reported real behavior verification is not inspectable and the failing CI check remains unattributed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Successfully finished Claude CLI commands appear to have unknown outcomes after reopening their conversation.
Reason: The maintainer-authored direction restores agreement between live and reloaded activity with a focused provider-specific normalization.

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
Reviewed head: 974e3e0d31c5d08d0dde7118f6d07cc4ac8c6dfb

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Attach sanitized before/after browser captures or raw Gateway output showing an existing Claude conversation reloaded with completed, failed, and missing-result cases, and report whether the regression fails on the base and passes on the head.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Claude tool-result normalization keeps the original intent (ef92380: Available blame carries the result branch through restoration of custom CLI backends and later pipeline refactors; no evidence establishes that omitting successful result classification was intentional, and the original introduction remains unknown.)
  • Documented distinction between results and call-only history keeps the original intent (fix(ui): running tools show unknown after history refresh #185261: Saved calls alone must not establish an execution outcome or retire live facts; the new Claude-specific result rule preserves that distinction.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced production change defaults is_error only inside the Claude tool_result branch; explicit true remains true, and tool calls receive no success flag. (src/gateway/cli-session-history.claude.ts:177, 974e3e0d31c5)
  • Current main remains affected: Current main preserves an omitted error flag in imported tool results; history projection consumes that optional flag, whereas Claude live-event handling treats is_error !== true as successful for ordinary tool_result blocks. (src/gateway/cli-session-history.claude.ts:175, ee9fb85d0960)
  • Owning-boundary regression: The added test feeds native Claude rows through the real chat.history handler and asserts completed, failed, and unpaired outcomes together; its response callback is mocked, rather than its import or projection decisions. (src/gateway/server-methods/chat-history-handler.cli-import.test.ts:213, 974e3e0d31c5)
  • Proof supplied in discussion: The full PR body reports seven corrected calls and a browser label change, but contains no screenshot, recording, raw output, or linked verification artifact; both discussion comments are review-status messages. (974e3e0d31c5)
  • CI failure requires attribution: The reviewed-head job fails in session-utils-store-lookup.test.ts:716 because a model override field is default instead of undefined; inspected base annotations did not establish the same failure, so it is not classified as inherited or PR-caused. (src/gateway/session-utils-store-lookup.test.ts:716, 974e3e0d31c5)
  • No durable model migration: The changed value is produced during import; source transcripts remain unchanged and the SQLite display index is reconstructible temporary storage. (src/gateway/cli-session-history-index.worker.ts:54, 974e3e0d31c5)

Likely related people:

  • Peter Steinberger: Raw commit e52c9a8 adds src/gateway/cli-session-history.claude.ts:167 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e52c9a89197f; files: src/gateway/cli-session-history.claude.ts)

PR surface

Source +2, Tests +40, Docs +2. Total +44 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 0 +2
Tests 2 42 2 +40
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 48 4 +44

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Incorrect completed-tool status after reload causes user confusion but does not rerun commands or block conversation use.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Incorrect completed-tool status after reload causes user confusion but does not rerun commands or block conversation use.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 22, 2026, 9:09 PM ET / November 23, 2026, 02:09 UTC.

obviyus added a commit that referenced this pull request Nov 23, 2026
…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]>
@vyctorbrzezowski
vyctorbrzezowski merged commit a27b4e6 into main Nov 23, 2026
143 of 146 checks passed
@vyctorbrzezowski
vyctorbrzezowski deleted the openclaw/plaid-barnacle-efa374 branch November 23, 2026 05:46
@vyctorbrzezowski

Copy link
Copy Markdown
Member Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 24, 2026
…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
obviyus added a commit that referenced this pull request Nov 26, 2026
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 27, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* 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]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant