Repository navigation
fix(terminal): preserve large agent prompt pastes - #17718
Conversation
Greptile SummaryThe 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.
Confidence Score: 4/5The 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
|
| 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
Reviews (5): Last reviewed commit: "fix(pty): propagate provider write refus..." | Re-trigger Greptile
8da0524 to
83d3023
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 2c2b1a3a710cd52e6125b4de8d8c97844f2db8e1 and 88ada7a. 📒 Files selected for processing (4)
Files not reviewed due to moderation or processing errors (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe 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 Merge Risk: 🟡 Moderate · up to 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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 CoverageExplanation 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.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
ℹ️ 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 —
writeTerminalAgentPromptnow writes the full bracketedpastePayload(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 —
yieldBetweenTerminalInputChunksswitches back fromsetImmediatetosetTimeout(0)so the genericsendTerminalchunked path yields on the timers phase and lets the PTY drain between chunks. - Test updates — regression coverage asserts the atomic paste (
pasteWriteslength 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 thansetImmediate.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
2c2b1a3 to
a56006e
Compare
There was a problem hiding this comment.
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 —
assertSshPtyWriteFitsTransportencodes thepty.dataframe and rejects writes that cannot fit the 2 MiB ordinary-lane queue budget, returningfalsebefore touching the mux in bothwriteToSshPtyandwriteToSshPtyWithSettlement. - Removed dead code —
writeTerminalAgentPromptdrops the unreachablewrotePasteBytes/completedPasteflags, the partial-paste-close catch branch, and the now-unusedAGENT_PROMPT_BRACKETED_PASTE_ENDimport. - Added regression tests — oversized sync and settled SSH writes are rejected before the mux is touched.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| // 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 |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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—yieldBetweenTerminalInputChunksdropssetTimeout(0)in favor ofsetImmediate, so the chunkedterminal.sendpath 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ 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 —
writePtyFromRuntimeControllernow returnsgetProviderForPty(ptyId).write(ptyId, data) !== falseinstead of unconditionally returningtrue. The SSH size guard'sfalsetherefore reacheswriteTerminalAgentPrompt'swrotecheck, so an oversizedpty.dataframe is surfaced as aterminal_not_writableerror with Enter withheld rather than silently dropped. - Added a regression test —
preserves a provider write refusal for callers that gate follow-up inputasserts the real controller (registerPtyHandlers→writePtyFromRuntimeController) returnsfalsewhen 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…-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.
* 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

Summary
Root cause
Large
orca terminal send --text ... --enteragent 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)tosetImmediate) 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.tspnpm tcpnpm run check:code-quality:changedpnpm run build:cliclaude --model haiku --dangerously-skip-permissions:FIRST=BEGIN_MARKER,LAST=END_MARKERFIRST=BEGIN_101,LAST=END_101FIRST=BEGIN_MULTI,LAST=END_MULTIClaude session evidence was checked from the resulting session JSONL rather than
bytesWritten.