Skip to content

fix(web): show only the agent's latest chunk in the magic chip - #6115

Open
404Wolf wants to merge 1 commit into
mainfrom
wolf/magic-chip-fixes
Open

fix(web): show only the agent's latest chunk in the magic chip#6115
404Wolf wants to merge 1 commit into
mainfrom
wolf/magic-chip-fixes

Conversation

@404Wolf

@404Wolf 404Wolf commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Two things, both visible on any Cursor session that narrates between tool calls:

  1. The chip stacked the whole turn's commentary. answerMarkdown joined every text part of the folded turn, so what you read was the sum of all chunks up to that point rather than the agent's reply.
  2. The chip grew and shrank while the agent worked, and a long Thinking detail could extend well past the right edge of the message it sits in.

Fix

Only the last chunk is the answer. The fold coalesces streamed chunks into the trailing text part (agent_fold append_text), so a text part that is no longer last is exactly a chunk the agent moved on from. The answer is the trailing text part and only that.

One fixed row until the answer. Mid-turn prose now rides the activity line as its detail rather than rendering as a block, so a running turn is one h-6 row from the first event to the last. The message below never shifts while the agent works, and an arbitrarily long thought truncates at whatever width the message gives it. The chip takes real height at exactly one moment — when the turn ends.

MagicChipPresentation drops from three states to two (working | settled) as a result. Any ending settles now, not just end_turn, so a cancelled or failed turn still shows the prose it managed with the reason underneath.

Verification

Driven against a live local stack with real Cursor turns.

Height, sampled every 250ms across an 87-second turn — 348 in-flight samples, one distinct height, zero horizontal escapes:

inFlightHeights: [[24, 348]]     // 24px, every sample
overflowEscapes: []              // nothing ever wider than the chip
t=0.0   Waiting for agent   h=24
t=1.3   Thinking            h=24
t=5.0   Writing response    h=24
t=7.3   web_search          h=24
...     (13 transitions)    h=24
t=87.3  Open session        h=2161   <- the one moment it grows

Content — settled on a single 5.5k-char answer opening "Octopuses are the closest thing the ocean has to an alien neighbor", with none of the four narration chunks from that turn leaking in.

bun run check (tsc + biome) clean; 13 tests pass.

Note for review

If a turn ends on a tool call after its last prose, the chip shows "Agent finished without a response" rather than that earlier prose. Consistent with the rule above and Cursor normally ends turns with prose, but it is a live behavior change.


Note

Low Risk
Scoped to Lexical Magic Chip UI and presentation derivation; behavior changes for edge cases (e.g. turn ending on a tool after prose) but no auth, data, or API surface changes.

Overview
Fixes Magic Chip layout and content during agent turns: mid-turn narration no longer stacks or expands the chip, and settled answers use only the final text chunk, not every narration segment in the turn.

Presentation model drops the answering state (working | settled only). answerMarkdown now reads only the trailing text part (aligned with fold coalescing); streaming prose appears on the activity line as detail with “Writing response”. Turns that end with prose settle for any stop kind, with optional footer activity for non–end_turn endings (e.g. cancelled).

MagicChipView uses one grid: quoted markdown when settled, then either the fixed h-6 activity row or “Open session”. Activity line gets overflow-hidden, flex-1, and truncation so long thoughts/commands stay within the message width.

Tests in presentation.test.ts cover the new derivation rules (including last-chunk answer and narration dropped after a tool).

Reviewed by Cursor Bugbot for commit d959700. Bugbot is set up for automated code reviews on this repo. Configure here.

The chip concatenated every text part of a turn, so a Cursor session that
narrated between tool calls stacked its whole running commentary above the
answer. The fold coalesces streamed chunks into the trailing text part
(agent_fold append_text), which makes a text part that is no longer last a
chunk the agent moved on from — so the answer is the trailing text part and
only that.

Mid-turn prose now rides the activity line as its detail instead of
rendering as a block. That holds a running turn to one h-6 row from the
first event to the last, however much the agent narrates: the message below
no longer shifts while the agent works, and a long thought truncates at the
message's width instead of extending past it. The chip takes real height at
exactly one moment, when the turn ends.

Any ending settles, not just end_turn, so a cancelled or failed turn still
shows the prose it managed with the reason underneath.
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 0331f161-c8d0-43ca-9905-349b66df64a1

📥 Commits

Reviewing files that changed from the base of the PR and between d7259f0 and d959700.

📒 Files selected for processing (3)
  • apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/MagicChipView.tsx
  • apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/presentation.test.ts
  • apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/presentation.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Improvements
    • Simplified Magic Chip display states for a more consistent experience during and after responses.
    • In-progress text is shown as activity, while completed responses display only the final answer.
    • Narration before tool activity is no longer incorrectly presented as the final answer.
    • Cancelled responses now settle correctly and retain relevant activity details.
    • Added an “Open session” link when no activity is available.

Walkthrough

Magic Chip presentation now uses working and settled states only. Working prose appears as activity detail, while narration before a tool call is excluded from answer markdown. Settled responses use the final text chunk and can include activity for non-clean endings. MagicChipView uses one layout for markdown, activity, and the “Open session” fallback. Tests cover tool activity, final text selection, and cancelled responses.

Merge Risk: ⚪ Minimal · up to d9597

This localized UI change limits in-progress activity to a fixed row and displays only the latest completed response chunk, with no changes to authentication, data handling, or service interfaces. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the conventional commit format, starts with fix(web):, is 62 characters long, and accurately describes the Magic Chip change.
Description check ✅ Passed The description clearly explains the Magic Chip problems, the implemented fixes, presentation-state changes, edge-case behavior, and verification results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant