Skip to content

fix(chat): preserve indentation and trailing newlines in structured transcript content - #50670

Merged
nwparker merged 1 commit into
mainfrom
bugbash/pr-50565
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/pr-50565

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Agents sometimes send a chat message or tool output as a structured list rather than one plain string. When they did, Orca cut all the spaces off the start and end. Indented code lost the indent on its first line, and file-read output lost its padding and its final newline. Orca now keeps that spacing, so structured messages look the same as plain ones.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

What Changed

Before: in Chat view, Claude, Grok and OMP transcript rows built from structured blocks ({type:'text'}, thinking, and tool_result arrays or objects) went through extractString, which trims. A Read result like " 1\t..." lost its first-line padding, and an indented code reply lost its first indent. Plain-string content already kept its whitespace.

After:

  • src/main/native-chat/transcript-decoding/transcript-record-blocks.ts
    • Tool output parts use contentString. It still drops blank parts but keeps everything else as-is. Array parts are joined with \n only when the previous part does not already end in one, so a part's own final newline no longer turns into a blank line.
    • Text and thinking blocks use blockText. It drops whitespace-only blocks and leading blank lines, keeps the first content line's indentation, and trims the end. Blocks are joined with \n\n and Copy does not trim, so keeping the edge blank lines would add stray blank lines to copied replies.
    • Ids and names still go through the trimming extractString.
  • src/shared/native-chat/tools/native-chat-tool-line-view.ts: the preview for a result with no matching call now uses the first non-blank line. Outputs that start with blank lines no longer show an empty preview. That also fixes plain-string outputs that already started with a newline on main.

Why

The string path already sent raw text to the same renderers, so the structured path should do the same. Tool output needs exact whitespace because people copy it. Prose blocks only need their first-line indent. Keeping their edge blank lines would change Copy output and the matching of pending sends.

Linked Issue

Fixes #50564

Original fix by @Afloat16 in #50565

Visual Proof

N/A. There are no screenshots because this is a decoder change in the main process. The visible effect is the first-line indent and tool-output padding in chat rows, and that is pinned by decoder-level probes instead. With main's versions of the two source files restored, 7 of the 10 probe cases fail: text indent, thinking indent, CRLF leading blank lines, tool_result array and object whitespace, the new decoder test, and the preview test. The 3 guard cases (blank suppression, part joining, id trimming) pass on both. On this branch all 10 pass.

Testing

  • Reproduced on main by running the new tests against main's source. transcript-record-blocks.test.ts gets "text": "indented()" and "output": "1\tx". native-chat-tool-line-view.test.ts gets an empty preview.

  • Scanned about 300 local Claude JSONL files. 584 of 5540 text blocks have trailing whitespace and 14 of 2732 tool_result array parts have leading whitespace, so the trimming does happen on real data.

  • Ran targeted vitest under src/main/native-chat/transcript-decoding and src/shared/native-chat/tools, which passes. An earlier wider run over src/main/native-chat, src/shared/native-chat and src/renderer/src/components/native-chat passed 656 tests with 2 skipped.

  • oxlint, oxfmt, anti-slop oxlint, code-quality oxlint, ast-grep and the changed-code quality gate are clean on the touched files.

  • Platform: macOS (unit level). The change is pure string handling with no platform-specific paths.

  • I manually tested these changes locally

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

  • Every added test fails without this change and avoids the test anti-patterns

Performance

This runs in the main process, once per decoded transcript line when a chat transcript is read or tailed. There is no new I/O, polling or subprocess work. Node benchmarks, best of 5, old / new:

  • Text block, short reply: 8.1ns / 7.1ns. With a leading indent or blank lines: about 10ns more per block, which is small next to the line's JSON.parse.
  • Text block, 1MB of leading newlines: 1.20ms / 0.56ms. 1MB whitespace-only: 0.42ms / 0.41ms.
  • Tool part join, 10 x 2KB parts: 1.70us / 1.06us. 1000 x 1KB parts: 0.15ms / 0.10ms. The join is linear. A first reduce variant was quadratic, at 49ms for 1000 parts, and was rejected.
  • Preview, short: 21ns / 25ns. 1MB of leading newlines: 9.5ms / 0.60ms. 1MB whitespace-only: 0.017ms / 0.27ms.

No case gets near 16ms.

Risk

Level: Low

Only chat transcript rendering and Copy are affected. A structured text block whose first line has 4 or more leading spaces now renders as a Markdown code block, the same as the plain-string path already did. Tool output keeps its edge whitespace. Pending-send matching, harness-injected detection and command-output regexes all tolerate edge whitespace already. Nothing is persisted and there is no IPC or remote format change, so a plain revert backs this out.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…ranscript content

Structured Claude/Grok/OMP transcript content (text, thinking and
tool_result parts given as arrays or objects) went through the trimming
extractString, so indented code lost its first-line indent and tool
output lost its leading padding and final newline. Plain-string content
was already kept raw.

- Tool output parts keep their whitespace; blank parts are still dropped,
  and a part that already ends in a newline is not given another.
- Text and thinking blocks keep the first content line's indentation but
  drop leading blank lines and trailing whitespace, so copied replies do
  not pick up extra blank lines.
- Lone tool-result previews use the first non-blank line.

Fixes #50564

Co-authored-by: Afloat <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Structured transcript decoding now preserves whitespace in nonblank text, thinking, and tool-result content while suppressing whitespace-only text. Tool result previews now skip leading whitespace when selecting their first line.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 58da3

This change preserves meaningful whitespace in structured transcript text and tool output, and tool result previews now skip leading blank lines. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: preserving indentation and trailing newlines in structured transcript content. The changeset stops trimming structured text, thinking, and tool-result blocks in the tr…
Description check Passed The description follows the repository template and covers the required sections. It has a clear ELI5, a before/after mechanism description, a rationale with the alternatives considered, a linked issu…
Linked Issues check Passed Direct issue #50564 requires that structured text, thinking, and tool-output content keep its meaningful whitespace, matching string-shaped content. Keep identifier normalization and whitespace-only s…
Out of Scope Changes check Passed All changes connect to the linked issue's whitespace-preservation objective.
- transcript-record-blocks.ts and its test: direct implementation of the structured-content whitespace behavior.
- native-c…
Full details: Title check

Explanation

The title names the main change: preserving indentation and trailing newlines in structured transcript content. The changeset stops trimming structured text, thinking, and tool-result blocks in the transcript decoder, and it changes the tool-line preview. The title matches the core change and is specific. The 86-character length is long but acceptable.

Full details: Description check

Explanation

The description follows the repository template and covers the required sections. It has a clear ELI5, a before/after mechanism description, a rationale with the alternatives considered, a linked issue (Fixes #50564), a justified N/A for visual proof, detailed testing evidence, a performance section with benchmarks, and a risk level with rollback guidance. The AI Disclosure section is left as template text, which is acceptable for an internal contributor. The Visual Proof N/A is justified because the change is a main-process decoder change.

Full details: Linked Issues check

Explanation

Direct issue #50564 requires that structured text, thinking, and tool-output content keep its meaningful whitespace, matching string-shaped content. Keep identifier normalization and whitespace-only suppression.

Evidence at head (diff of transcript-record-blocks.ts against merge base):

  • Tool output: toolResultOutput now uses contentString, which drops only blank parts and keeps leading spaces and final newlines. Array parts are joined with \n only when the previous part does not end in \n. This addresses the reported loss of leading spaces and final LF.
  • Text and thinking blocks: blockText keeps the first content line's indentation, which addresses the reported object-text unindent. It drops whitespace-only blocks and trims the end.
  • Ids and names still use extractString. Whitespace-only blocks and parts are still suppressed.
  • The PR reports new decoder tests for these cases. Its probe results show 7 of 10 cases fail on main's sources and all pass on head.

Remaining divergence: text and thinking blocks still drop leading blank lines and trailing whitespace, while the plain-string path keeps them. The issue does not require this case for prose. The PR explains the choice: edge blank lines would change Copy output. This is a deliberate, documented choice and does not contradict the issue's observed regressions.

The issue's non-coding statements about Linux testing and platform scope are not assessed.

Full details: Out of Scope Changes check

Explanation

All changes connect to the linked issue's whitespace-preservation objective.

  • transcript-record-blocks.ts and its test: direct implementation of the structured-content whitespace behavior.
  • native-chat-tool-line-view.ts and its test: the preview uses the first non-blank line. Once tool output keeps leading blank lines, an unmatched tool result would otherwise show an empty preview. The change is a necessary follow-on to the preserved output, and it also covers plain-string outputs that begin with a newline. This is a small, closely related change.

No unrelated files or behavior changes appear in the summary. Related issues #46311 and #31554 are context only and have no implementation in this diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1459a354-f018-4546-b2a7-983443e2b231
Commits

Reviewing files that changed from the base of the PR and between 8e6a9c0 and 58da397.

Files selected for processing: 4

  • src/main/native-chat/transcript-decoding/transcript-record-blocks.test.ts
  • src/main/native-chat/transcript-decoding/transcript-record-blocks.ts
  • src/shared/native-chat/tools/native-chat-tool-line-view.test.ts
  • src/shared/native-chat/tools/native-chat-tool-line-view.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit 767b930 into main Nov 27, 2026
56 checks passed
@nwparker
nwparker deleted the bugbash/pr-50565 branch November 27, 2026 08:41
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.

[Bug]: Structured transcript text loses indentation and final newlines

1 participant