Skip to content

fix(reducer): preserve agent text when message has both text and internal tool-call#1145

Open
AaronZ021 wants to merge 2 commits intoslopus:mainfrom
AaronZ021:upstream-pr/fix-agent-text-swallow
Open

fix(reducer): preserve agent text when message has both text and internal tool-call#1145
AaronZ021 wants to merge 2 commits intoslopus:mainfrom
AaronZ021:upstream-pr/fix-agent-text-swallow

Conversation

@AaronZ021
Copy link
Copy Markdown
Contributor

Problem

When a Claude agent message contains both text content and a tool call to mcp__happy__change_title, EnterPlanMode, or enter_plan_mode, the user's visible text is silently discarded.

Call path

  1. shouldSkipNormalProcessing(msg) is evaluated early in message processing.
  2. It calls parseMessageAsEvent(msg) — if any content item is a change_title / EnterPlanMode tool-call, the whole message is converted to an event like "Title changed to X" or "Entering plan mode".
  3. shouldSkipNormalProcessing returns true, and the reducer never sees the original message. The text content the agent emitted is gone.

In practice, Claude often outputs something like:

"I'll rename this session so it's easier to find later." → change_title({title: "…"})

After this PR: the user sees the explanatory text AND the title updates. Before this PR: the text is silently dropped and the user just sees Title changed to ….

Fix

Two coordinated changes that must land together:

1. sync/reducer/messageToEvent.ts — in parseMessageAsEvent, if the message has meaningful text content alongside tool calls, return null so the message goes through normal rendering. A hasText check excludes the Claude AI usage limit reached|<ts> sentinel (which is legitimately text-only and should still become an event).

2. sync/reducer/reducer.ts — when parseMessageAsEvent returns null, the reducer would otherwise create a visible tool-call UI element for mcp__happy__change_title / EnterPlanMode (now reaching Phase 2 and Phase 4 sidechain processing). Skip these internal tool names in both phases so the text renders cleanly without tool-icon clutter.

Without change (2), change (1) alone would introduce a regression (text appears, but the tool icon is also shown).

Test coverage

No new tests in this PR. The existing reducer spec suite passes; the regression this fixes is invisible to the current tests because they don't assert that text content survives message-to-event conversion. Happy to add a case if the reviewer would like one.

Scope

  • 2 files, 25 lines changed (22 added / 3 removed effectively; see diff).
  • No type changes, no API changes, no behavior change when message has only text or only internal tool calls.
  • Behavior change: when both are present, text is preserved.

Origin

These two commits were carried on a fork for several weeks and proved stable in production use. Extracted onto a clean branch off upstream/main for this PR.


Co-authored-by: Claude (Happy AI pair-programming session) noreply@anthropic.com

…ol call

When an assistant message contained both text content and a
mcp__happy__change_title tool call, parseMessageAsEvent converted the
entire message into an event, discarding the text the user should see.

Fix: when the message has meaningful text alongside tool calls, skip
event conversion so text flows through normal Phase 1 processing.
Also skip mcp__happy__change_title tool calls in Phase 2 so they don't
create visible tool messages in the UI.

Same fix applies to EnterPlanMode tool calls which had the identical bug.
Extend the internal tool call filter to also skip EnterPlanMode in
both Phase 2 (main messages) and Phase 4 (sidechain messages).
Also hide mcp__happy__change_title in sidechain processing.

These internal tool calls should not appear as visible tool messages.
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