feat(cli): worker start -a|--attach — foreground view, detach with Ctrl-D - #12
Merged
Conversation
…rl-D Add attach mode: `c0mpute worker start -a` runs the worker as a background daemon and stays attached, streaming its log to the terminal. Press Ctrl-D (stdin EOF) or Ctrl-C to detach — the worker keeps running; stop it with `worker stop`. If a worker is already running, `-a` re-attaches to it instead of spawning a second one. Implemented as a supervisor + file tail that never builds the async runtime, so it hands off to the daemon and returns the shell cleanly. This is the tmux/docker-attach model: converting an already-running multi-threaded foreground process into a daemon in place isn't sound (fork after the Tokio runtime spawns threads is UB), so the worker is a standalone daemon the whole time and `-a` just attaches a viewer. `-a` conflicts with `-d`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ralyodio
added a commit
that referenced
this pull request
Jul 19, 2026
Adds background-worker lifecycle from #11 and #12: - worker start -d|--daemon detach and run as a daemon (PID file + log) - worker start -a|--attach stream the log, Ctrl-D/Ctrl-C to detach - worker stop / worker status now functional (were stubs) Ships the systemd user unit at scripts/systemd/c0mpute-worker.service. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Adds
c0mpute worker start -a|--attach: run the worker attached in the foreground watching its log, then press Ctrl-D (or Ctrl-C) to detach and leave it running in the background. Follow-up to #11 (the-ddaemon).The design decision (important)
The naive ask — "run in the foreground, then on Ctrl-D convert this process into a daemon" — isn't sound. Once
worker startis up, the Tokio runtime is multi-threaded with live libp2p sockets, andfork()on a multi-threaded process is UB (it copies only the calling thread, leaving a dead runtime + half-held locks). That's exactly why-ddaemonizes before the runtime starts.So
-auses the tmux /docker attachmodel: the worker is a standalone background daemon the whole time, and-aattaches a live log viewer to your terminal. Detaching (Ctrl-D / Ctrl-C) just stops the viewer — it never touches the worker. Same UX as asked, but robust: nothing is lost on detach, and there's never a duplicate or momentarily-forked worker.Behavior
worker start -a→ launches the daemon (via the existing-dpath, so the fork-before-runtime happens in that child), then streams the log.-are-attaches to it instead of spawning a second one.detached — worker still running (pid N).-aconflicts with-d(clap enforces).Testing (Linux, verified end-to-end)
-a;-a -derrors with a clap conflict.-aspawns a separate daemon and tails its log; SIGINT detaches the viewer, daemon keeps running;worker stopcleans up.-aprintsworker already running (pid N); attaching, no duplicate spawned.0x04detaches the viewer (worker still running (pid N)), viewer exits, daemon survives.cargo build(debug) andcargo build --releaseboth clean.🤖 Generated with Claude Code