Skip to content

fix(terminal): bracket agent-pane pastes so a pasted newline can't submit the draft - #14456

Merged
brennanb2025 merged 6 commits into
mainfrom
brennanb2025/remote-windows-codex-paste
Aug 15, 2026
Merged

brennanb2025 merged 6 commits into
mainfrom
brennanb2025/remote-windows-codex-paste

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

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?\n to \r and wraps the payload in ESC[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:

src/renderer/src/components/terminal-pane/TerminalPane.tsx:718-720
// Why: Windows ConPTY doesn't forward DECSET 2004 from TUIs, ...
const forceBracketedMultilineTextPaste = isWindowsUserAgent()

isWindowsUserAgent() reads navigator.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:

entry point file
Cmd+V / Ctrl+V + native paste event TerminalPane.tsx
Edit ▸ Paste menu TerminalPane.tsx
right-click / context menu use-terminal-pane-context-menu.ts
middle-click primary selection TerminalPane.tsx — had no force flag at all

Evidence 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 latched true while 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 at done with an old updatedAt; 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.

shell ?2004h / ?2004l
zsh 5.9, fish 4.8.1, bash >= 5.1 2 / 2 — l emitted ~1ms before exec
macOS /bin/bash 3.2, /bin/sh, bash 4.4 0 / 0 — never emits anything
bash 5.2 with enable-bracketed-paste off 0 / 0
zsh with unset zle_bracketed_paste 0 / 0
bare cat as the pty command 0 / 0

The 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/bash and /bin/sh are 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 bare cat in a pty, capturing what the program actually received:

received: \e[200~foo\nbar\e[201~\n

The markers arrive as literal payload bytes (rendered ^[[200~foo), and ICRNL still turned the CR into a newline, so foo submitted 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 announces h, 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 beyond INHERIT_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 makePaneKey throwing on a paste path. It is not reachable: pane.leafId is 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 .catch is attached, so a paste would be a silent no-op with no toast.

Other verified-clean findings worth surfacing:

  • No double-bracketing. The forced path uses terminal.input() with pre-framed bytes, bypassing xterm's own paste(), so a local agent pane that did see DECSET 2004 gets one frame, not two.
  • Security is net-positive. The forced path runs the payload through sanitizeBracketedPasteText, replacing embedded ESC with U+241B — so a pasted ESC[201~ from scrollback cannot close the frame early. The direct path it replaces had no such sanitization.
  • No backward-compat surface. No persisted state, schema, settings key, IPC payload, or wire contract touched.
  • Tests are not vacuous — mutation-checked: killing any single branch fails a specific test.

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[?2004h from its output — byte-for-byte what Windows ConPTY does to a TUI, so the client never observes bracketed-paste mode. In both runs the draft hello is typed, then a clipboard payload whose first character is a newline is pasted.

BEFORE — the draft is submitted. sent: 1, >>> SENT: hello, and only def ok is left in the composer. This is the reported bug.

orca-proof-BEFORE.png

AFTER — the draft survives. sent: 0, and the composer holds hello⏎def ok with the newline kept literally.

orca-proof-AFTER-v2.png

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: 0 and a preserved draft; row removed gives sent: 1 and >>> 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 from direct/unbracketed to bracketed-terminal/bracketed; plain shell pane unaffected; per-leaf gating; Windows-client behavior preserved; non-TUI agentType ignored; process-confirmed agent with no row; restart-rehydrated veto; long-idle agent at done; latched shellForeground not suppressing an agent pane; single-line paste staying on direct.

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 pass
  • tsc --noEmit -p config/tsconfig.tc.web.json — clean
  • oxlint, react-doctor lint, oxfmt — clean via pre-commit. The one react-doctor warning in TerminalPane.tsx is pre-existing; verified it sits at the same site on main.

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.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Review

  • Security — no new IPC, no new input surface; strictly narrows when raw bytes reach a PTY.
  • Cross-platform — the Windows-client branch is preserved unchanged and short-circuits first. Non-Windows clients gain bracketing only for agent panes.
  • Remote SSH — no wire change. A separate, unfixed defect found while investigating: on SSH relay panes the mode bit can be lost outright, since relay reattach replays a 100 KiB rolling raw tail with no server-side emulator or persisted modes, and that truncation then seeds main's headless model. POST_REPLAY_MODE_RESET also ends in ESC[?2004l. Affects remote hosts of any OS; needs the proven bracketedPaste bit carried on the attach wire. Tracked separately, deliberately out of scope.
  • Mobile — untouched; mobile has its own send path.
  • Backwards compatibility — no persisted-state or protocol change.
  • Performance — two record lookups per paste.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

Author

  • X / Twitter: @BrennanKB5

…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
@brennanb2025
brennanb2025 marked this pull request as ready for review August 14, 2026 05:45
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a8cff455-7d49-483b-8e17-ff0e37580de4

📥 Commits

Reviewing files that changed from the base of the PR and between 6728e36 and 7c5bc23.

📒 Files selected for processing (15)
  • src/main/ipc/dashboard-payload-validation.test.ts
  • src/main/ipc/dashboard-payload-validation.ts
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.tsx
  • src/renderer/src/components/dashboard-popout/preview-terminal-paste.ts
  • src/renderer/src/components/dashboard/dashboard-card-terminal-input.test.ts
  • src/renderer/src/components/dashboard/dashboard-card-terminal-input.ts
  • src/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-coordinator.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-model.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-payload-metadata.test.ts
  • src/renderer/src/lib/paste-payload-metadata.test.ts
  • src/renderer/src/lib/paste-payload-metadata.ts
  • src/shared/dashboard-snapshot.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/terminal-pane/terminal-paste-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-coordinator.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-model.ts

📝 Walkthrough

Walkthrough

Terminal paste protection now resolves per pane from platform, pane identity, agent status, and foreground-agent state. Windows input-record pastes support alt-enter and csi-u newline encoding with byte-aware chunk planning. Keyboard, app-menu, middle-click, context-menu, and clipboard paste paths pass the resolved options. Tests cover agent selection, pane scoping, Windows encoding, chunking, and single-line pastes.

Merge Risk: 🔵 Low · up to 7c5bc

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix for unsafe newlines in agent-pane pastes.
Description check ✅ Passed The description thoroughly covers the change, rationale, linked issue, visual proof, testing, review areas, and checklist.
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 💡 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.

…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

@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/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.ts (1)

12-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb92f2 and 7f2a1dc.

📒 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
@brennanb2025

Copy link
Copy Markdown
Contributor Author

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 window.api.app.getIdentity() before any interaction: devRepoRoot=/Users/brennanbenson/orca/workspaces/orca/merman, devBranch=brennanb2025/remote-windows-codex-paste, git HEAD 7a9270dea36690c1dbebd1f2d6d46935870ecfe6.

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; pane.terminal.modes.bracketedPasteMode was false at paste time in both runs. Clipboard payload's first byte was \n. The pane's agent identity was injected into the store (agentStatusByPaneKey, agentType: codex) for the protected case, mirroring the PR's own disclosure.

Protected agent-pane case — draft preserved, sent: 0, frames: 1 (one ESC[200~/ESC[201~ frame received; composer holds hello\rThis is the pasted second line):

agent-pane-pre-paste.png

agent-pane-preserved.png

Narrow non-agent control (same TUI, no agent row) — pre-fix behavior unchanged: sent: 1, >>> SENT: "hello", frames: 0 (draft submitted; the gate is per-pane, not a blanket force):

control-shell-submitted.png

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.

@OrcaWin

OrcaWin commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

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.

pr14456-windows-validation-failure.png
pr14456-windows-validation-failure.png

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a9270d and 6728e36.

📒 Files selected for processing (14)
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.test.ts
  • src/renderer/src/components/terminal-pane/terminal-agent-paste-bracketing.ts
  • src/renderer/src/components/terminal-pane/terminal-bracketed-paste.test.ts
  • src/renderer/src/components/terminal-pane/terminal-bracketed-paste.ts
  • src/renderer/src/components/terminal-pane/terminal-clipboard-paste.test.ts
  • src/renderer/src/components/terminal-pane/terminal-clipboard-paste.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-chunks.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-coordinator.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-executor.ts
  • src/renderer/src/components/terminal-pane/terminal-paste-model.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts
  • src/shared/tui-agent-config.ts

Comment on lines +174 to +203
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()

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.

🎯 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

@OrcaWin

OrcaWin commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Fixed-HEAD Windows Low Spec rerun at 6728e369e4776d9500c157d40a565101a8294d9f: ✅ in real OpenConsole/ConPTY with Codex 0.145.0, both Ctrl+V and Ctrl+Shift+V kept their unique parked drafts unsubmitted while the complete LF-leading payload remained in the composer (Context 0% used); focused paste tests passed 82/82. Evidence screenshot.

@brennanb2025
brennanb2025 merged commit e12b22c into main Aug 15, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
nwparker added a commit that referenced this pull request Oct 25, 2026
…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]>
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.

2 participants