Repository navigation
feat(desktop): add the building blocks of the local serve supervisor - #1096
Merged
Merged
Conversation
crates/tole-desktop gets a supervisor module (macOS and Linux) with the pieces the lifecycle will use, each tested alone: the settings and the restart backoff, the choice of the tole binary (a configured path, the one next to the desktop, then PATH; never a relative path), the per-launch credential and its 0600 file, the probe of a socket (is a serve there, does its protocol match, does it accept the credential), the child process (the credential on an inherited pipe, never the arguments or the environment) and the few system calls (private directory check, flock, signals, the owner of a socket). tole-desktop now depends on tole-client, and on libc for these calls. Part of #1029.
token::read checked the path with symlink_metadata and opened the file afterwards, so a swap in between could put another file under the checks. It now opens first (O_NOFOLLOW, so a link is refused by the open itself, and O_NONBLOCK, so a named pipe does not wait for a writer) and checks the descriptor with fstat: type, owner, mode and size. A test refuses a pipe, a directory and a link to nothing without waiting.
The macOS build of the desktop lints tole-client once tole-desktop depends on it, and clippy's large_enum_variant flags StreamItem::Event (240 bytes there). Boxing it would stop callers matching StreamItem::Event(Event::Entry(e)) in one pattern, so the lint is allowed with the reason beside it. 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 building blocks of the local
tole servesupervisor of the desktop, each tested alone: the settings and restart backoff, whichtolebinary to run, the per-launch credential and its private file, the probe of the socket, the child process, and the few system calls. No window uses them and nothing starts a serve yet; the next changes of this series put the lifecycle on top.Why
Part of #1029 (owner decisions D3, D4 and D8, and the answers of 2026-11-21 recorded below). The desktop is a thin client of a local
tole serveover a private Unix socket, and it must start that serve, attach to one that already runs, and never leave the credential where another user or a process listing could read it.tole-desktopnow depends ontole-client(allowed by the guardrail change #1083) and onlibcforflock,killand the peer credentials of a socket, which std does not expose.libcis already in the tree throughtole-core,tole-cliandtole-client, soCargo.lockgains two dependency lines and no package. Size: about 1,340 changed lines in 11 files, of which about 470 are tests; above the 1,000-line ideal and below the 1,500 ceiling, and split from the lifecycle for that reason.Changes
supervisor/config.rs:Config(one workspace and one runtime directory; the scheduler is off unless asked),CloseBehavior(leave the serve running when the window closes, which is the default, or stop it) andBackoff(1 s doubling to 30 s, give up after 6 starts that did not hold, a 60 s steady run resets the count).supervisor/binary.rs: the binary is a configured path, else the one next to the desktop binary, else the first onPATH; always an absolute path to an executable file, never relative to the working directory, and a configured path that does not work is an error, not a reason to try another.supervisor/token.rs: a fresh random token per launch (32 bytes, hex), kept in a0600file in the private directory so a second desktop process can attach, written as a new file and renamed over the old one, removed when the serve is stopped from the desktop. Reading it opens the file withO_NOFOLLOW | O_NONBLOCKand judges the descriptor withfstat(a regular file, the owner's, no group or other bits, under 256 bytes, printable ASCII), so what is checked is what is read and a named pipe cannot hang the read.Tokenprints<redacted>inDebug.supervisor/process.rs:tole serve --socket <path> --token-fd 0 --workspace <folder>, with the token written into a pipe whose read end is the child's standard input: it is in no argument and no environment (TOLE_SERVE_TOKENis also removed from the child's environment). The child has its own process group, so a Ctrl-C in the terminal that started the desktop, or the desktop's exit, does not stop it. The last 20 lines of its standard error are kept (a line is cut at 512 bytes) and are the only thing shown when a start fails.supervisor/probe.rs: what answers on the socket (nothing, not a tole serve, a serve of this protocol, of another one) and whether a token is accepted, throughtole-client;EXPECTED_PROTOCOL = 1.supervisor/sys.rs: the private runtime directory (created0700, refused if it is not the owner's or is a link), the launch lock and the serve's lock (flock),terminateandkill, the pid of a socket's owner (SO_PEERCREDon Linux,LOCAL_PEERPIDon macOS), and random bytes.cfg(unix); there is no Windows stub yet (the named pipe is feat(serve): Windows named pipe transport for the local desktop #1051).tole-client/src/resume.rs:#[allow(clippy::large_enum_variant)]onStreamItem, with the reason beside it. Oncetole-desktopdepends ontole-client, the macOS window build lints it, andEventis 240 bytes there; the first run of this PR failed on it. It is not boxed because aBoxwould stop callers matchingStreamItem::Event(Event::Entry(e))in one pattern, and the value is moved once per frame.Cargo.tomlandCargo.lockas above, andCHANGELOG.md.Owner decisions on #1029 that this follows (2026-11-21): a copy of the per-launch token may be kept in
<runtime dir>/tokenso a second desktop process can attach; closing the window leaves the serve running; the cron scheduler is off by default; the restart numbers above; the OS keychain is deferred (there is aCredentialStoretrait in the model and no implementation).Callers checked with grep: everything in
supervisor/is new and has no caller outside the module (the lifecycle comes next). The one change to existing code istole-desktop'sCargo.toml(the dependency ontole-client, andlibcfor unix),lib.rs(thecfg(unix)module) and the lint attribute onStreamItem(no caller is affected).scripts/desktop-check.sh depsaccepts the graph under the rule of #1083:tole-coreis in the closure only throughtole-client, andtole-cliandtole-tuinowhere.Testing
cargo test -p tole-desktop -p tole-desktop-model: 26 and 44 tests pass; the supervisor tests include a stand-intolethat shows the token arrives on standard input and in no argument or environment, the credential file's checks (modes, size, a link, a link to nothing, a directory and a named pipe, the last without waiting), and the binary choice.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-client --all-targets -- -D warnings: pass.bash scripts/test-desktop-check.sh(all cases) andbash scripts/desktop-check.sh all: pass.cargo check -p tole-desktop --features gpui: pass.cora review --no-llm --base origin/developaftercora index: no issues.scripts/review-local.shnot run (no LLM key); the CI Cora Review is the gate.LOCAL_PEERPIDlookup compiles only behindcfg(target_os = "macos")and was never built or run here, and theStreamItemlint was only seen in the macOS CI job; the Desktop macOS build on the current head is the check), Windows (the supervisor is not compiled there), the tests as an unprivileged user, and the swap between check and open of the credential file, which the descriptor-based check closes by construction but a test cannot race deterministically. Not run: a fullcargo test --workspace.Part of #1029.