Repository navigation
feat(cli): commonly daemon run — the resident supervision loop (ADR-026 Phase 2, slice 2) - #1563
Merged
Merged
Conversation
…26 Phase 2, slice 2) The server work list (agent-binding/assigned) is the source of truth: a requested row is adopted through the D3 CAS (a lost race is dropped cleanly), a bound row is provisioned (runtime token minted with daemon lineage, written to ~/.commonly/tokens/<name>.json so the ordinary `agent run` boots) and supervised as a child process, and a row that leaves the list is stopped. Per-agent running|stopped|crashed + restart counts ride every machine heartbeat (D5). D6 discipline: a replacement child is only ever scheduled from the previous child's exit event — no code path can produce two runners for one agent. Crash respawn backs off 5s→60s. token_exists is answered with an explicit, logged rotate (the binding to this machine is the owner's takeover choice), never silently. All side effects (client, spawn, token I/O, adapter detection, timers) are injected; 8 new supervisor tests cover adopt/mint/rotate, the lost race, de-assignment stop, double-spawn prevention, backoff, and heartbeat shape. cli 0.1.31 → 0.1.32. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EtwYLMJAYuZ3grLQoXWMWT
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.
Companion to #1562 (merge that first — this loop consumes its three endpoints). Together they close ADR-026 Phase 2's adopt+spawn slice: after
commonly daemon register+commonly daemon run, creating an agent in the web UI and pointing it at this machine is sufficient — the daemon notices, adopts, provisions, and keeps it running. No terminal per agent, ever again (D1/D2).What it does
commonly daemon runpollsGET /api/agent-binding/assignedand reconciles:POST /adopt(the D3 CAS; a lost race logs and drops — the other machine won cleanly)~/.commonly/tokens/<name>.jsonexists: mint viaPOST /runtime-token(daemon-lineage credential), resolve the adapter for THIS machine (server preference honored when installed, else probe claude/codex), write the record — then spawn the ordinarycommonly agent run <name>as a supervised child logging to~/.commonly/logs/daemon/<name>.log. The daemon isagent run's supervisor, never its replacement.stopped.Heartbeats now carry
agents: [{agentName, instanceId, state, restarts}](D5), so the server renders truthful per-agent liveness.D6: a replacement child is scheduled exclusively from the previous child's
exitevent — a tick during a running child or during backoff spawns nothing (both pinned by tests). Crash respawn backs off 5s→60s.token_existson mint is answered with an explicitrotate:trueand a loud log line: binding to this machine was the owner's takeover choice, and the old token stops working by design.Verification
30 CLI suites green (420 tests, 8 new): adopt→mint→record→spawn, existing-token skip, rotate-on-conflict, lost-race drop, de-assignment stop, double-spawn prevention across ticks and backoff, clean-exit/stop() semantics, heartbeat payload shape. CLI lint green. cli 0.1.31 → 0.1.32.
Remaining Phase 2 residue (next, separate PRs): the UI machine picker wired to
POST /api/agent-binding/request(the "Add a computer" where-step), andcommonly daemon install(launchd/systemd registration, D1's install-once).🤖 Generated with Claude Code
https://claude.ai/code/session_01EtwYLMJAYuZ3grLQoXWMWT