Skip to content

fix(terminal): deliver batched output when a paired view pauses, so its queries get answered - #33749

Merged
nwparker merged 2 commits into
mainfrom
nwparker/agint-32944
Oct 26, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/agint-32944

Conversation

@nwparker

@nwparker nwparker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

ELI5

When you switch away from a paired-server terminal, the desktop tells the host to stop sending output for it. A few bytes can still be waiting in the host's 5 ms send buffer at that moment. The host was throwing those bytes away. If they held fish's "what terminal are you?" question (DA1), nothing ever answered it, and fish froze for 10 s and printed fish could not read response to Primary Device Attribute query. Now the host sends those buffered bytes before it pauses, so the desktop sees the question and answers it.

Root cause

#33273 made the host's own responder answer queries while a remote view is paused. It decides who answers once, when the chunk is ingested (shouldAnswerQueriesForLiveChunk → hasRemoteReceivingOutput). If the view is receiving at that moment, the host stays silent and the view owns the reply.

The chunk then waits in the multiplex output batcher (terminal-output-batcher.ts, 5 ms timer, often longer under load). The SetOutputPaused handler set outputPaused = true first and only then flushed the batcher. The flushed bytes went into the paused gate (queueOrSendOutput) and were dropped. So no one answered them: the host had already handed the reply to the view, and the view never got the bytes. #33273's PR lists this as known gap 1.

Trace from a failing run on main (host-side instrumentation, not committed):

21700 INGEST DA1  mainAnswers=false remoteRecv=true    <- host yields the reply to the view
21729 STREAM DA1  paused=false buffering=false          <- chunk enters the output batcher
21767 PAUSE       paused=true
21767 QUEUE DA1   paused=true                           <- batcher flush lands in the paused gate: dropped
...   fish warns after 10 s

What changed

  • terminal-multiplex-slot-frames.ts: on pause, flush the output batcher before setting outputPaused, so already-ingested bytes reach the view.
  • The desktop already handles bytes that arrive after it paused. They take the hidden-pane path (shouldSkipHiddenRendererOutput → skipHiddenRendererOutput → writeHiddenStartupRendererQueries), which answers stateless queries such as DA1. Live traces showed that path answering these late bytes.
  • The ack backlog cleared on pause is unchanged. It is discarded only under flow-control pressure, and resending it would undo the backpressure.

Each query is still answered exactly once. The host yielded these bytes to the view at ingestion, and now the view gets them.

Verification

  • Repro used real fish 4.9.3 (release binary in a temp dir), a headless --serve host and a paired desktop client, with isolated profiles, hidden windows and ORCA_BACKGROUND_LAUNCH=1. It ran a scratch Playwright spec that is not checked in. Scenario: the desktop opens a new terminal tab in the server workspace, then switches to another tab after about 150 ms. A host-side 300 ms delay on SetOutputPaused emulated SSH latency.
    • main: 1/5 and 1/10 warned; failing traces show the batcher drop above.
    • With this change, the batcher drop no longer occurs: 0 DA1 chunks hit the paused gate across 35 runs. 2/35 still warned, from the client-side gap below.
  • The other scenarios didn't warn on main: a CLI-created background terminal with no client (0/2); with a paired client viewing the workspace (0/5); with the workspace inactive (0/5); a visible desktop tab (0/5).
  • Unit test: terminal-multiplex-paused-output-drop.test.ts now asserts that output batched when the pause lands, including a DA1, is delivered and no drop notice is sent. It fails on main, passes here.
  • pnpm tc, pnpm test src/main/runtime/rpc (395 files, 4027 tests), and pnpm run check:code-quality:changed pass.

Known remaining gap (not fixed here)

In the remaining failures, the DA1 was ingested while the new stream was still buffering before its first snapshot. The host sent it after the snapshot (not covered, seq 83 > snapshot seq 0), and the desktop's binary controller received the frame. It never reached the query branches of live-data-callback.ts, though: no hidden-skip, restore-queue drain, restore-queue clear, or salvage path logged it. So the desktop drops it earlier in its live-data path, while the newly created pane is still attaching and its first restore is in flight. Candidates are the reattach live-data deferral queue (deferredReattachLiveData), post-restore drop-duplicate reconciliation, and the hidden ordered-seq filter. None of these salvage queries. It needs its own fix and is tracked as a follow-up.

Compatibility / risk

  • No wire or protocol change. A new host with an old desktop: the old desktop receives straggler bytes it would have gotten anyway had the batch flushed 5 ms earlier. An old host: unchanged. Mobile (binary subscribe, no pause): unchanged.
  • Cross-platform: host-side TypeScript only. Folder workspaces: the repro used a folder workspace.
  • Managed SSH hosts get this only once their orcad updates. Orcad defers auto-update while any terminal is open on the host (orcad_update_terminals_running).

Refs #32944 (reporter @bengry; follow-up to #33273).

Agent skill upstream boundary

  • Not applicable.

…ts queries get answered

Main yields a chunk's query replies to a receiving remote view at ingestion.
If that view paused while the chunk was still in the 5 ms output batcher,
the pause flushed it into the paused gate and dropped it, so a fish DA1
went unanswered and fish stalled 10 s. Flush the batcher before applying
the pause; the desktop's hidden-pane path already answers queries in
bytes that arrive after it paused.

Refs #32944
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9cd61f9c-31c3-43ba-941b-ee04f4954d68
Commits

Reviewing files that changed from the base of the PR and between 61cab5e and c66d877.

Files selected for processing: 2
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-slot-frames.ts
  • src/main/runtime/rpc/terminal-multiplex-paused-output-drop.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker
nwparker merged commit f460c92 into main Oct 26, 2026
42 checks passed
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.

1 participant