Repository navigation
fix(terminal): bracket agent-pane pastes so a pasted newline can't submit the draft - #14456
Conversation
…bmit A paste of <=64KB is handed to xterm's term.paste(), which rewrites newlines to CR and wraps in ESC[200~/ESC[201~ only when its parser observed DECSET 2004. Windows ConPTY never forwards that mode, so an unbracketed pasted newline reaches a TUI agent as Enter and submits the draft parked in its composer. The existing force-bracket guard keyed on isWindowsUserAgent() - the client's platform - but the ConPTY can be on a remote host, so the guard was off in exactly the configuration that needs it. Gate on the pane's own TUI agent instead, applied to all four paste entry points; middle-click primary selection had no force flag at all. The agent status row is retained deliberately and is not lifecycle-driven, so it can outlive the agent. Veto on shell-confirmed foreground (OSC 133;D) and on a row rehydrated across an app restart. The freshness TTL and a state check are both unusable here - an idle-but-live agent sits at done and still needs bracketing. Refs STA-4294
…Foreground Measured against a real pane: shellForeground is republished only at OSC 133 boundaries, so a shell without 133 integration leaves it latched true while an agent owns the foreground. Vetoing on it silently reinstated the submit bug the parent commit fixes - the parked draft was sent on paste with the gate in place. Prefer process-confirmed agent identity when present, keep the restart-rehydrated veto, and drop the shellForeground veto. Erring toward bracketing costs a literal ESC[200~ in a non-2004 program; erring the other way sends the user's draft. Refs STA-4294
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughTerminal paste protection now resolves per pane from platform, pane identity, agent status, and foreground-agent state. Windows input-record pastes support Merge Risk: 🔵 Low · up to The paste behavior is narrowly improved for agent panes with broad automated coverage, but merge should retain owner awareness that Windows validation does not exercise a real OpenConsole/ConPTY path and that a lengthy explanatory source comment may require maintenance follow-up. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
…e mode bit Measured in real ptys before taking the obvious alternative. A tri-state on DECSET 2004 (observed-on / observed-off / never-observed) does not work: zsh 5.9, fish 4.8.1 and bash >= 5.1 announce and withdraw the mode cleanly, but macOS /bin/bash 3.2, /bin/sh, bash 4.4 and any shell with bracketed paste disabled emit nothing at all, byte-identical to a bare `cat`. Silence cannot be read as consent. Agent identity disambiguates it in the one direction that matters: agents always enable the mode, so silence on an agent pane means the announcement was lost in transit, never an opt-out. Also measured: bracketing a program that never negotiated is worse than useless - the markers land as literal payload bytes and ICRNL still turns the CR into a submit - so the gate stays narrow. Refs STA-4294
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.ts (1)
12-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten this documentation comment.
Keep the decision rationale near the helper. Remove the detailed shell-version and protocol evidence from this source comment. This evidence will become stale and makes the decision logic harder to scan.
As per coding guidelines, comments must be “concise, non-obvious, and brief” and should prefer one line.
Proposed reduction
- * Why keyed on the pane's agent and not on the mode bit itself: "we never observed - * DECSET 2004" is not usable evidence. Measured in real ptys — zsh 5.9, fish 4.8.1 and - * bash >= 5.1 emit `?2004h` at the prompt and `?2004l` just before exec, but macOS - * /bin/bash 3.2, /bin/sh, bash 4.4, and any shell with bracketed paste turned off in - * .inputrc/zle emit *nothing at all*. A deliberate opt-out is byte-identical to a bare - * `cat`. So silence cannot be read as "nobody has an opinion". - * - * Agent identity is the only signal that disambiguates it: a TUI agent always enables - * bracketed paste, so on an agent pane silence can only mean the announcement was lost - * in transit (ConPTY, replay) — never an opt-out. Keep this narrow for that reason. - * Bracketing a program that never negotiated is measurably worse than useless: the - * markers arrive as literal payload bytes and ICRNL still turns the CR into a submit. + * DECSET 2004 silence cannot distinguish an opt-out from a lost announcement. + * Force bracketing only for known TUI agent panes.Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 83c6bf69-7a14-44fc-93b6-314abd85dd47
📒 Files selected for processing (1)
src/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.ts
Readiness review follow-ups, none behaviour-changing for reachable inputs. makePaneKey throws on a malformed leaf/tab id. It is unreachable today (pane.leafId is a minted UUID and the same pair is already called unguarded from a hotter site), but the failure mode was bad: the throw escapes before the paste helper's catch is attached, so the paste would be a silent no-op with no error surface. Degrade to the pre-fix path instead, with a test. Also record two things a future reader needs: the process-confirmed branch is dead for remote-runtime and SSH panes because foreground tracking is disabled there, so a remote pane's status row is its only evidence; and why this resolver deliberately omits the shellForeground/routingRevoked/routingTrusted gates its two siblings enforce - they route input bytes, this only wraps a paste whose payload is ESC-sanitized downstream. Refs STA-4294
Independent validation at exact HEAD 7a9270d (validation only — no changes made)Launched this worktree's dev build (isolated user data, CDP port 9555) and verified Method: real Orca terminal (node-pty), real system clipboard, real ⌘V key path. A deterministic bracketed-paste-aware stand-in TUI (agent-composer semantics, never emits DECSET 2004 — the ConPTY condition) ran in the pane; Protected agent-pane case — draft preserved, Narrow non-agent control (same TUI, no agent row) — pre-fix behavior unchanged: Findings: the fix works as claimed at this HEAD — the agent-pane paste is bracketed and cannot submit the parked draft, while non-agent panes keep the unbracketed direct path. No regressions observed in renderer console or app logs; the worktree's git state was untouched. Cleanup: dev instance, temp profile, stand-in process, and scripts removed. |
|
Windows validation at 7a9270d on Windows 10 Pro 10.0.26200 (real OpenConsole.exe ConPTY + Codex 0.145.0): ❌ a leading-newline paste still submitted the parked draft. I parked PARKED_DRAFT_SHIFT_PR14456, verified the system clipboard began with LF and retained the complete 78-character payload, then used the real Ctrl+Shift+V shortcut; Orca prevented the key event, but agent state changed to working with that draft and the rendered TUI showed its submission error while all payload lines remained in the new composer. Ctrl+V and a direct bracket frame reproduced the failure; the new unit file passes 12/12 and the renderer console recorded 0 errors.
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6807172e-e543-43ce-ad96-f3b6bf8d25ba
📒 Files selected for processing (14)
src/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.test.tssrc/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.tssrc/renderer/src/components/terminal-pane/terminal-bracketed-paste.test.tssrc/renderer/src/components/terminal-pane/terminal-bracketed-paste.tssrc/renderer/src/components/terminal-pane/terminal-clipboard-paste.test.tssrc/renderer/src/components/terminal-pane/terminal-clipboard-paste.tssrc/renderer/src/components/terminal-pane/terminal-paste-chunks.tssrc/renderer/src/components/terminal-pane/terminal-paste-coordinator.test.tssrc/renderer/src/components/terminal-pane/terminal-paste-coordinator.tssrc/renderer/src/components/terminal-pane/terminal-paste-executor.tssrc/renderer/src/components/terminal-pane/terminal-paste-model.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.tssrc/shared/tui-agent-config.ts
| platform: 'win32', | ||
| ptyId: 'remote:host-abc/pty-1', | ||
| isWindowsConpty: false | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| it('encodes the leading newline as modified Enter instead of submit', async () => { | ||
| const terminal = { | ||
| modes: { bracketedPasteMode: false }, | ||
| options: { ignoreBracketedPasteMode: false }, | ||
| input: vi.fn(), | ||
| paste: vi.fn() | ||
| } | ||
| const plan = planTerminalPaste({ | ||
| text: PASTED, | ||
| source: 'keyboard', | ||
| target: remoteWindowsTarget(), | ||
| terminalBracketedPasteMode: false, | ||
| ...decide({ hostPlatform: 'win32' }) | ||
| }) | ||
| await executeTerminalPastePlan(plan, { | ||
| pasteText: (text, options) => pasteTerminalText(terminal, text, options) | ||
| }) | ||
|
|
||
| expect(plan.payload.lineCount).toBe(2) | ||
| expect(plan.mode).toBe('windows-input-record') | ||
| expect(plan.bracketed).toBe(false) | ||
| expect(terminal.input).toHaveBeenCalledWith(`\x1b\r${PASTED.slice(1)}`) | ||
| expect(terminal.paste).not.toHaveBeenCalled() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Cover and fix the Windows 10 OpenConsole ConPTY path before merge. This execution test disables the ConPTY condition, so it does not exercise the reported failure mode. Supplied validation indicates that a leading-newline paste can still submit a parked draft on Ctrl+V, Ctrl+Shift+V, and direct bracket-frame input. Add regressions for all affected paths with the ConPTY behavior enabled, then fix the paste path until the draft remains unsent.
📍 Affects 2 files
src/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.test.ts#L174-L203(this comment)src/renderer/src/components/terminal-pane/terminal-bracketed-paste.ts#L137-L142
|
Fixed-HEAD Windows Low Spec rerun at |
…bmit the draft (stablyai#14456) * fix(terminal): bracket agent-pane pastes so a pasted newline can't submit A paste of <=64KB is handed to xterm's term.paste(), which rewrites newlines to CR and wraps in ESC[200~/ESC[201~ only when its parser observed DECSET 2004. Windows ConPTY never forwards that mode, so an unbracketed pasted newline reaches a TUI agent as Enter and submits the draft parked in its composer. The existing force-bracket guard keyed on isWindowsUserAgent() - the client's platform - but the ConPTY can be on a remote host, so the guard was off in exactly the configuration that needs it. Gate on the pane's own TUI agent instead, applied to all four paste entry points; middle-click primary selection had no force flag at all. The agent status row is retained deliberately and is not lifecycle-driven, so it can outlive the agent. Veto on shell-confirmed foreground (OSC 133;D) and on a row rehydrated across an app restart. The freshness TTL and a state check are both unusable here - an idle-but-live agent sits at done and still needs bracketing. Refs STA-4294 * fix(terminal): key agent-paste bracketing on live evidence, not shellForeground Measured against a real pane: shellForeground is republished only at OSC 133 boundaries, so a shell without 133 integration leaves it latched true while an agent owns the foreground. Vetoing on it silently reinstated the submit bug the parent commit fixes - the parked draft was sent on paste with the gate in place. Prefer process-confirmed agent identity when present, keep the restart-rehydrated veto, and drop the shellForeground veto. Erring toward bracketing costs a literal ESC[200~ in a non-2004 program; erring the other way sends the user's draft. Refs STA-4294 * docs(terminal): record why paste bracketing keys on the agent, not the mode bit Measured in real ptys before taking the obvious alternative. A tri-state on DECSET 2004 (observed-on / observed-off / never-observed) does not work: zsh 5.9, fish 4.8.1 and bash >= 5.1 announce and withdraw the mode cleanly, but macOS /bin/bash 3.2, /bin/sh, bash 4.4 and any shell with bracketed paste disabled emit nothing at all, byte-identical to a bare `cat`. Silence cannot be read as consent. Agent identity disambiguates it in the one direction that matters: agents always enable the mode, so silence on an agent pane means the announcement was lost in transit, never an opt-out. Also measured: bracketing a program that never negotiated is worse than useless - the markers land as literal payload bytes and ICRNL still turns the CR into a submit - so the gate stays narrow. Refs STA-4294 * fix(terminal): guard the paste pane key and document the evidence policy Readiness review follow-ups, none behaviour-changing for reachable inputs. makePaneKey throws on a malformed leaf/tab id. It is unreachable today (pane.leafId is a minted UUID and the same pair is already called unguarded from a hotter site), but the failure mode was bad: the throw escapes before the paste helper's catch is attached, so the paste would be a silent no-op with no error surface. Degrade to the pre-fix path instead, with a test. Also record two things a future reader needs: the process-confirmed branch is dead for remote-runtime and SSH panes because foreground tracking is disabled there, so a remote pane's status row is its only evidence; and why this resolver deliberately omits the shellForeground/routingRevoked/routingTrusted gates its two siblings enforce - they route input bytes, this only wraps a paste whose payload is ESC-sanitized downstream. Refs STA-4294 * fix(terminal): encode Windows agent paste newlines as input records * fix protected paste handling in dashboard previews
…s one draft (#33339) Windows + Codex: Ctrl+V, Shift+Insert and Edit > Paste send multi-line pastes with Alt+Enter newlines like right-click already does (restoring #14456 wiring lost in a refactor), so pasted lines no longer submit one by one when Codex's paste-burst heuristic doesn't catch them (e.g. disable_paste_burst = true). macOS/Linux clients unchanged. Fixes #30470. Supersedes #30550. Co-authored-by: STiFLeR7 <[email protected]>




ELI5
Pasting text is not the same as pressing Enter. But if you had a half-written message sitting in an agent's input box and pasted something that started with a newline, that newline was delivered as an Enter keypress — so your unfinished message got sent. This makes pastes into agent panes always safe.
What Changed
A paste of ≤64 KB is handed to xterm's
term.paste(), which rewrites\r?\nto\rand wraps the payload inESC[200~/ESC[201~only if its parser has observed DECSET 2004. Unwrapped, a pasted newline arrives at the agent as a bare CR — Enter.Orca already had a force-bracket guard for this, but it keyed on the wrong machine:
isWindowsUserAgent()readsnavigator.userAgent— the client's platform. The ConPTY is on the host. So the guard was off in exactly the configuration that needs it (macOS/Linux client → Windows host) and on unnecessarily for a Windows client → Linux host.This PR gates the force-bracket on what is running in the pane instead, via a new pure module
terminal-agent-paste-bracketing.ts. Wired into all four paste entry points, which all shared the defect:TerminalPane.tsxTerminalPane.tsxuse-terminal-pane-context-menu.tsTerminalPane.tsx— had no force flag at allEvidence order: a process-confirmed agent wins; otherwise the pane's agent row, minus rows rehydrated from disk across a restart.
Why
Bracketing must key off what the pane is running, not what laptop the user is sitting at. A TUI agent composer is the one context where a pasted newline is unambiguously content rather than submit.
The second commit exists because live testing falsified the first. The initial gate also vetoed on
shellForeground, which looked like sound process-grade evidence. It isn't: that flag is republished only at OSC 133 boundaries, so a shell without 133 integration leaves it latchedtruewhile an agent owns the foreground. With that veto in place the bug still reproduced — the parked draft was sent. It is now dropped, with a test pinning the behavior.Deliberately not used as gates: the 30-minute freshness TTL, and
state !== 'done'. An idle-but-live agent sits atdonewith an oldupdatedAt; both would strip bracketing from exactly the pane that needs it most.Note the fix only adds behavior when the mode bit is false — when a program has genuinely enabled DECSET 2004, xterm brackets anyway and this gate is inert, so it cannot override an agent that turned the mode off.
Design rationale (measured, not assumed)
The obvious alternative is to key this on the mode bit itself — a tri-state of observed-on / observed-off / never-observed, bracketing only when nothing was ever announced. I built the case for it and then measured it in real ptys before writing any code. It does not work.
?2004h/?2004llemitted ~1ms before exec/bin/bash3.2,/bin/sh, bash 4.4enable-bracketed-paste offunset zle_bracketed_pastecatas the pty commandThe last three are byte-identical in 2004 terms: a deliberate opt-out is indistinguishable from a program with no opinion. And macOS's default
/bin/bashand/bin/share in the silent bucket, so the heuristic would misfire on the system shells.Bracketing on silence is also worse than useless. Feeding
\e[200~foo\rbar\e[201~to a barecatin a pty, capturing what the program actually received:The markers arrive as literal payload bytes (rendered
^[[200~foo), and ICRNL still turned the CR into a newline, sofoosubmitted anyway — 12 bytes of corruption, zero protection.That is why this keys on the pane's agent. Agent identity disambiguates silence in the one direction that matters: a TUI agent always enables bracketed paste, so on an agent pane silence can only mean the announcement was lost in transit (ConPTY, replay) — never an opt-out. On any other pane silence stays ambiguous and nothing is forced.
Residual risk, stated precisely: a stale agent row on a pane that has dropped to one of the silent shells (macOS
/bin/bash,/bin/sh) would force brackets and emit^[[200~garbage. On zsh/fish/bash 5.2 the shell announcesh, the mode bit is true, xterm brackets natively, and this gate is inert — no garbage possible.Is this the standard remediation?
Checked, because the obvious objection is "shouldn't the host fix this?" One reference notes "Conpty v1.22+ uses passthrough", which would mean modern ConPTY forwards child escape sequences and none of this is needed.
It doesn't, and the proof is in this repo: Orca already ships
conpty.dll 1.23.251008001— the passthrough generation — on every local Windows spawn (pty-subprocess.ts:570,local-pty-utils.ts:206,windows-conpty-warmup.ts:28), and the pre-existing local Windows force-bracketing is still there and still needed. If passthrough forwarded DECSET 2004, that code would already be dead.Supporting:
PSEUDOCONSOLE_PASSTHROUGH_MODE (8u)is declared in node-pty but never passed and unreachable from JS; no reference project sets any ConPTY flag beyondINHERIT_CURSOR; no codebase examined states that child-emitted DEC private modes survive ConPTY. Passthrough is documented as affecting reprint frequency, DA1 queries, and image protocols — never mode announcements.Client-side compensation is therefore the standard fix. The closest peer does the same with a blunter rule (
platform.isMacintosh || isMultilineCommand(command)).Unrelated finding, not fixed here: the relay spawns a remote Windows PTY without
useConptyDll: true(src/relay/pty-handler.ts:1564,:2111), diverging from all three local spawn sites. That affects DA1 blocking, wrap markers, and reflow — not this bug. Worth its own ticket.Readiness review
Reviewed against the 7-dimension release checklist. Verdict: ship — no P0, no P1.
The highest-risk item flagged for independent review was
makePaneKeythrowing on a paste path. It is not reachable:pane.leafIdis a branded UUID that the pane identity registry re-mints rather than accept invalid, and the same(tabId, pane.leafId)pair is already called unguarded from a hotter pre-existing site. Guarded anyway in the last commit, because the failure mode was bad — the throw escapes before the paste helper's.catchis attached, so a paste would be a silent no-op with no toast.Other verified-clean findings worth surfacing:
terminal.input()with pre-framed bytes, bypassing xterm's ownpaste(), so a local agent pane that did see DECSET 2004 gets one frame, not two.sanitizeBracketedPasteText, replacing embeddedESCwith U+241B — so a pastedESC[201~from scrollback cannot close the frame early. Thedirectpath it replaces had no such sanitization.Three P2 follow-ups were raised; all three are addressed in the final commit (pane-key guard + test, the remote-pane note below, and the sibling-divergence rationale).
Documented in code from the review: the process-confirmed-agent branch is dead for remote-runtime and SSH panes, because foreground tracking is disabled for them — so a remote pane's agent status row is its only evidence. That is precisely the configuration this bug was reported in.
Linked Issue
https://linear.app/stably/issue/STA-4294/paste-into-an-agent-pane-submits-the-parked-draft-when-bracketed-paste
Visual Proof
Real Orca window, real PTY, real system clipboard, real ⌘V. A TUI with a visible composer runs inside a pty wrapper that strips
ESC[?2004hfrom its output — byte-for-byte what Windows ConPTY does to a TUI, so the client never observes bracketed-paste mode. In both runs the drafthellois typed, then a clipboard payload whose first character is a newline is pasted.BEFORE — the draft is submitted.
sent: 1,>>> SENT: hello, and onlydef okis left in the composer. This is the reported bug.AFTER — the draft survives.
sent: 0, and the composer holdshello⏎def okwith the newline kept literally.Re-verified at final HEAD as a clean A/B: same TUI, same bytes, same paste, with the agent row as the only variable — row present gives
sent: 0and a preserved draft; row removed givessent: 1and>>> SENT: hello. That confirms the gate is narrow rather than a blanket force.Disclosure: the pane's agent identity was injected into the store for the capture, because the stand-in TUI is not a real agent binary. The paste path, the mode state, and the bytes are all genuine. A remote Windows host was not available; the ConPTY condition was reproduced at its only observable point — the missing DECSET.
Testing
11 unit tests in
terminal-agent-paste-bracketing.test.ts: the reported payload flipping fromdirect/unbracketed tobracketed-terminal/bracketed; plain shell pane unaffected; per-leaf gating; Windows-client behavior preserved; non-TUIagentTypeignored; process-confirmed agent with no row; restart-rehydrated veto; long-idle agent atdone; latchedshellForegroundnot suppressing an agent pane; single-line paste staying ondirect.Live: the before/after above, captured through the real UI.
Full local gates:
vitest run src/renderer/src/components/terminal-pane/— 265 files / 3385 tests passtsc --noEmit -p config/tsconfig.tc.web.json— cleanoxlint, react-doctor lint,oxfmt— clean via pre-commit. The one react-doctor warning inTerminalPane.tsxis pre-existing; verified it sits at the same site onmain.Platforms actually tested: macOS, against a local pty with the ConPTY condition emulated. Not exercised on Linux, a Windows client, or a real remote Windows host.
Review
POST_REPLAY_MODE_RESETalso ends inESC[?2004l. Affects remote hosts of any OS; needs the provenbracketedPastebit carried on the attach wire. Tracked separately, deliberately out of scope.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author