Skip to content

fix(terminal): preserve large agent prompt pastes - #17718

Merged
Jinwoo-H merged 4 commits into
mainfrom
sta4577-terminal-send-truncation-fix
Aug 31, 2026
Merged

Jinwoo-H merged 4 commits into
mainfrom
sta4577-terminal-send-truncation-fix

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​80 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45 $\color{#cf222e}{\Huge{\mathbf{−}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​15

Summary

  • Preserve Claude/Codex bracketed-paste frames in one PTY write.
  • Restore timer-based yielding for generic chunked terminal input.
  • Update regression coverage for atomic agent-prompt framing and multiline input.

Root cause

Large orca terminal send --text ... --enter agent prompts were split into 16 KiB PTY writes. Claude's composer can retain only the tail when a bracketed-paste frame is split. The Aug. 26 change in #16586 (setTimeout(0) to setImmediate) made the chunks arrive as a tighter burst, increasing the failure rate. The underlying chunked-paste behavior dates to June 19, so this distinguishes the recent aggravating regression from the original boundary defect.

The fix keeps the bracketed paste start/body/end together in one PTY write, leaves Enter as a separate delayed write, and retains chunking for generic raw terminal input.

Validation

  • pnpm test src/main/runtime/orca-runtime.test.ts src/main/runtime/agent-prompt-submission-runtime.test.ts
  • 1,251 tests passed, 1 skipped.
  • Related agent-prompt suites: 69 passed.
  • pnpm tc
  • pnpm run check:code-quality:changed
  • pnpm run build:cli
  • Fresh dev Orca + real claude --model haiku --dangerously-skip-permissions:
    • 65,724-byte prompt: FIRST=BEGIN_MARKER, LAST=END_MARKER
    • 101,170-byte prompt: FIRST=BEGIN_101, LAST=END_101
    • 118,957-byte multiline prompt: FIRST=BEGIN_MULTI, LAST=END_MULTI

Claude session evidence was checked from the resulting session JSONL rather than bytesWritten.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR preserves large agent prompts by writing each bracketed-paste frame atomically, propagates PTY-provider write refusal, and retains immediate-based yielding for generic chunked input.

  • Sends the bracketed-paste body and delimiters in one PTY write, with Enter delayed separately.
  • Adds SSH transport-size rejection and propagates provider refusal through runtime routing.
  • Updates prompt framing, permission, failure, and generic-input regression coverage.

Confidence Score: 4/5

The PR is not yet safe to merge because SSH-hosted agent prompts between the 2 MiB relay-frame limit and the 16 MiB accepted input limit are rejected.

Atomic prompt framing fixes split-paste handling, but the same full payload reaches an SSH transport that refuses frames above 2 MiB, causing otherwise accepted large prompts to fail with terminal_not_writable.

Files Needing Attention: src/main/runtime/orca-runtime.ts and src/main/providers/ssh-pty-write.ts

Important Files Changed

Filename Overview
src/main/runtime/orca-runtime.ts Makes agent-prompt pastes atomic and keeps immediate-based generic chunking, but accepted prompts above the SSH frame limit now fail.
src/main/providers/ssh-pty-write.ts Rejects writes whose encoded JSON-RPC frame exceeds the 2 MiB ordinary transport limit.
src/main/ipc/pty/runtime/operations.ts Correctly propagates an explicit provider write refusal instead of unconditionally reporting success.
src/main/runtime/agent-prompt-submission-runtime.test.ts Updates cancellation, permission, and stale-handle expectations for atomic bracketed-paste writes.
src/main/runtime/orca-runtime.test.ts Covers atomic prompt framing and immediate-based generic input yielding but not the accepted 2–16 MiB SSH prompt range.

Sequence Diagram

sequenceDiagram
  participant R as Runtime
  participant C as PTY controller
  participant S as SSH PTY provider
  participant M as SSH multiplexer
  R->>C: write(full bracketed paste)
  C->>S: write(PTY ID, payload)
  S->>S: Encode pty.data frame
  alt Frame is at most 2 MiB
    S->>M: notify(pty.data)
    S-->>R: true
  else Frame exceeds 2 MiB
    S-->>R: false
    R->>R: throw terminal_not_writable
  end
Loading

Reviews (5): Last reviewed commit: "fix(pty): propagate provider write refus..." | Re-trigger Greptile

Comment thread src/main/runtime/orca-runtime.ts Resolved
@Jinwoo-H
Jinwoo-H force-pushed the sta4577-terminal-send-truncation-fix branch from 8da0524 to 83d3023 Compare August 31, 2026 19:35
@coderabbitai

coderabbitai Bot commented Aug 31, 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: Repository UI

Review profile: CHILL

Plan: Team

Run ID: fd259e57-d059-4a78-81a8-3923b6e15dd5

📥 Commits

Reviewing files that changed from the base of the PR and between 2c2b1a3a710cd52e6125b4de8d8c97844f2db8e1 and 88ada7a.

📒 Files selected for processing (4)
  • src/main/ipc/pty-controller-ownership-routing.test.ts
  • src/main/ipc/pty/runtime/operations.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
Files not reviewed due to moderation or processing errors (1)
  • src/main/runtime/orca-runtime.test.ts

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


📝 Walkthrough

Walkthrough

The runtime now writes complete agent prompt bracketed-paste frames in one PTY write. SSH PTY writes validate encoded frame size before multiplexer notification. PTY write refusals now propagate to runtime callers. Chunked terminal input yields with setImmediate between writes. Tests cover atomic writes, write failures, transport limits, permission changes, chunked input, and carriage-return handling.

Merge Risk: 🟡 Moderate · up to 88ada

The PR preserves large pasted prompts, but concurrent terminal input can still be mixed into the delayed submission to a privileged agent, and a runtime test check is failing at the current head. Merge should wait for the ordering/recovery behavior and failing check to be resolved or explicitly accepted.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, root cause, and validation, but it omits required template sections and information. It does not include an ELI5 section, a linked issue, Visual Proof or an explic… Add the missing template sections. Include a linked issue after “Fixes #”. Add Visual Proof with attachments or write “N/A” with a reason. Complete the Testing checkboxes, Review, Agent skill upstream boundary, Notes, and Checklist sections…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving large agent prompt pastes in the terminal.
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.
Full details: Description check

Explanation

The description explains the change, root cause, and validation, but it omits required template sections and information. It does not include an ELI5 section, a linked issue, Visual Proof or an explicit N/A statement, the required testing checkboxes, Review, Agent skill upstream boundary, Notes, or Checklist.

Resolution

Add the missing template sections. Include a linked issue after “Fixes #”. Add Visual Proof with attachments or write “N/A” with a reason. Complete the Testing checkboxes, Review, Agent skill upstream boundary, Notes, and Checklist sections. Add the ELI5 explanation and AI Disclosure details when applicable.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (2 skipped: 2 too large.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@pullfrog pullfrog 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.

ℹ️ One minor cleanup — dead code left behind by the atomic write. Otherwise this is a tight, well-tested fix.

Reviewed changes

A terminal prompt-submission fix that stops splitting Claude/Codex bracketed-paste frames across PTY writes, plus a revert of a recent setImmediate regression in the generic chunked-input path. Reviewed 3 files, 1 commit.

  • Atomic agent-prompt paste — writeTerminalAgentPrompt now writes the full bracketed pastePayload (start + body + end) in one synchronous PTY write instead of iterating 16 KiB chunks, dropping the per-chunk permission/generation/lease re-checks and the inter-chunk yield. Enter remains a separate delayed write, with permission/staleness still re-checked before it.
  • Timer-yield revert — yieldBetweenTerminalInputChunks switches back from setImmediate to setTimeout(0) so the generic sendTerminal chunked path yields on the timers phase and lets the PTY drain between chunks.
  • Test updates — regression coverage asserts the atomic paste (pasteWrites length 1, frame intact), the write-failure path, the stale/permission-rejection paths (frame still fully delivered, Enter withheld), and a new test that the generic chunked path uses timers rather than setImmediate.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/runtime/orca-runtime.ts Resolved

@pullfrog pullfrog 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.

ℹ️ Rebase only — no new findings.

Reviewed changes

The new commit 83d3023 is a pure rebase onto a newer main (base moved aabcc57 → 894ed75). The three file diffs are content-identical to 8da0524 (same per-file diff hashes), with only line-number drift. No behavioral changes since the prior review, so the minor dead-code suggestion from that review carries forward unchanged.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H force-pushed the sta4577-terminal-send-truncation-fix branch from 2c2b1a3 to a56006e Compare August 31, 2026 20:05

@pullfrog pullfrog 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.

Important

Oversized SSH agent prompts are now silently dropped: the new size guard returns false, but the runtime write path discards that boolean and still submits Enter, so a >2 MiB prompt over SSH vanishes with no error (see inline comment).

Reviewed changes

The new commit adds an SSH PTY write-size guard and removes the dead code flagged in the prior review.

  • Added an SSH PTY write guard — assertSshPtyWriteFitsTransport encodes the pty.data frame and rejects writes that cannot fit the 2 MiB ordinary-lane queue budget, returning false before touching the mux in both writeToSshPty and writeToSshPtyWithSettlement.
  • Removed dead code — writeTerminalAgentPrompt drops the unreachable wrotePasteBytes/completedPaste flags, the partial-paste-close catch branch, and the now-unused AGENT_PROMPT_BRACKETED_PASTE_END import.
  • Added regression tests — oversized sync and settled SSH writes are rejected before the mux is touched.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/providers/ssh-pty-write.ts Resolved
// Keep the bracketed paste frame in one PTY write; Claude's composer can drop the
// beginning when a large frame is split into independently processed chunks.
renderGate?.arm()
const wrote = this.ptyController?.write(ptyId, pastePayload) ?? false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Large SSH prompts are rejected

When an SSH-hosted agent prompt produces an encoded bracketed-paste frame larger than 2 MiB, the runtime sends the complete payload in one PTY write and the SSH provider rejects it, causing terminal_not_writable even though the shared terminal-input limit accepts prompts up to 16 MiB.

Knowledge Base Used:

@pullfrog pullfrog 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.

No new issues in this delta. The new commit is a clean simplification — it walks back the earlier setTimeout(0) revert now that agent prompts no longer route through the chunk scheduler.

Reviewed changes

One commit since the prior review (8af75b8, fix(terminal): avoid timer delay for generic sends), spanning 2 files.

  • Reverted the generic chunk yield to setImmediate — yieldBetweenTerminalInputChunks drops setTimeout(0) in favor of setImmediate, so the chunked terminal.send path stops paying a ~15 ms Windows timer tick per 16 KiB write. This is safe: agent prompts already moved to an atomic bracketed-paste write, and the generic path only carries raw text (never bracketed-paste frames), so the split-frame hazard that motivated the timer no longer applies there.
  • Updated the regression test — the chunked-input test now asserts the immediates path (expect(immediate).toHaveBeenCalled()) instead of the timer path, and still verifies byte order and the trailing \r.

The one open concern from the prior review — an oversized SSH pty.data frame being silently dropped when the new size guard returns false, because writePtyFromRuntimeController discards that boolean before it reaches writeTerminalAgentPrompt — is untouched by this commit and remains the only item blocking merge.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

One commit since the prior review (88ada7a, fix(pty): propagate provider write refusals), spanning 2 files. This closes the lone open concern from the earlier reviews.

  • Propagated provider write refusals — writePtyFromRuntimeController now returns getProviderForPty(ptyId).write(ptyId, data) !== false instead of unconditionally returning true. The SSH size guard's false therefore reaches writeTerminalAgentPrompt's wrote check, so an oversized pty.data frame is surfaced as a terminal_not_writable error with Enter withheld rather than silently dropped.
  • Added a regression test — preserves a provider write refusal for callers that gate follow-up input asserts the real controller (registerPtyHandlers → writePtyFromRuntimeController) returns false when the provider refuses, and that the provider was actually invoked.

The !== false mirrors the existing writePtyAgentSessionProofFromRuntimeController idiom and preserves the "undefined counts as success" behavior for providers that don't return a boolean.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 8bebcf5 into main Aug 31, 2026
59 of 62 checks passed
nwparker added a commit to nwparker/orca that referenced this pull request Sep 1, 2026
…-refactor

main advanced 45 commits, six of them landing inside the orca-runtime.ts this
branch splits apart. Git resolves that as a plain "take one side", and either
side silently loses work, so each was ported into the module that now owns the
code:

- stablyai#17655 bound ref and worktree scans -> runtime-repository-ref-queries
- stablyai#17448 preserve user-set workspace names -> the worktree-create modules
- stablyai#17667 cut cold worktree-switch attach latency -> the mutation lock, including
  the deletion half (worktree-terminal-mutation-wait.ts is gone)
- stablyai#17718 preserve large agent prompt pastes -> the agent-prompt write path
- stablyai#17486 unblock targeted SSH session tab refresh -> the mobile refresh modules
- stablyai#17159 close readiness gaps -> 34 runtime hunks and 5 test hunks

Every added line of the six was checked against the merged tree; the unmatched
ones are all renames or line splits, verified individually.

Two defects surfaced while porting, both predating this merge:

- isMobileSessionSurfaceMembershipAllowed read a session accessor that answers
  null where main's answers undefined, so main's `session !== undefined` guard
  was always true and the fence stopped fencing. Three clauses found in neither
  main nor the split base had been added ahead of it to compensate, and one of
  them dropped a freshly published split leaf out of syncWindowGraph. Restored
  to main's control flow with the sentinel normalized; stablyai#17159's two new tests
  cover it from both directions.
- retiredMobileSessionPtyIds was write-only state this branch invented. Its only
  reader was the clause above, and it exists in neither main nor the split base.
- RuntimeTerminalWriter.writeAgentPrompt had no callers and still carried the
  chunked-paste shape stablyai#17718 replaced.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(terminal): preserve large agent prompt pastes

* fix(terminal): guard oversized SSH PTY writes

* fix(terminal): avoid timer delay for generic sends

* fix(pty): propagate provider write refusals
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