Skip to content

feat(cli): commonly daemon run — the resident supervision loop (ADR-026 Phase 2, slice 2) - #1563

Merged
lilyshen0722 merged 2 commits into
mainfrom
feat/daemon-run-supervisor
Sep 6, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
feat/daemon-run-supervisor

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

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 run polls GET /api/agent-binding/assigned and reconciles:

  • requested → POST /adopt (the D3 CAS; a lost race logs and drops — the other machine won cleanly)
  • bound → ensure ~/.commonly/tokens/<name>.json exists: mint via POST /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 ordinary commonly agent run <name> as a supervised child logging to ~/.commonly/logs/daemon/<name>.log. The daemon is agent run's supervisor, never its replacement.
  • gone from the list → SIGTERM the child, report 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 exit event — a tick during a running child or during backoff spawns nothing (both pinned by tests). Crash respawn backs off 5s→60s. token_exists on mint is answered with an explicit rotate:true and 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), and commonly daemon install (launchd/systemd registration, D1's install-once).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EtwYLMJAYuZ3grLQoXWMWT

…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
@lilyshen0722
lilyshen0722 merged commit 15d980a into main Sep 6, 2026
13 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/daemon-run-supervisor branch September 6, 2026 03:02
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