Skip to content

fix(tui): ask the Coven daemon off the UI loop, with one deadline per request (#580) - #601

Merged
BunsDev merged 8 commits into
mainfrom
fix/580-daemon-requests-off-loop
Nov 28, 2026
Merged

BunsDev merged 8 commits into
mainfrom
fix/580-daemon-requests-off-loop

Conversation

@BunsDev

@BunsDev BunsDev commented Nov 20, 2026

Copy link
Copy Markdown
Member

Summary

  • A Coven daemon that accepts a connection and never answers no longer freezes the terminal. /coven sessions, /coven familiars and /familiar list ask the daemon on a thread of their own, in Classic and Next; the loop keeps reading keys and drawing, says after 300 ms that it is waiting, and shows the result when it lands. A second listing typed while one waits is not sent.
  • Every daemon request has one 5 s deadline over the connect, the request and the whole answer. A peer that trickles bytes, or a full listen queue on Linux, can no longer hold a request (or the ledger registration) past it.
  • Quitting waits at most 2 s for the session completions (plus up to 2 s for a registration still in flight, unchanged), and nothing the ledger started keeps the process alive after that.

Related #580

Context

  • Related issue/user request: A Coven daemon that accepts and never answers freezes the TUI for 5 s per command, and quit for 5 s #580, found with the accepts-and-never-answers daemon from feat(tui): read a restarted Coven daemon as unknown until the next session start #547's journey. Builds on feat(tui): read a restarted Coven daemon as unknown until the next session start #547's probe and transport (DaemonClient::sight, parse_response, the ledger in main.rs) rather than adding another client.
  • Scope: the daemon client's transport, the three listings named in the issue, and the exit's ledger wait.
  • Non-goals, and why this says "Related" rather than "Fixes": other places still ask the daemon on the UI loop thread. They are now bounded by the 5 s deadline instead of unbounded, but still freeze for up to that long against a silent daemon:
    • bare /familiar (opening the agents menu reads familiar statuses through load_agent_definitions);
    • /familiar handoff (send_handoff in the TUI intercept);
    • the other in-process /coven verbs (status, info, log, events, send, kill, capabilities, actions) and /status doctor.
      They can move to the same DaemonListing path in a follow-up.
  • Not changed: --print, stream-json and ACP. They never run slash commands or contact the daemon; execute_command is called only from the interactive loop. coven-code agents list prints the same text as before.

What changes in Classic

Classic is the default renderer and shares this loop, so these are Classic changes, all within #580's bug:

  • The three listings' output (or error) appears when the daemon answers instead of before the next frame; with a healthy daemon that is the next loop tick. If the answer takes longer than 300 ms, a toast says Waiting for Coven: /coven sessions until it lands. An answer that lands during a turn is held until the turn ends, so command output never lands between a prompt and its reply.
  • A listing typed while another is waiting is not sent; a toast says Not sent; waiting on /coven sessions (both toasts fit the toast's 40 columns), and it comes down when the first listing lands.
  • A listing still waiting when /clear, a rewind or /session resume replaces the transcript is dropped with its toast, so its answer never lands in the new transcript.
  • A request that runs out of time reads daemon transport error: no complete answer within 5s instead of the OS error text (Resource temporarily unavailable (os error 35) on macOS).
  • Quit with a daemon that never answers: about 2 s instead of 5 s (more when a listing was queued behind a freeze before).

The exit bound

The completions get 2 s, the budget the engine already gives a busy daemon (the reachability probe, the health reads around a registration). A daemon on a local socket answers a completion in milliseconds. Past 2 s the exit goes on without the answer; a completion the daemon never records leaves its row running, as against a daemon that is down. With a registration still in flight (the first seconds after a launch or a /session resume), the existing 2 s wait for it comes first, so a quit waits for the daemon 4 s at most, however it behaves. The registration and the completions now run on plain threads instead of the runtime's blocking pool, because #[tokio::main]'s runtime waits for that pool when it shuts down: before this, a registration still waiting for a silent daemon held the process up to 7 s after the exit had stopped waiting.

Changes

  • crates/core/src/coven_daemon.rs: connect_by(deadline) opens the socket with socket2 and sets its send timeout before connecting (Linux waits for room in a full listen queue for that long; macOS refuses at once). request runs request_within(…, 5 s): one deadline over the connect, each write and each read. sight and check_reachability connect with their own budgets; a full queue, or a connect a signal interrupts while it waits on one, reads as busy, not offline. sight keeps reading when macOS refuses the read timeout after the daemon has answered and closed. Tests: a trickling peer, a silent peer, a full listen queue.
  • crates/core/Cargo.toml, Cargo.toml, Cargo.lock: socket2 0.6 becomes a direct dependency of claurst-core on Unix. It was already in the lock at 0.6.3; the lock gains only the edge.
  • crates/commands/src/lib.rs: CommandResult::DaemonListing(DaemonListing) with Sessions, Familiars and Agents; DaemonListing::run does the blocking work and formatting that the three commands did inline. A missing socket file is still answered at once.
  • crates/commands/src/named_commands.rs: the agents list text moves into agents_listing, shared by coven-code agents list and /familiar list.
  • crates/cli/src/main.rs: DaemonListings holds the one listing in flight, shows the waiting toast, delivers the answer (held while a turn runs), refuses a second listing and forgets a listing when the transcript is replaced. LedgerRegistrations registers and completes on plain threads; complete_all waits LEDGER_COMPLETION_WAIT (2 s) at most.
  • docs/tui-v2/reconnect-policy.md: the transport, exit and silent-daemon sections updated.
  • scripts/tui-tests/cases/37_silent_daemon_keeps_input.sh and its README row.

Validation

Toolchain 1.100.0, macOS, CARGO_BUILD_JOBS=4, host load 17-21 during the final gates (local gates were run, not replaced by hosted runs).

Fail-first. The tests were committed first (bb33f72f, on main's code) and failed:

  • a_request_to_a_trickling_daemon_ends_at_its_deadline: the request took 15.098803334s against its 5 s deadline.
  • the_daemon_listings_do_not_wait_for_the_daemon: /coven sessions held the event loop for 5.004198583s: Some(Error("daemon transport error: Resource temporarily unavailable (os error 35)")).
  • exit_waits_a_bounded_time_for_an_unanswered_completion: the exit waited for a completion that never answers: Elapsed(()); daemon_ledger_calls_do_not_hold_the_runtime_at_exit: the runtime waited 5.101344s for daemon calls at exit. The same two failed on the hosted Linux run of that commit: https://github.com/OpenCoven/coven-code/actions/runs/44532594936
  • a_connect_to_a_full_listen_queue_ends_at_its_deadline passes on macOS either way (the connect is refused). On Linux it was shown failing against a temporary mutation (the fix with UnixStream::connect put back), pushed to a throwaway branch that is now deleted: the request was still connecting after 10 s: Timeout (https://github.com/OpenCoven/coven-code/actions/runs/44534268970).
  • tmux case 37 against a debug build of bb33f72f: 26 passed, 18 failed at 120x40 and at 80x24. In both renderers typed text was not drawn within 2.5 s after any of the three listings, no waiting toast, the second listing reached the daemon, and the exit took 8.6 s. (That run checked the older toast texts; the behaviour it failed on is the same.)

After the change (head 4632fd9d, which merges main 5057346e):

  • git diff --check origin/main...HEAD: reports only the three lines added to crates/core/Cargo.toml, for their CRLF line endings. Every line of that file on main ends in CRLF, so the new lines keep the file's convention.
  • cargo fmt --all -- --check: clean.
  • cargo check --workspace --locked: clean.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and cargo clippy -p claurst-tools --features computer-use --all-targets --locked -- -D warnings: clean.
  • cargo test --workspace --locked: 3519 passed, 0 failed, 69 ignored. The next_frame_perf alloc gate passes.
  • Targeted: cargo test -p claurst-core --lib coven_, cargo test -p claurst-commands --lib -- coven daemon_listing agent_command familiar, cargo test -p claurst --bin coven-code -- ledger exit_ daemon_listing registration: all pass.
  • tmux suite (scripts/tui-tests/run.sh, debug build of the head): 826 of 826 at 120x40 and 826 of 826 at 80x24, none skipped (REQUIRE_TMUX=1, scratch HOME and working directory outside the home directory). Case 37 alone: 44 of 44 at each size; typed text was drawn about 0.0-0.1 s after each listing, each listing ended with its result after about 5 s, and the exit took about 2 s (the case allows 4.5 s, which still catches the old 5 s wait).
  • Not run: Windows. The daemon client is Unix only (cfg(unix)); the hosted Windows jobs cover the build.

Review

Three independent review rounds, each by a fresh reviewer given only the diff and the issue:

  • Round 1 (fix commit): the exit wait set to 2 s, a listing forgotten when the transcript is replaced, socket2's sub-millisecond timeout guarded, connect_by ignores a failed timeout setting after the peer closed, case 37 tightened (per-listing request count, a result not before 4 s, the daemon stopped when the case fails to start). Fixed in 761f393f; one test-only follow-up in 7bad024d.
  • Round 2: shorter toasts and the refusal toast cleared with its listing, an answer held while a turn runs, sight ignores a failed timeout setting after the daemon closed, a connect a signal interrupts reads as busy, doc moves, the case's exit bound set to 4.5 s. Fixed in 9307ae07.
  • Round 3 (this head, after merging main): nothing blocking. Its non-blocking points are listed under follow-ups below; none of them changes code in this PR. One point, that /familiar list foo now drops foo, is not a change: the named agents list it called before ignored extra arguments too.

Follow-ups and remaining risks

  • The loop-thread daemon calls listed under Context remain (bare /familiar, /familiar handoff, the other /coven verbs, /status doctor), and so does the familiar status read when a familiar is saved or deleted in the agents menu (it reloads the definitions through load_agent_definitions). /coven status and /status doctor skip their follow-up reads when the 200 ms probe gets no answer, but a daemon that sends one byte passes the probe, and each later read can then hold the loop for up to 5 s. One follow-up issue could move them all to DaemonListing.
  • A slow but working daemon that takes more than 2 s to record a completion loses it at exit; the row stays running, as against a daemon that is down. This is the intended bound (see "The exit bound").
  • a_connect_to_a_full_listen_queue_ends_at_its_deadline proves the connect deadline only on Linux; macOS refuses the connect at once.
  • While a turn runs, the Waiting for Coven toast stays up until the turn ends, even when the answer has already landed and is being held.
  • Small: a connect a signal interrupts, or a read that times out a little early, is reported as no complete answer within 5s; /agent list waits under the label /familiar list; in the_daemon_listings_do_not_wait_for_the_daemon the elapsed-time check carries the proof, and the zero-connections check is weaker; case 37 relies on the previous listing's error being cleared when the next one is typed, which clear_command_error does today.

PR Readiness

  • Diff is limited to the intended files.
  • Generated files were not edited by hand. (Cargo.lock changed through cargo, for the new dependency edge only.)
  • User-facing docs/help were updated or are not needed. (docs/tui-v2/reconnect-policy.md; tmux suite README row.)
  • No secrets, credentials, local paths, or unrelated logs are included.
  • Remaining risks or follow-up work are listed above.

…580)

Tests that fail on main:

- core: a request to a peer that trickles one byte a second outlives its
  5 s timeout (15 s), and on Linux a connect to a full listen queue waits
  without a deadline.
- commands: /coven sessions, /coven familiars and /familiar list block
  their caller for the 5 s request timeout against a silent daemon.
- cli: the exit waits without bound for a completion that never answers,
  and the runtime waits for in-flight ledger calls when it shuts down.
- tmux case 37: in Classic and Next, typed text is not drawn while a
  listing waits, a second listing is sent anyway, and quitting with a
  silent daemon takes more than 2.5 s.

socket2 becomes a direct dependency of claurst-core (already in the lock
at 0.6.3) so the Linux test can fill a listen queue.

Related #580
… request (#580)

- core: every request has one 5 s deadline over the connect, the request
  and the whole answer. The connect sets the socket's send timeout first,
  so a full listen queue on Linux waits only until the deadline; the
  health probe's connect shares its budget too. A request that runs out
  of time says so ("no complete answer within 5s").
- commands: /coven sessions, /coven familiars and /familiar list hand
  back a DaemonListing instead of asking the daemon on the caller's
  thread. The agents list text moves into agents_listing, shared with
  `coven-code agents list`.
- cli: the loop runs one listing at a time on a thread of its own. After
  300 ms a notice says the daemon is being waited for; the answer lands
  as the command's message or error. A second listing meanwhile is not
  sent, and a notice says so.
- exit: the registration and the completions run on threads of their own
  instead of the runtime's blocking pool, which the runtime waits for at
  shutdown. The exit waits at most 1 s for the completions (plus up to
  2 s for a registration still in flight, as before).

Related #580
- The exit waits up to 2 s for the completions, the budget the engine
  gives a busy daemon elsewhere, instead of 1 s.
- A listing still waiting when /clear, a rewind or /session resume
  replaces the transcript is forgotten with its notice.
- connect_by: never hand socket2 a timeout under 1 ms (it reads one
  under 1 us as none), and do not fail a connect whose peer has already
  answered and closed (macOS refuses the timeout then).
- tmux case 37: each listing must send exactly one request and land its
  result no earlier than 4 s; stop the fake daemon when it fails to
  start; the exit bound is 3.5 s.

Related #580
…ts-off-loop

# Conflicts:
#	src-rust/crates/cli/src/main.rs
…580)

The earlier "Still waiting" warning lasts 5 s, so it is still the
current notification at that point of the test.

Related #580
- The waiting and refusal toasts fit the toast's 40 columns in both
  renderers ("Waiting for Coven: /coven sessions", "Not sent; waiting
  on /coven sessions"), and the refusal comes down with the listing.
- A listing answer that lands during a turn waits for the turn to end,
  so slash command output never lands between a prompt and its reply.
- sight keeps reading when macOS refuses the read timeout after the
  daemon has answered and closed.
- A connect interrupted by a signal while it waits on a full queue
  reads as busy, not gone.
- reconnect-policy.md: the transport note leaves "What this does not
  prove", and the registration bound gives both 9 s and 7 s.
- tmux case 37: matches the new toasts; exit bound 4.5 s.

Related #580
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 28, 2026 3:57am UTC

Request Review

@BunsDev
BunsDev merged commit 7d57d29 into main Nov 28, 2026
17 checks passed

This branch was successfully deployed

1 active deployment
Preview — c185eda8 Deployed Nov 28, 2026 by vercel[bot]
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