Skip to content

fix(native-chat): fold thoughts and tool calls between replies into one row - #26048

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/native-chat-work-runs
Oct 7, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/native-chat-work-runs

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1097
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​460 $\color{#cf222e}{\Huge{\mathbf{−}}}$​57 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​403

ELI5

When an agent thinks before each tool call, the desktop chat drew every thought as its own "Thought for 5s" row between the calls. One answer could take 25 rows to read, for example 13 thoughts and 12 commands. Now everything the agent does between two replies is one row ("Edited 1 file and ran 2 commands"). Open it to see the calls and the thoughts in order.

What Changed

Before

  • Each thinking block was a separate "Thought for Ns" row in the transcript, even mid-task.
  • A thought between two tool calls also stopped those calls from merging, so each call got its own row too. A turn read as Thought / command / Thought / command… while it ran, and again when you expanded a finished turn.

After

  • An unbroken stretch of tool calls and thoughts inside one turn is one tool run row. Its label counts only the tool calls. While the turn works it stays one live row naming the current call, including in turns that edit files.
  • Opening the run shows the thoughts in order among the calls, each still a collapsible "Thought for Ns" that remembers whether you opened it.
  • If the agent's reply already carries tool calls, the run hangs under that reply, so the reply's calls and the ones after its thoughts are one run, not two.
  • Inside an expanded subagent section, the subagent's calls and thoughts group the same way. A thought the subagent is still thinking shows as its own row until it finishes.
  • A lone thought right before a reply still shows as its own row.
  • A run ends at anything that isn't plain tool work: a reply without calls, a new turn, an approval or question, a subagent roster, a background task, or a subagent section that opens in between.
  • Codex and ACP agents: a diff from a file edit always shows under its own edit inside a run. Before, a result that carried no call id was paired with the oldest unanswered call, so a diff could show as a quiet command's output once a run spanned several messages. This also fixes the same mix-up between adjacent calls that already happened on main.

Mechanism

  • Orca already merges a tool-only message into the reply before it. A thinking message ended that merge, so every thought started a new row.
  • src/shared/native-chat-work-run.ts holds the rules as pure functions with no renderer imports: which rows are run work (nativeChatWorkRunMember), where runs start and end (nativeChatWorkRunSpans), and how a run's calls and thoughts interleave.
  • The transcript slot builder is unchanged apart from one final pass (native-chat-transcript-work-runs.ts). Over the slots it has already built, that pass merges each span into one slot that carries every member message (workRun). Anything else that takes a slot (a subagent section heading, a roster, a row that only carries the turn's bar) ends a run just by sitting between its rows, so no special cases are needed. The run takes the turn's status bar from its first member and the turn's changed-files summary from its last. Its estimated height counts one collapsed header (plus a leading reply's text), not the hidden thoughts.
  • NativeChatMessageRow draws both a lone row and a run, so when a row grows into a run it is not remounted and its open state, text selection and a diff you jumped to stay put. It uses the existing NativeChatToolRun, with the thoughts in one keyed list among its lines. Each message keeps its own id, so reveals, disclosure state, diff jumps (re-keyed to the run's numbering) and the task-list history still resolve.
  • structured-agent-session-projection now gives the call and the result built from one journal row a shared id (the provider's call id, else the row's own item id). That is what keeps each diff under its own edit.

Why

This is the common pattern for agent transcripts: thinking lives inside the group of work around it, the group's label speaks for the tool calls, only finished thoughts fold into the group, and a lone thought before a reply stays a row.

I grouped at the presentation layer, not by merging messages earlier, because each thought keeps its identity there: its open/finished state, duration, disclosure key, and the live "Thinking" line all key off the thinking message. Merging thoughts into another message's blocks would need a new block type and would lose all of that. Running the grouping as one pass over the finished slot list, rather than inside the slot loop, removed three special-case rules from an earlier draft, one of which split live edit turns.

Differences from the common pattern:

  • Intended: while the turn works, the trailing run is a single live row naming the current call, rather than splitting the live run by kind of tool. Orca's run header already summarizes mixed tools and shows the latest call. Once a reply lands, the result is the same.
  • Temporary: the mobile transcript still draws each thought as its own row. It can call the same nativeChatWorkRunSpans over its list; that follow-up PR is not opened yet.

Linked Issue

N/A (maintainer change, from a live session where one turn drew 13 thought rows between 12 tool calls).

Visual Proof

First round (head 8b0e53f): the same conversation opened in both builds, a real Claude (Opus, high effort) turn that ran five commands and thought between each one. Captured on a macOS rig.

Before (main): with the turn expanded, ten alternating rows, each command and then its "Thought for Ns".

before: alternating thought and command rows

After: the same turn is one "Ran 5 commands" row.

after: one run row

After, run opened: the thoughts read in order between the commands.

after: run expanded with thoughts in order

Second round (head f42da78, macOS rig): a real Claude Opus turn that edits a file, runs commands, and launches a subagent that runs three commands, thinking between steps.

While it works: one live row for the turn's work so far ("Editing 1 file, running 1 command, and running 1 agent"), and the subagent's commands growing as one live run inside its section. No lone thought rows.

live: one run row, subagent commands as one live run

Finished turn, expanded: one run before the mid-turn reply and one after it.

finished turn expanded: run, reply, run, reply

Run opened: thoughts in order among the edit, the command and the subagent call.

run opened: thoughts among the edit, command and subagent call

Subagent section opened: its three commands are one run.

subagent section: three commands as one run

Testing

  • src/shared/native-chat-work-run.test.ts: membership and span rules.

  • native-chat-transcript-work-runs.test.ts: which rows join, runs headed by a reply, lone thoughts, turn and receipt boundaries, a live turn that edits files (one run, carrying the changed-files summary), a stopped turn ending on work, Stop in flight, height estimates, reveal lookup, diff-key re-numbering.

  • native-chat-subagent-section-work-runs.test.ts: grouping inside sections, never across agents, depths or section headings; a thought the subagent is still thinking stays its own row.

  • NativeChatTranscriptRow.work-run.test.tsx, NativeChatMessageRow.work-run.test.tsx, NativeChatMessageList.work-runs.test.tsx: no remount when a row becomes a run (a revealed diff does not scroll again), thoughts in order, a thought opened while live is still open inside the run, Stop in flight and a waiting prompt draw no lone thought row.

  • NativeChatMessageList.work-run-memo.test.tsx: streaming into the live run rebuilds only that run (fails if the row's memo check is broken).

  • native-chat-work-run-pairing.test.ts: through the real projection, each diff stays under its own call, with and without thoughts between.

  • Locally: web and node typechecks pass; oxlint, oxfmt and the changed-code quality gate are clean; 419 test files across src/renderer/src/components/native-chat/, src/shared/native-chat-* and src/shared/structured-agent-session-* pass (4,418 tests).

  • I manually tested these changes locally (macOS rig, real Claude Opus turns; screenshots above. Not tried live: a Codex or ACP turn with diffs, which is unit-tested through the real projection; a thought opened while live, unit-tested.)

  • Automated tests added/updated, or explained why not below

Notes

Presentation-only, plus one client-side projection change. Each client builds chat messages from the journal items it already receives, so no wire format, stored schema or host behavior changes, and mixed-version desktop, mobile, SSH and remote setups keep working. The worker transcript output and the stored worker archive gain a value in their existing optional callId field. Cross-platform: no platform-specific code. Performance: the grouping pass adds about 1–2 ms per streamed frame on a 10,000-message transcript and cuts the number of slots the windowed list handles; settled runs do not re-render while the live one streams.

…ne row

A model that thinks before every tool call drew a 'Thought for Ns' row between
each call, and each thought also stopped the calls from merging, so a turn read
as dozens of alternating rows. The transcript now draws an unbroken stretch of
tool calls and thoughts within a turn as one tool run; thoughts read in order
inside it when opened and are not counted in its label.
A live turn that had edited a file kept splitting its newest call or
thought off the run (the row carrying the turn's diff rollup could not
join), so a lone "Thought for Ns" row came back at the bottom.

- Run boundaries are now one pure pass in src/shared
  (nativeChatWorkRunSpans), applied over the built transcript slots.
  Section heads end runs by sitting between rows, and rows inside an
  expanded subagent section are grouped the same way.
- The row carrying the turn's diff rollup joins as the run's last
  member; the run takes the rollup from it and the bar from its head.
- A collapsed run reserves one tool row plus a lead's words, not every
  thought's text.
- Lone rows and runs draw through the same MessageRow, with one flat
  keyed line list, so a row becoming a run no longer remounts (a
  revealed diff card no longer re-fires its scroll).
- A run opens by default while the reader holds one of its thoughts
  open; the run's own choice still wins.
- A drawn thought with no visible text joins a run instead of
  splitting it.
… thoughts out of runs

- A structured journal row's call and result now share one id (the
  provider's call id, else the row's own id), so a diff or output can no
  longer pair with an earlier unanswered call in the same work run or
  folded message. A quiet command followed by edits now shows each diff
  card under its own call, and the rollup's reveal lands on it.
- A thought still being thought, while its turn or subagent works, keeps
  its own row after the run and joins once it ends.
- Removed the rule that opened a run because a thought inside it was
  open; a thought keeps its own open state inside its run.
Only a subagent section keeps a still-running thought out of its run.
At the top level the live line owns the open thought; when it lets go
(a Stop in flight, a prompt waiting on the reader) the thought now joins
the run at once instead of flashing as its own row until the turn ends.
…st after it

Settled work runs must not rebuild their lines and thoughts on every stream
frame of the live run. Renames the slot-level run test so it no longer
shares a name with the shared span test.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary (final head 393aaaf)

The problem. In the desktop native chat, a model that thinks before each tool call (Claude Opus at high effort, for example) drew a separate "Thought for Ns" row between nearly every call, and each thought also stopped the calls around it from merging. One real turn with 13 thoughts, 12 tool calls and 3 replies drew about 25 rows of work.

What changes for you. Everything the agent does between two replies is now one row whose label counts the tool calls ("Edited 1 file and ran 2 commands"). Open it to read the calls and the thoughts in order. While the turn works it stays one live row naming the current call. Subagent sections group the same way. A lone thought right before a reply still shows as its own row.

What the review loop fixed (three review rounds plus a readiness pass, each finding proven with a test against the real code):

  • Edit turns split while live (high). In a turn that had edited a file, the newest call or a lone "Thought for Ns" row kept splitting off below the run, and the run header flipped between live and done. The row carrying the turn's changed-files summary could not join a run. Fixed by moving the grouping rules into one pass over the finished row list, which also removed two other special cases and groups rows inside subagent sections. This hit Codex and ACP agents, the ones that produce a changed-files summary.
  • Diff under the wrong call (medium, Codex/ACP). A diff result with no call id paired with the oldest unanswered call in the run, so an edit's diff could show as a quiet command's output. Fixed where messages are built from the journal: a call and the result from the same journal row now share an id. This also fixes the same mix-up between adjacent calls on main.
  • Row remount (medium). When a row grew into a run it was remounted, which re-fired a diff you had jumped to and scrolled you back to it. Lone rows and runs now draw through the same component.
  • Height estimate (medium). A collapsed run's estimated height counted every hidden thought (about 1,500 px reserved for a 60 px row), so scrolling jumped. It now counts one header.
  • Smaller fixes: a whitespace-only thought no longer splits a run; a thought still being thought inside a subagent section shows as its own row until it finishes; a Stop in flight no longer flashes a lone thought row.
  • An extra rule from an earlier round, which opened a run when you had opened one of its thoughts, was removed because neither common design does it. Your open thought stays open inside the run.

Deferred (low impact, recorded):

  • A thought that finishes before the first call of a stretch shows briefly as its own row, then becomes the run. One common design does the same. It can last a few seconds before a large edit, and it remounts that row.
  • Loading older history that starts mid-run renames the run, which resets its open state. Common designs also name a group after its first loaded item.
  • An open live run re-renders all its lines each streamed frame. Collapsed and settled runs don't.
  • A Codex "Viewed image" step ends a run.
  • The mobile transcript still draws each thought as its own row. It can reuse the same shared span function; that follow-up PR is not opened yet.
  • Pre-existing, not changed here: the Claude transcript-file reader turns thinking into reply text.

What was verified.

  • Web and node typechecks; oxlint, oxfmt and the changed-code quality gate; 419 test files (4,418 tests) across the native-chat renderer and the shared native-chat and session-projection code.
  • New tests for each fix above, each checked to fail without its fix.
  • Readiness checklist: no P0, P1 or P2 issues. No wire, stored-schema or host change, and mixed-version clients are unaffected because each client builds messages from the journal itself.
  • Rendered on a macOS rig with real Claude Opus turns. Round one: before and after. Round two, on the final design: a live turn that edits a file, runs a command and launches a subagent stays one run row the whole time (sampled every 250 ms), and the subagent's commands are one run. Screenshots are in the PR body.

What was not verified.

  • A live Codex or ACP turn with diffs: the rig had no Codex login it could use without copying credentials. That path is covered by tests through the real projection.
  • A thought opened while live staying open in the real app (unit-tested only).
  • Mobile, Windows and Linux: no platform-specific code changed.
  • The subagent appears both in the run label ("ran 1 agent") and as its own "Ran 1 subagent" row. From reading the code that predates this PR, but it was not compared against a main build.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 7, 2026 10:32
@brennanb2025
brennanb2025 merged commit 520033b into main Oct 7, 2026
77 of 79 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/native-chat-work-runs branch October 7, 2026 18:06
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