Repository navigation
Fix delayed terminal color-scheme replies leaking into fish - #8206
Conversation
ebc2a68 to
cc2ceec
Compare
📝 WalkthroughWalkthroughMode 2031 seed and theme-flip replies are centralized in a new module using immediate transport sends. Seed replies retry while disconnected, revalidate pane subscription state, and record successful modes. Appearance handling imports the shared flip helper and no longer re-exports the sequence helper. Lifecycle seeding delegates pane state, transport, mode resolution, recording, and scheduling through injected callbacks. Tests cover immediate-send routing, retry cancellation, gating, failure handling, and per-pane isolation. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 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.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-mode-2031-replies.test.ts (1)
67-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test for the retry-success path.
The suite covers the immediate-send routing and the unsubscribe cancellation, but doesn't verify that a scheduled retry actually delivers the reply when the transport connects while still subscribed. This is a core behavior of
pushMode2031SeedReplyand the harness already supports it.♻️ Proposed test addition
it('cancels a pre-connect retry after the program unsubscribes', () => { const harness = createHarness(false) harness.push() expect(harness.scheduled).toHaveLength(1) harness.subscribed.current = false harness.connected.current = true harness.scheduled.shift()?.() expect(harness.sendInputImmediate).not.toHaveBeenCalled() expect(harness.sendInput).not.toHaveBeenCalled() expect(harness.scheduled).toHaveLength(0) }) + + it('sends the reply when the transport connects during retry', () => { + const harness = createHarness(false) + + harness.push() + expect(harness.scheduled).toHaveLength(1) + + harness.connected.current = true + harness.scheduled.shift()?.() + + expect(harness.sendInputImmediate).toHaveBeenCalledWith('\x1b[?997;1n') + expect(harness.sendInput).not.toHaveBeenCalled() + expect(harness.recordMode).toHaveBeenCalledWith(1, 'dark') + }) })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d2fa06af-7e00-4eab-bb5b-51c7430668fb
📒 Files selected for processing (5)
src/renderer/src/components/terminal-pane/terminal-appearance.test.tssrc/renderer/src/components/terminal-pane/terminal-appearance.tssrc/renderer/src/components/terminal-pane/terminal-mode-2031-replies.test.tssrc/renderer/src/components/terminal-pane/terminal-mode-2031-replies.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
…#8206) * fix(terminal): send mode 2031 replies immediately * docs(terminal): name mode 2031 color replies accurately
Description
Fixes #8128.
fish 4.7.1 subscribes to terminal color-scheme updates with
CSI ?2031hand expects the terminal'sCSI ?997;1n/;2nresponse while it still owns a short raw-input read window. The visible-pane responder used ordinary remote input batching, so an 8 ms-delayed response could arrive after fish ranCSI ?2031land handed input to a foreground command. The escaped response then appeared as^[[?997;1n.This PR:
sendInputImmediate, matching other latency-sensitive terminal-query responders;?2031lcancels a stale seed;terminal-mode-2031-replies.tswith deterministic regression tests.Evidence of fix
Before: reproduced
Reproduction and protocol analysis: #8128 (comment)
A real fish 4.7.1 + node-pty + Orca xterm.js harness ran
sleep 0.15immediately after fish subscribed:This was rerun after implementation with the same result, proving the timing oracle independently of mocks. No external downloads or untrusted artifacts were used.
After: fixed source path
pnpm exec vitest run --config config/vitest.config.ts \ src/renderer/src/components/terminal-pane/terminal-mode-2031-replies.test.ts \ src/renderer/src/components/terminal-pane/terminal-appearance.test.ts \ src/renderer/src/components/terminal-pane/remote-runtime-pty-query-reply-immediate.test.tsThe regression oracle proves that the visible mode-2031 response calls
sendInputImmediatewithCSI ?997;1n, never calls ordinarysendInput, and sends nothing when a queued pre-connect attempt runs after unsubscribe. Existing remote-transport coverage also proves immediate replies flush earlier typed bytes in order before bypassing the 8 ms batch.Additional checks:
pnpm typecheck:web— passed.oxlinton all five changed files — passed.pnpm check:max-lines-ratchet— passed; no new suppression.pnpm check:reliability-gates— passed.pnpm test— 26,490 passed, 33 skipped, one unrelated 100-tab wall-clock threshold failure (57.17 ms > 50 ms); the isolated test rerun passed (1/1, 51 ms total test duration).pnpm lintreached an unrelated existing Japanese localization interpolation mismatch atcomponents.native-chat.composer.uploadingAttachments; changed-file lint and all relevant gates passed.ELI5
fish briefly asks Orca, “am I using dark or light colors?” Orca knew the answer, but remote terminals sometimes held that tiny answer for 8 ms to batch it with typing. By then fish had stopped listening, so the answer was treated like text typed into the next command and printed as random characters. Orca now sends this terminal-only answer immediately, and throws it away if fish has already said it no longer wants updates.
User-facing trade-offs
^[[?997;1n/^[[?997;2nleak into fish prompts or foreground commands on delayed remote paths.Terminal reliability proof
terminal-capability.query-reply-timeliness— a mode-2031CSI 997response must reach the subscribing program before its raw-read window closes, in byte order, and must never be sent for a subscription that has since been cleared. Motivated by [Bug]: Terminal leaks DSR escape sequence responses as garbled text (997;1n) with fish shell #8128.terminal-capability.startup-color-querygate is OSC 10/11-specific and remains unchanged. Intended future gate id isterminal-capability.mode-2031-reply-timeliness; this PR does not claim promotion from a mismatched gate.^[[?997;1n; immediate reply does not. Source-coupled tests require the immediate method and zero post-unsubscribe sends.leak, matching rendered lines, and raw PTY echo; focused tests identify whether immediate routing or stale cancellation regressed. No raw-terminal telemetry/logging was added.none— deterministic red/green coverage exists, but there is no registered manifest command or cross-platform stability history yet.