Repository navigation
fix(tui): ask the Coven daemon off the UI loop, with one deadline per request (#580) - #601
Merged
Merged
Conversation
…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
- 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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/coven sessions,/coven familiarsand/familiar listask 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.Related #580
Context
DaemonClient::sight,parse_response, the ledger inmain.rs) rather than adding another client./familiar(opening the agents menu reads familiar statuses throughload_agent_definitions);/familiar handoff(send_handoffin the TUI intercept);/covenverbs (status,info,log,events,send,kill,capabilities,actions) and/status doctor.They can move to the same
DaemonListingpath in a follow-up.--print, stream-json and ACP. They never run slash commands or contact the daemon;execute_commandis called only from the interactive loop.coven-code agents listprints 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:
Waiting for Coven: /coven sessionsuntil 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.Not sent; waiting on /coven sessions(both toasts fit the toast's 40 columns), and it comes down when the first listing lands./clear, a rewind or/session resumereplaces the transcript is dropped with its toast, so its answer never lands in the new transcript.daemon transport error: no complete answer within 5sinstead of the OS error text (Resource temporarily unavailable (os error 35)on macOS).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).requestrunsrequest_within(…, 5 s): one deadline over the connect, each write and each read.sightandcheck_reachabilityconnect with their own budgets; a full queue, or a connect a signal interrupts while it waits on one, reads as busy, not offline.sightkeeps 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 ofclaurst-coreon 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)withSessions,FamiliarsandAgents;DaemonListing::rundoes 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 intoagents_listing, shared bycoven-code agents listand/familiar list.crates/cli/src/main.rs:DaemonListingsholds 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.LedgerRegistrationsregisters and completes on plain threads;complete_allwaitsLEDGER_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.shand 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/44532594936a_connect_to_a_full_listen_queue_ends_at_its_deadlinepasses on macOS either way (the connect is refused). On Linux it was shown failing against a temporary mutation (the fix withUnixStream::connectput 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).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 main5057346e):git diff --check origin/main...HEAD: reports only the three lines added tocrates/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, andcargo clippy -p claurst-tools --features computer-use --all-targets --locked -- -D warnings: clean.cargo test --workspace --locked: 3519 passed, 0 failed, 69 ignored. Thenext_frame_perfalloc gate passes.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.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, scratchHOMEand 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).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:
connect_byignores 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 in761f393f; one test-only follow-up in7bad024d.sightignores 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 in9307ae07./familiar list foonow dropsfoo, is not a change: the namedagents listit called before ignored extra arguments too.Follow-ups and remaining risks
/familiar,/familiar handoff, the other/covenverbs,/status doctor), and so does the familiar status read when a familiar is saved or deleted in the agents menu (it reloads the definitions throughload_agent_definitions)./coven statusand/status doctorskip 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 toDaemonListing.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_deadlineproves the connect deadline only on Linux; macOS refuses the connect at once.Waiting for Coventoast stays up until the turn ends, even when the answer has already landed and is being held.no complete answer within 5s;/agent listwaits under the label/familiar list; inthe_daemon_listings_do_not_wait_for_the_daemonthe 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, whichclear_command_errordoes today.PR Readiness
Cargo.lockchanged through cargo, for the new dependency edge only.)docs/tui-v2/reconnect-policy.md; tmux suite README row.)