Skip to content

fix(native-chat): stop clipping assistant text blocks at the tool-preview cap - #12159

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-3230-chat-truncation
Aug 3, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-3230-chat-truncation

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

Long assistant messages viewed over a paired connection (headless orca serve viewed from a paired desktop client or the mobile app) were cut short with a … (truncated) marker and no way to read the rest (STA-3230, GitHub #12138). The mobile payload diet in the nativeChat.readSession/nativeChat.subscribe runtime RPC applied the 4,000-char tool-preview cap to text blocks — the fully rendered message body — for any connection whose paired device token has scope mobile (which includes desktops that redeem a --serve-mobile-pairing offer, so both clients truncated identically). The reporter's "exactly 60 chars of the code block" was 4000 − prose length; the collapsed newline was the broken markdown left by a mid-code-block cut.

Fix at the source, shared by both clients: text blocks now get their own generous 64k-char safety ceiling (real replies pass through whole), while tool-result/tool-call bodies keep the 4,000-char preview diet that the cap was designed for. No renderer changes needed on desktop or mobile.

Screenshots

No visual change (transport fix; the chat views simply receive the full message text they already render).

Testing

  • pnpm lint (oxlint clean on the repo sweep)
  • pnpm typecheck
  • pnpm test (targeted: vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/native-chat.test.ts — 18/18, including 2 new regression tests)
  • pnpm build (build:electron-vite + build:cli, used for the live repro/verify rig)
  • Added or updated high-quality tests that would catch regressions: a >4k assistant text block must pass through unclipped for mobile clients, and a 70k pathological block must still clip at the ceiling.

Live end-to-end verification on an isolated orca serve rig (temp HOME + ORCA_USER_DATA_PATH; the primary daemon untouched), with a planted Claude transcript engineered so the 4,000-char boundary lands 60 chars into a trailing fenced code block, mirroring the ticket exactly:

  • Before: mobile-scope device token → text length 4,014 ending plans/lessons-cont\n… (truncated); runtime-scope token → full 4,149 chars. Reproduced identically through a real paired desktop instance (addFromPairingCode → runtimeEnvironments.call, the same bridge the chat view's transport uses).
  • After: same mobile-scope token and same paired desktop both receive the full 4,149-char message with the closing fence intact and no marker.

AI Review Report

Reviewed the change for: regression risk to the mobile payload diet (tool-result/tool-call clipping is byte-for-byte unchanged, verified by the existing 16 tests), wire-size risk from unclipped text (bounded by the new 64k ceiling, the 40-message window, and the upstream 2MB transcript-record cap), and parity with the desktop IPC path (which has never clipped). Confirmed both the read and subscribe paths flow through the same clipBlock, so snapshots, replacements, and appends all benefit. Cross-platform: the change is pure main-process string handling with no shortcuts, labels, paths, shell, or Electron platform APIs; it is identical on macOS, Linux, and Windows hosts and for SSH/WSL-backed runtimes, and applies equally to folder workspaces and git worktrees.

Security Audit

No new input surfaces: the RPC schema is unchanged, and the modified code only alters the char budget applied to already-parsed transcript strings before serialization. No command execution, path handling, auth, secrets, or dependency changes. The clip remains a bound (now 64k for text), so a hostile transcript still cannot ship unbounded payloads to paired clients; tool-input sanitization (depth/node/key budgets) is untouched. IPC/RPC gating by clientKind is unchanged.

Notes

  • The 60-char figure in the ticket was a red herring — it is the remainder of the reporter's ~3,940-char prose against the 4,000-char cap.
  • Related follow-up (not in scope): a desktop client that redeems a mobile-scope pairing offer is treated as a mobile client for every payload-diet decision, not just this one. If we want full-fidelity desktop behavior over mobile-scoped pairings, scope negotiation deserves its own ticket.

Fixes STA-3230 (https://linear.app/stably/issue/STA-3230). Closes #12138.

…view cap

Long assistant messages read over a paired connection (headless orca
serve viewed from desktop or mobile) were cut at 4,000 chars with a
'… (truncated)' marker and no way to read the rest. The mobile payload
diet in nativeChat RPC applied the tool-preview char cap to text blocks,
which are the fully rendered message body. Give text blocks their own
64k safety ceiling so real replies pass through whole while pathological
multi-hundred-KB blocks still can't freeze the phone.

Fixes STA-3230
@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

Fixes a regression where long assistant text blocks sent over a paired mobile (or mobile-scoped desktop) connection were cut at the 4,000-char tool-preview cap — the same budget designed for tool-result/tool-call payloads — leaving replies truncated mid-sentence with no way to read the rest.

  • Core fix: clipBlock now applies a distinct 64k ceiling (MOBILE_TEXT_BLOCK_CHAR_CAP) to text blocks instead of the shared MOBILE_BLOCK_CHAR_CAP (4k). The clip() helper gains a cap parameter so every call site is explicit about which budget applies. Tool-result and tool-call clipping is byte-for-byte unchanged.
  • Coverage: two new readSession regression tests (6k prose passes through; 70k is clipped at 64k) plus one subscribe test that exercises all three frame types (snapshot, replacement, appended) with a mobile context. The existing tool-result/tool-call assertions are tightened to exact toBe expectations.

Confidence Score: 5/5

Safe to merge — the change is a two-constant, two-call-site string-budget adjustment with no new I/O, no schema changes, and full test coverage for all affected paths.

The diff is minimal and surgically precise: clip() gains a parameter, clipBlock switches text blocks to the new 64k constant, and every other block type keeps its existing budget unchanged. Both the read and subscribe code paths route through the same clipBlock, so the fix is applied consistently. No auth, path, network, or dependency changes are involved.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/runtime/rpc/methods/native-chat.ts Introduces a separate 64k cap (MOBILE_TEXT_BLOCK_CHAR_CAP) for text blocks while keeping the 4k cap for tool-result/tool-call previews; adds a cap parameter to clip() so all callers are explicit about which budget to use.
src/main/runtime/rpc/methods/native-chat.test.ts Adds two readSession regression tests and one subscribe test verifying all three frame types carry unclipped text for mobile clients. Existing clipping assertions are tightened with exact toBe expectations.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[RPC call] --> B{clientKind?}
    B -- runtime/undefined --> C[no char clipping]
    B -- mobile --> D[sanitizeMessage via clipBlock]
    D --> F{block.type?}
    F -- text --> G{length > 64k?}
    G -- No --> H[pass through unchanged]
    G -- Yes --> I[clip to 64k + marker]
    F -- tool-result --> J{length > 4k?}
    J -- No --> K[pass through unchanged]
    J -- Yes --> L[clip to 4k + marker]
    F -- tool-call --> M[sanitizeToolInput 4k budget]
Loading

Reviews (2): Last reviewed commit: "test(native-chat): cover long text strea..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86950825-f68f-42c1-97df-67c1692663a7

📥 Commits

Reviewing files that changed from the base of the PR and between acd1843 and 8487798.

📒 Files selected for processing (1)
  • src/main/runtime/rpc/methods/native-chat.test.ts
📝 Walkthrough

Walkthrough

Mobile chat block clipping now uses separate limits for text and tool-result blocks. Text blocks allow up to 64,000 characters. Tool-result blocks remain limited to 4,000 characters. Tests cover unchanged long text below the limit and truncation of oversized text with a marker.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: separating assistant text clipping from the tool-preview cap.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and notes with specific verification details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/native-chat.test.ts (1)

170-182: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the exact 64,000-character contract.

The current assertions pass for any smaller cap. Assert the exact preserved prefix and truncation marker so a regression to 4,000 or another value fails.

Suggested assertion
-    expect(block.text.length).toBeLessThan(text.length)
-    expect(block.text).toContain('truncated')
+    expect(block.text).toBe(`${text.slice(0, 64_000)}\n… (truncated)`)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a01f77ec-02fd-4444-89d3-564bf8f10cf0

📥 Commits

Reviewing files that changed from the base of the PR and between 8c5371e and acd1843.

📒 Files selected for processing (2)
  • src/main/runtime/rpc/methods/native-chat.test.ts
  • src/main/runtime/rpc/methods/native-chat.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA (isolated paired-desktop instance) passed for STA-3230.

  • A 7,466-character assistant text block crossed the former 4,000-character tool-preview boundary.
  • The remote Native Chat UI rendered the complete response, including the closing code fence and sentinel, with no truncation marker.

Start of the long response:

STA-3230 long assistant response

Completion sentinel preserved:

STA-3230 completion sentinel

@brennanb2025
brennanb2025 merged commit 922268a into main Aug 3, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…view cap (stablyai#12159)

* fix(native-chat): stop clipping assistant text blocks at the tool-preview cap

Long assistant messages read over a paired connection (headless orca
serve viewed from desktop or mobile) were cut at 4,000 chars with a
'… (truncated)' marker and no way to read the rest. The mobile payload
diet in nativeChat RPC applied the tool-preview char cap to text blocks,
which are the fully rendered message body. Give text blocks their own
64k safety ceiling so real replies pass through whole while pathological
multi-hundred-KB blocks still can't freeze the phone.

Fixes STA-3230

* test(native-chat): cover long text stream frames
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]: Mobile Chat UI truncates assistant messages at exactly 4,000 characters with no expand control (desktop unaffected)

1 participant