Repository navigation
Description
Summary
On POSIX hosts, terminal query replies reach the pty out of the order the queries were observed. OSC responses and private-DSR replies are deferred 21–200 ms by the echo-safe delivery path added in #13309, while CPR and DA1 replies are written immediately.
Programs that use DA1 as a read sentinel — fish, and the idiom generally (neovim, kitty/ghostty capability detection, termwiz) — block until DA1 returns, consume everything ahead of it, then hand the tty to the next child. Any reply arriving after DA1 is stranded in the tty input queue and is read as stdin by that child.
This is a sibling of #9993 but a distinct mechanism, and it is deterministic, not racy.
The key finding: latency is not the failure mode — ordering is
Measured with real fish 4.7.1 under node-pty:
| Reply emission | Leak? |
|---|---|
| In query order, 0 ms | no |
| In query order, uniform 200 ms delay | no |
| Query order, OSC 11 delayed 1 ms relative to CPR/DA1 | yes |
| Query order, OSC 11 delayed 5 / 20 / 200 ms | yes (all) |
| DA1 delayed 50 ms (DA1 last) | no |
A 200 ms in-order reply is fine. A 1 ms out-of-order reply leaks.
Root cause
extractOnlyCookedEchoSafeQueryReplies (src/shared/terminal-query-reply.ts:100-115) admits only OSC responses and private DSR CSI ? … n. So per fish prompt paint:
| Reply | Path |
|---|---|
\x1b]11;rgb:…\x1b\\ (OSC 11) |
echo-safe queue: 21–200 ms |
\x1b[?997;1n (private DSR) |
echo-safe queue |
\x1b[1;1R (CPR) |
immediate |
\x1b[?1;2c (DA1) |
immediate |
PtyStartupReplyDelivery.answer (src/shared/pty-startup-reply-delivery.ts:199-218) never writes directly on posix-pty; it queues and sets a deadline of ECHO_POLL_BUDGET_MS = 200 (:71). attemptPendingWrites (:290-329) polls stty — a subprocess per poll, measured min 21.2 / p50 21.7 / max 112.9 ms — and a deadline timer calls flushPendingWrites() unconditionally regardless of echo state. So when fish has already handed the tty to a cooked-mode child, the reply is held the full budget and then written into that child's stdin anyway.
Three call sites split identically: src/main/providers/local-pty-provider.ts:1082-1087, src/main/daemon/session.ts:247-252, src/relay/pty-handler.ts:1695-1700. Hidden/parked panes answer from main's headless emulator but sink through the same ptyController.write (src/main/runtime/orca-runtime.ts:11461-11478), so they invert identically — the renderer round trip is not required to reproduce this.
Reproduction
Verified against real fish + the real PtyStartupIngress / PtyStartupReplyDelivery / createPtySlaveEchoProbe imported from the worktree, with local-pty-provider.write()'s split reproduced verbatim (3/3 runs leaked):
[ 868.900ms] ORCA-WRITE OSC11 -> ECHO-SAFE QUEUE "\e]11;rgb:2828/2c2c/3434\e\"
[ 868.944ms] ORCA-WRITE CPR -> immediate "\e[1;1R"
[ 868.956ms] ORCA-WRITE DA1 -> immediate "\e[?1;2c" <-- fish's sentinel arrives FIRST
[1079.316ms] INGRESS->PTY deferred write "\e]11;rgb:..." <-- exactly +200.16ms
[3610.492ms] RESULT GOT-line "GOT: '\x1b]11;rgb:2828/2c2c/3434\x1b\\hello\n'" LEAKED
Control run with --bypass-echo-safe: 3/3 clean, GOT: 'hello\n'.
User-visible impact is the same as #9993: brew / npx / git add -p confirmations swallow the escape bytes.
Proposed fix — order-preserving reply FIFO per PTY
Restore the invariant: replies reach the pty in the order the queries were observed. Not "answer faster" (200 ms in-order is fine) and not "answer closer to the tty" (main already does for hidden panes and still leaks).
-
src/shared/pty-startup-reply-delivery.ts:199— add a sibling toanswer():/** Latency-critical replies that need no echo hold, but must not overtake a held one. */ answerInOrder(reply: string): boolean { if (this.closed) return false if (!defersWrite(this.ownerBackend) || this.pendingWrites.length === 0) return this.writeReply(reply) this.pendingWrites.push({ reply, onFailed: undefined }) // no new deadline; rides the head's return true }
flushPendingWrites()(:331-337) already drains FIFO, so nothing else changes. -
src/shared/pty-startup-ingress.ts:97-101— route echo-risk replies viaanswer()and every otherisTerminalQueryReplypayload viaanswerInOrder(). -
The three call sites above — admit plain CPR/DA/DECRPM/DCS replies into the FIFO instead of letting them jump it.
Validated by execution (--order-fifo, 3/3 clean): GOT: 'hello\n', no escape bytes.
Two properties worth noting:
- Self-limiting on latency. Holding DA1 keeps fish blocked in raw mode, so the first
sttyprobe returnsquietand the group flushes together — measured ~23 ms, not 200 ms. The ordering fix largely fixes the latency too. - Composes with [Bug]: Raw OSC 10/11 color-query replies leak as text in Linux agent pane (opencode) #12112 / Terminal escape sequence leaks as literal text during npx interactive prompt (e.g.
997;1n) #13137: the echo hold and cooked-echo projections are untouched.
Risk
Medium-narrow; every POSIX pty reply on three hosts. Main risk: CPR/DA1 inherit up to 200 ms latency whenever an OSC/private-DSR reply is pending for the same pty; a program with a sub-200 ms CPR timeout that also probes colors in the same burst could time out. Mitigation: consider a shorter live-reply budget (the 200 ms was sized for startup multi-pane restore, not steady state — see the rationale at pty-startup-reply-delivery.ts:59-70), or cap the in-order hold at one probe interval. Windows/ConPTY is unaffected (defersWrite() is posix-pty-only, :81-83).
Worth considering as a follow-up, not in the first fix: on budget expiry with the tty still echoing, the querying program has demonstrably left, so writing is strictly harmful. Dropping instead of flushing would close the residual window, but risks hanging a genuinely-cooked querier and needs its own evidence.
Notes
- [Bug]: Raw OSC 10/11 color-query replies leak as text in Linux agent pane (opencode) #12112 and Terminal escape sequence leaks as literal text during npx interactive prompt (e.g.
997;1n) #13137 are the reasons the deferral exists — they are the constraint here, not evidence for this bug. src/renderer/src/components/terminal-pane/issue-12112-agent-pane-startup-color-reply-leak.repro.test.tsmodels a single-writer startup tty and cannot express reply ordering across two writers, so it neither covers nor blocks this.- Found while fixing [Bug]:
?997;1ncolor-scheme replies leak into fish and corrupt stdin of interactive prompts (repro on v1.4.152) #9993; that PR deliberately does not include this fix (disjoint files, different regression surface across three hosts, independent revert decisions).
Made with Orca 🐋
Activity
rhlsthrm commentedon Aug 12, 2026
A second user-visible impact of this ordering inversion, beyond
brew/npx/git add -pswallowing bytes: TUI agents that use DA1 as the OSC 11 barrier resolve the wrong light/dark theme. Filed the symptom separately as #13908; adding the mechanism detail here since it bears on how the FIFO fix should be regression-tested.omp (oh-my-pi) 17.2.14 doesn't wait on a timeout for the color reply. It emits the query and a DA1 immediately after, and treats DA1's arrival as proof that nothing more is coming. From its shipped bundle (minified, names as emitted):
The DA1 branch of its reply handler pops that pending
osc11entry and abandons the in-flight query.So for this class of prober, your table's distinction between "1 ms out-of-order" and "200 ms in-order" has a sharper consequence than leakage: a late reply is not slow, it is a negative answer. The prober cannot distinguish "deferred 21–200 ms behind DA1" from "terminal does not support OSC 11". No bytes need to be dropped or misread for the failure to land.
Downstream, omp's fallback chain on macOS terminates in a constant:
Net effect on macOS in Light mode, in a light Orca pane: dark TUI. That's the same end state as #10492 reports on bundled ConPTY, reached through the POSIX path described here. (The
ZELLIJgate is an omp-side bug of its own — theirs to fix, not yours.)Attribution caveat, stated plainly: I verified omp's probe shape, its DA1-as-barrier handling, and its fallback chain by reading the installed bundle, and I verified macOS is in Light mode with
COLORFGBGunset. I have not captured a byte-level ordering trace inside my own pane, so "this issue's mechanism causes that theme outcome" is inference from two code paths that fit — not a measured reproduction. Anyone with the node-pty harness from this issue can confirm or kill it quickly.Suggested addition to the fix's test surface: the proposed
answerInOrderFIFO should be validated against a DA1-sentinel prober, asserting the OSC 11 reply is observed before DA1 — not only that no bytes strand into the next child's stdin. The fish repro exercises the leak surface but passes regardless of whether a prober that already gave up ever gets its answer in a usable order.Environment: Orca 1.4.180, macOS darwin 27.0.0 (Light), omp 17.2.14, no multiplexer,
COLORFGBGunset in the pane shell.nwparker commentedon Aug 12, 2026
I'm going to leave this open for a minute
Appreciate if people share screenshots on how this affects them!
test(terminal): guard the sync ECHO probe's wiring and its native bin…
AmethystLiang commentedon Aug 12, 2026
thanks for reporting. looking into it
AmethystLiang commentedon Aug 14, 2026
Related report transferred from #14020 (closing as a duplicate).
gh auth loginon Linux (and independently on macOS 1.4.180 / gh 2.97.0) fails at the first prompt with:That is the user-visible shape of this issue: gh (via termenv) sends OSC 11 then CPR and treats the CPR reply as its read sentinel, so the deferred OSC 11 reply lands in the prompt reader as an unexpected
ESC ]. Tracking continues here.fix(terminal): answer a query in its own turn when the kernel is quiet
test(terminal): guard the sync ECHO probe's wiring and its native bin…
yulin0629 commentedon Aug 16, 2026
Still reproducing on 1.4.183 (current Latest) — neither #13998 nor #14609 has landed yet. Adding a timing data point, since the reports above are on 1.4.180.
Client: chezmoi 2.72.0 (Homebrew), another termenv v0.16.0 consumer.
chezmoi statusemitsESC ] 11 ; ? ESC \thenCSI 6non startup.Measured from inside an Orca pane, raw mode, sending exactly that pair, 5 runs:
CPR first in 5/5. Same script, same machine, Terminal.app: OSC 11 first in 5/5, 0.30–0.74 ms.
The stranded reply is not just visible — it lands in the zsh edit buffer and runs:
(the
clearI typed was swallowed into the leaked text)macOS Darwin 25.5.0 arm64, zsh,
TERM=xterm-256color, plain (non-agent) pane.nwparker commentedon Sep 19, 2026
Current main contains the ordered live-query reply path. The shared regression suite explicitly models termenv/OMP behavior (OSC 11 then CPR) and proves replies are delivered [OSC 11, CPR], while reverse query order remains [CPR, OSC 11]. The focused Orca run passed 182/182, including real node-pty fish coverage and daemon/session reply paths. Closing as fixed; reopen if a current build reproduces it.
nwparker commentedon Sep 19, 2026
Fixed and covered by current query-reply ordering tests.