Skip to content

Stop fish from stalling 10s in terminals opened in the background - #32947

Closed
bengry wants to merge 3 commits into
stablyai:mainfrom
bengry:fix/fish-da1-before-first-attach
Closed

bengry wants to merge 3 commits into
stablyai:mainfrom
bengry:fix/fish-da1-before-first-attach

Conversation

@bengry

@bengry bengry commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When fish starts, it asks the terminal "what are you?" and waits for an answer. It asks twice in a row, and also after each resize and each command. If no Orca window is showing the terminal yet, nobody answers. Fish then ignores all input, Ctrl+D included, for 10 seconds and prints a warning. Now the daemon answers until the first input reaches the terminal, which shows that a window is live.

What Changed

  • Before: a plain shell (no startup command, so no shell-ready barrier) sends DA1 before any client attaches. The query is buffered, then the renderer replays it with replies suppressed (replay-guard.ts). Fish waits 10 s and warns.
  • After: for ungated shells, SessionShellReadyBarrier installs the existing startup DA1 responder and filter. It answers ESC[?1;2c, the renderer's own reply, and drops the query from recorded output. It releases them on the first client input (Session.write → noteClientInput()), after the existing 15 s timeout, and on every existing exit path. From then on the renderer answers as before.
  • Why input, not attach or the first answer: the daemon stream client attaches at creation, before any renderer exists, so attach proves nothing. An earlier revision released after the first answered DA1, but fish sends a second blocking DA1 right after the first reply (measured below). Only a live renderer or a user writes input, because replies to replayed bytes are suppressed.
  • The change is POSIX only. Windows (ConPTY) startup is unchanged.
  • session.ts gets 1 line. The existing "does not reply to terminal queries" test now attaches a client first, because the daemon answers before the first attach.

Why

The daemon already owns DA1 during startup for gated shells. This extends the same authority, with the same response and filter, to the one window where no renderer can answer. I rejected two alternatives:

  • Answering whenever no client is attached would change query authority mid-session. It also cannot live in the daemon: its stream client stays attached while renderers come and go upstream.
  • Answering DA1 in the daemon for the whole session would hide Sixel: the renderer adds attribute 4 to its DA1 reply when inline images are on (terminal-capability-replies.ts).
  • Letting the renderer answer replayed DA1 would undo the replay guard.

Why only fish

Orca drops the late query for every shell, but only fish waits on it. At startup, fish 4.x sends a batch of terminal queries, and DA1 marks the end of the batch. Fish waits up to 10 s for the DA1 reply. In the probe, fish sent ESC[?u (kitty keyboard), ESC[>0q (XTVERSION) and ESCP+q696e646e (XTGETTCAP indn), then DA1.

Queries the terminal at startup Waits for the reply
fish 4.x yes yes: 10 s, then the warning
bash (readline) no no
zsh (zle) no no

Prompt themes or plugins in bash or zsh can send their own queries, but they usually don't block. This PR covers only DA1, so those other queries are still unanswered before the first input. I did not run the probe with bash or zsh.

Linked Issue

Fixes #32944

Visual Proof

N/A. There is no UI change. The fix removes a 10 s stall and a warning printed by fish. The before and after numbers are under Testing.

Testing

Tested on Linux only. Real fish 4.9.3 (fish --no-config -i) in a raw PTY, timing a command sent at 0.5 s:

Reply policy DA1 queries seen (s) Command ran after
answer every DA1 0.01, 0.02, 0.52 0.05 s
answer only the first DA1 (previous revision) 0.01, 0.02, 10.53 10.06 s

The same probe shows fish sending ESC[6n, OSC 11 ? and then DA1 as a barrier on every resize and after every command.

For the first revision (release on attach) I also ran a throwaway probe, not committed: real fish through Session, with a client that answers DA1 seen live and never in replayed bytes, like the renderer. 28 shells per run, 3 rounds. Each value is warnings per 12 shells:

Client attach delay Before After
0 ms 0/12 0/12
20 ms to 3 s (6 delays) 12/12 each 0/12 each

Other checks:

  • session.test.ts and terminal-host.test.ts: the DA1 tests now send 2 queries before any input and expect both answered, then expect the next query to reach the client after input. Both fail on the previous revision and pass now.

  • pnpm tc:node passes. oxlint and oxfmt --check pass on the changed files.

  • src/main/daemon suite: 21 or 22 real-shell tests fail on my machine, the same tests with and without this change, from my local zsh/bash setup. The files are shell-ready, shell-ready-bash-wrapper, repro-13767, bash-prompt-command-composition and daemon-stream-backpressure-socket.

  • I manually tested these changes locally. I tested through the probe above, not in the packaged app.

  • Automated tests added/updated, or explained why not below

AI Disclosure

Root-cause analysis, the fix and the tests were done with Claude Code (Claude Opus 5.5 and Sonnet 5.5). I reviewed them.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Not covered: a resize or prompt while a renderer is briefly detached later in the session (for example while a paired client reconnects). The daemon cannot see that detach; fixing it needs the runtime layer that knows its viewers.

  • Edge: a write from main itself, such as an injected startup command, also counts as input and hands DA1 back early. That is no worse than before.

  • Security: the daemon writes a fixed 7-byte reply to the PTY only for DA1 queries before the first client input.

  • SSH and remote: this helps slow remote attaches.

  • Windows: excluded.

  • Performance: one CSI handler for the pre-attach window.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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). I ran typecheck and lint on the changed files, plus the daemon tests. The rest is left to CI.

…aches

A plain shell has no shell-ready barrier, so a DA1 sent before any client attaches is buffered and later replayed with replies suppressed. Fish then stalls 10s and warns. Reuse the startup DA1 responder until the first attach.
@bengry bengry changed the title fix(daemon): answer DA1 for ungated shells until the first client attaches Stop fish from stalling 10s in terminals opened in the background Oct 23, 2026
@bengry
bengry marked this pull request as ready for review October 23, 2026 22:34
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

For unsupported readiness on non-Windows platforms, the barrier installs a startup DA1 responder and filter. It releases them after the startup timeout or when client input arrives. Supported readiness continues to use the configured readiness timeout. Tests cover the initial DA1 response, forwarding subsequent queries, and a DA1 sequence split across the startup-window boundary.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to eb347

Some background terminals can still stall during fish startup when a startup command is sent. Keep DA1 handling active until query replies are available before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title "Stop fish from stalling 10s in terminals opened in the background" matches the main change. The PR adds startup DA1 answering for ungated shells, which stops fish from waiting 10 seconds fo…
Description check Passed The description follows the template and covers the main sections. The ELI5, What Changed, Why, Linked Issue (Fixes #32944), Visual Proof (N/A with reason), Testing, AI Disclosure, and Notes sections …
Linked Issues check Passed [#32944] The PR covers the Linux startup race for ungated shells. On POSIX, SessionShellReadyBarrier installs the existing DA1 responder and filter during the startup window. It answers repeated DA1…
Out of Scope Changes check Passed The production changes support [#32944] by extending the existing startup DA1 handling to ungated POSIX shells and notifying the barrier of client input. The updated session and terminal-host tests ve…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4…
Full details: Title check

Explanation

The title "Stop fish from stalling 10s in terminals opened in the background" matches the main change. The PR adds startup DA1 answering for ungated shells, which stops fish from waiting 10 seconds for a reply in terminals opened in the background. The title is specific and describes the user-visible result. It does not name the mechanism, but that is expected for a title.

Full details: Description check

Explanation

The description follows the template and covers the main sections. The ELI5, What Changed, Why, Linked Issue (Fixes #32944), Visual Proof (N/A with reason), Testing, AI Disclosure, and Notes sections are filled in with detail. The Testing section names the platform (Linux only) and gives timing results. The Checklist has one item left unchecked, and the description says the remaining checks are left to CI. The Review section has no content under its heading, and the 'Agent skill upstream boundary' item is checked. The template's Testing checkbox for manual testing is also left unchecked, and the author explains why. These gaps are minor.

Full details: Linked Issues check

Explanation

[#32944] The PR covers the Linux startup race for ungated shells. On POSIX, SessionShellReadyBarrier installs the existing DA1 responder and filter during the startup window. It answers repeated DA1 queries and removes them from recorded output. Session.write calls noteClientInput(), which releases the responder before later queries reach the client. The 15-second timeout remains a release path. Tests cover repeated startup DA1 queries, post-input forwarding, and a held DA1 prefix at timeout.

Full details: Out of Scope Changes check

Explanation

The production changes support [#32944] by extending the existing startup DA1 handling to ungated POSIX shells and notifying the barrier of client input. The updated session and terminal-host tests verify this behavior. The Windows path remains unchanged, and no unrelated production behavior is introduced.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4 files.

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

@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
  • 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: c39bf8e7-34ea-47fd-8dd4-86123a19e665
📥 Commits

Reviewing files that changed from the base of the PR and between 2c53a55 and 56debbb.

📒 Files selected for processing: 3
  • src/main/daemon/session-shell-ready-barrier.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread src/main/daemon/session.ts Resolved
…st DA1

The daemon stream client attaches when the session is created, so releasing on the first attach removed the responder before the shell ran. Fish still stalled 10 s. Release after the first answered DA1 instead, or after the 15 s startup window.
@bengry

bengry commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Correction: the first revision had no effect in the app.

  • Cause: TerminalHost attaches the daemon stream client when it creates a session, so "first attach" fired before fish started and nobody answered DA1.
  • Evidence: a real-fish run (fish 4.9.3) through createOrAttach, with no renderer attached, warned at 10.05 s on both the base and 56debbb.
  • Fix: 531939a releases DA1 authority after the first answered DA1, or after the same 15 s window the gated path uses (SHELL_READY_TIMEOUT_MS).
Code Daemon DA1 reply fish warning Prompt at
base none yes, 10.05 s 10.08 s
56debbb none yes, 10.05 s 10.08 s
531939a ESC[?1;2c no ~0.07 s

A new TerminalHost-level test covers this and fails without the fix.

Known trade-off: during the 15 s window, an ungated bash or zsh shell also gets its DA1 answered by the daemon. The reply is the same text the renderer sends (DEFAULT_DA1_RESPONSE).

fish sends a second blocking DA1 right after the first is answered, and
again on every resize and prompt. Releasing DA1 authority after the first
answer left that second query to a renderer that may not exist yet, so a
background fish still waited 10 s. Keep answering until the client writes
input, which only a live renderer or a user does.
@bengry

bengry commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

New revision (eb3476b9d): the daemon now answers DA1 for ungated shells until the first client input, not just the first query. The previous revision did not fix a background fish terminal. Measured with real fish 4.9.3 in a raw PTY:

Reply policy DA1 queries seen (s) Command ran after
answer every DA1 0.01, 0.02, 0.52 0.05 s
answer only the first DA1 (previous revision) 0.01, 0.02, 10.53 10.06 s

Fish uses DA1 as a barrier more often than I assumed. It sends ESC[6n, OSC 11 ? and then ESC[0c at startup (twice), on every resize, and after every command. Until the reply arrives or 10 s pass, it ignores all input, Ctrl+D included.

The same stall also happens later in a session. On a browser client against an orcad built from main, I ran 80 rounds of split + Ctrl+D with fish. When a sibling pane exits, every pane goes recovering for about 0.7 s and is resized. In 5 of the 80 rounds, a host-side sampler showed fish exiting 11.6-11.8 s after Ctrl+D instead of about 1.5 s. This PR does not fix that case: the daemon cannot see a renderer detach, because its stream client stays attached. It needs the runtime layer that knows its viewers. The PR description lists it under Notes.

@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
  • 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: b6750ca0-d1dd-4407-bc86-d710a1bb26b7
Commits

Reviewing files that changed from the base of the PR and between 531939a and eb3476b.

Files selected for processing: 4
  • src/main/daemon/session-shell-ready-barrier.ts
  • src/main/daemon/session.test.ts
  • src/main/daemon/session.ts
  • src/main/daemon/terminal-host.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@nwparker

Copy link
Copy Markdown
Contributor

Thank you, @bengry, for both the report and this PR. Your measurements made the race easy to see: the warning only shows up when the view attaches late, and the DA1 query fish sends gets no answer from anyone.

We went with a different fix, in #33273, and are closing this one in favor of it. Running real fish against a windowless orca serve host with a paired desktop, we found where the query was actually lost. Local terminals were fine, because main already answers queries for panes nobody is showing. On a paired host, though, the desktop pauses the stream of a background tab. The host dropped that output but still treated the paused view as the one answering, so it stayed quiet too. #33273 makes the host's existing responder answer whenever the only view is paused, the same way it already does for hidden local panes. That keeps one responder per query, with no new answerer in the daemon, no 15-second window, and nothing tied to the first keystroke. It also covers queries sent after startup.

We didn't take code from this PR, but your diagnosis shaped the fix, so the commit credits you as a co-author. Thanks again!

@nwparker nwparker closed this Oct 24, 2026
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.

[Bug]: fish warns about unanswered Primary Device Attribute query when a terminal attaches late

2 participants