Skip to content

feat(desktop): add the building blocks of the local serve supervisor - #1096

Merged
ajianaz merged 3 commits into
developfrom
feat/desktop-supervisor-blocks
Nov 21, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/desktop-supervisor-blocks

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What

The building blocks of the local tole serve supervisor of the desktop, each tested alone: the settings and restart backoff, which tole binary 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 serve over 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-desktop now depends on tole-client (allowed by the guardrail change #1083) and on libc for flock, kill and the peer credentials of a socket, which std does not expose. libc is already in the tree through tole-core, tole-cli and tole-client, so Cargo.lock gains 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) and Backoff (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 on PATH; 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 a 0600 file 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 with O_NOFOLLOW | O_NONBLOCK and judges the descriptor with fstat (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. Token prints <redacted> in Debug.
  • 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_TOKEN is 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, through tole-client; EXPECTED_PROTOCOL = 1.
  • supervisor/sys.rs: the private runtime directory (created 0700, refused if it is not the owner's or is a link), the launch lock and the serve's lock (flock), terminate and kill, the pid of a socket's owner (SO_PEERCRED on Linux, LOCAL_PEERPID on macOS), and random bytes.
  • The supervisor is 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)] on StreamItem, with the reason beside it. Once tole-desktop depends on tole-client, the macOS window build lints it, and Event is 240 bytes there; the first run of this PR failed on it. It is not boxed because a Box would stop callers matching StreamItem::Event(Event::Entry(e)) in one pattern, and the value is moved once per frame.
  • Cargo.toml and Cargo.lock as above, and CHANGELOG.md.

Owner decisions on #1029 that this follows (2026-11-21): a copy of the per-launch token may be kept in <runtime dir>/token so 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 a CredentialStore trait 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 is tole-desktop's Cargo.toml (the dependency on tole-client, and libc for unix), lib.rs (the cfg(unix) module) and the lint attribute on StreamItem (no caller is affected). scripts/desktop-check.sh deps accepts the graph under the rule of #1083: tole-core is in the closure only through tole-client, and tole-cli and tole-tui nowhere.

Testing

  • cargo test -p tole-desktop -p tole-desktop-model: 26 and 44 tests pass; the supervisor tests include a stand-in tole that 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) and bash scripts/desktop-check.sh all: pass. cargo check -p tole-desktop --features gpui: pass.
  • cora review --no-llm --base origin/develop after cora index: no issues. scripts/review-local.sh not run (no LLM key); the CI Cora Review is the gate.
  • Not verified locally: macOS (the LOCAL_PEERPID lookup compiles only behind cfg(target_os = "macos") and was never built or run here, and the StreamItem lint 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 full cargo test --workspace.

Part of #1029.

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.
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

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