Repository navigation
feat(desktop): attach to or start the local serve, restart it with backoff - #1097
Merged
Merged
Conversation
…ckoff Supervisor::launch attaches to a tole serve that answers on the private socket and speaks protocol version 1, or starts one with a per-launch credential on an inherited pipe. A second launch attaches and never starts a second serve (a launch lock decides, the serve's flock refuses the rest). A serve with another protocol version or a socket directory that is not owner-only is refused. A serve that stops by itself is started again with a growing wait and given up on after too many stops. Closing the window leaves the serve running; quit_completely stops it and waits until its lock proves it is gone. Part of #1029.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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.
What
The lifecycle of the local
tole serveon top of the building blocks of #1096:Supervisor::launchattaches to a serve that answers on the private socket or starts one, a monitor thread notices a serve that stopped and starts it again with a growing wait, andquit_completelystops it. Nothing in a window calls it yet; the state it publishes is theServeStateof #1095.Why
Part of #1029 (owner decisions D3, D4 and D8 and the answers of 2026-11-21: closing the window leaves the serve running, the restart numbers, no keychain yet). The desktop is a thin client and has to own the answer to "is there a serve I can talk to, and with what credential".
Changes
supervisor/engine.rs:Engine::ensuredecides, in order: a serve answers and speaks protocol 1 → attach (using the credential file if the token is accepted); another protocol version, a not-tole listener, a socket directory that is not owner-only → refused with a plain-languageServeFailure; nothing answers → take the launch lock, check again, start one with a fresh per-launch token. A second desktop process attaches and never starts a second serve: the launch lock decides, and the serve's ownflockrefuses the rest.supervisor/recover.rs:ticklooks at the serve (a child throughtry_wait, an attached one through the socket). A serve that stopped by itself becomesRestartingand is started again once theBackoffhas passed; a steady run of 60 s resets the count; after 6 starts that did not hold it is given up on with the last lines of its standard error. A serve that was not started here is not treated as a crash loop.supervisor/stop.rs:stop_serveasks withSIGTERM, waits until the serve's lock is free (the proof that it is gone, however it ended), thenSIGKILL, and only then removes the socket file the signal left and the credential file.StopErrorsays why it could not (unknown process, signal refused, still running).supervisor/hub.rs: the shared state, the observer callback and the credential, so aClientcan be built from outside only while there is a serve to talk to.supervisor/mod.rs: the publicSupervisor(launch,launch_observed,state,client,retry,restart_serve,quit_completely,close_window).close_windowhonoursCloseBehavior: by default it leaves the serve running.supervisor/probe.rs:Refusedis split intoInsecure(the client refused a socket that is not the owner's alone) andInvalid(a path that cannot be a socket address), so the failure text can tell the user which.supervisor/fake.rsandtests.rs: a faketoleand 13 tests of the engine.process.rstakes the shared spawn guard in its test.CHANGELOG.md.Known edge, stated rather than hidden: when the serve was not started by this process,
stop_servesignals the pid of the socket's owner (SO_PEERCRED/LOCAL_PEERPID), and only while the serve's lock is held. If a different process replaced the socket file while the real serve still holds the lock, the signal would go to that process. The socket lives in the private0700directory, so only the same user can do that. A later change can take the pid from the holder of the lock instead; it is not done here.Callers checked with grep: everything new is inside
supervisor/and has no caller outside it; the one edited existing file isprobe.rs(itsRefusedcallers are all in this module and are updated). Nopubitem of a published crate changes.Testing
cargo test -p tole-desktop: 39 tests pass. The 13 new engine tests cover: attaching to a running serve without starting a second; a second launch attaching to the same serve; another protocol version refused and never talked to; a serve that does not take the credential is not used; a socket directory that is not owner-only refused and left alone; a directory widened while a serve runs stops the desktop from sending anything; notolebinary is a clear state; a start that fails says why and is not retried on launch; a serve that dies restarts with growing waits and is then given up on; a serve that comes back on its own is attached to; closing the window leaves the serve running by default;quit_completelywith nothing running cleans up and reports stopped; the desktop never signals itself when the serve is in its own process.SIGTERMthenSIGKILLpath against a real serve, and the reset of the restart count after a 60 s steady run (a unit test ofBackoffin feat(desktop): add the building blocks of the local serve supervisor #1096 covers the count itself). The end-to-end test against the realtolebinary is the next PR of this series and covers the stop.cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo clippy -p tole-cli --no-default-features --all-targets -- -D warnings,cargo clippy -p tole-desktop --features gpui --all-targets -- -D warnings,bash scripts/desktop-check.sh all: pass.flockbehaviour were never run there; the Desktop macOS job builds and runs the unit tests only), Windows (not compiled), running as an unprivileged user.scripts/review-local.shnot run (no LLM key); the CI Cora Review is the gate.Part of #1029.