Skip to content

fix(tui): show tool details for replayed history messages - #546

Merged
huichen merged 1 commit into
mainfrom
claude/tui-history-tool-call
Sep 10, 2026
Merged

huichen merged 1 commit into
mainfrom
claude/tui-history-tool-call

Conversation

@huichen

@huichen huichen commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

Reopening a session in the TUI rendered every past tool call as its raw call id — call_00_xxxxxxxx — instead of the usual read <path> / $ <cmd> / write <path> form.

Root cause

apply_messages (the get_messages replay path) resolved a tool message's display name and arguments from the first tool_call | tool_result block:

let tool = blocks.iter().find(|b| matches!(b["kind"].as_str(), Some("tool_call" | "tool_result")));
cm.name = tool.and_then(|b| b["name"].as_str())...;
cm.tool_args = tool.and_then(|b| b.get("arguments"))...;

In a persisted history the tool entry is a tool_result block, which carries only toolCallId — name and arguments live on the paired tool_call block in the preceding assistant entry (MessageBlock::from_model in packages/rpc). With name unset, render_tool_message fell back to msg.name.or(msg.tool), i.e. the call id. This only affected history; live streaming is fine because tool_start events carry tool_name / tool_args directly.

Fix

Index all tool_call blocks by toolCallId up front, then resolve a replayed tool message's name/arguments through its call id, falling back to the block's own fields when present. Also stops double-encoding arguments that already arrive as a JSON string (Value::to_string on a Value::String).

Tests

Extended welcome_variants_and_messages with a paired tool_call + tool_result history and asserted the rendered frame contains read /tmp/notes.txt and no bare call id.

  • cargo test -p future-tui — 842 + 5 passed
  • cargo fmt -p future-tui --check, cargo clippy -p future-tui --all-targets -- -D warnings — clean

Reopening a session rendered tool calls as their raw call id
(`call_00_...`) instead of the usual `read <path>` / `$ <cmd>` form.

`apply_messages` picked the display name and arguments from the first
`tool_call | tool_result` block. In a session history the tool entry is a
`tool_result` block, which carries only `toolCallId` — the name and
arguments live on the paired `tool_call` block in the preceding assistant
entry. With `name` unset, `render_tool_message` fell back to
`msg.name.or(msg.tool)`, i.e. the call id. Live streaming never hit this
because `tool_start` events carry `tool_name` / `tool_args` directly.

Index the `tool_call` blocks by call id first, then resolve a replayed
tool message's name and arguments through its `toolCallId`. Also avoid
double-encoding arguments that already arrive as a JSON string.
@huichen
huichen enabled auto-merge (squash) September 10, 2026 11:33
@huichen
huichen merged commit 85559e8 into main Sep 10, 2026
12 checks passed
@huichen
huichen deleted the claude/tui-history-tool-call branch September 10, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant