Skip to content

feat(daemon): Phase 2 work surface — placement requests, work list, runtime mint, agent-state heartbeats - #1562

Merged
lilyshen0722 merged 2 commits into
mainfrom
feat/daemon-phase2-work-surface
Sep 6, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
feat/daemon-phase2-work-surface

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

ADR-026 Phase 2, slice 1 — the server-side surface a resident daemon needs before commonly daemon run (slice 2, next PR) can exist. All driver-layer; no kernel change.

What changed

Placement request — POST /api/agent-binding/request (owner JWT). The UI's "run it on <machine>" choice, stored as a directive (botMetadata.requestedMachineId), never a binding. D3 holds: the adopt CAS remains the only binding writer, a successful adopt consumes the request, release withdraws it. Ownership is the same sole-installer predicate as adopt; the target machine must be owned by the caller; a bound-elsewhere identity 409s with boundTo.

Daemon work list — GET /api/agent-binding/assigned (daemon token, agents:adopt scope). Identities bound to or requested onto THIS machine (credential-derived machineId, never caller input), intersected with the owner's active installation set — an identity outside it never appears. Each row carries state: bound|requested, podIds, and the installation's config.runtime so the daemon can provision (model pin included) without another read.

Runtime credential mint — POST /api/agent-binding/runtime-token (daemon token). Requires the D3 binding to this machine; mints the cm_agent_* token as a child of the machine's daemon credential (D4.5 lineage — machine removal already cascade-revokes descendants). An existing token 409s token_exists unless rotate:true; rotation is total — ledger row revoked AND both legacy stores cleared (User.agentRuntimeTokens + installation runtimeTokens copies), otherwise the old bearer would keep working through the legacy auth fallback. req.machine stays the minimal S1 projection; the parent credential is re-derived server-side.

Agent-state heartbeats (D5) — POST /api/machines/:id/heartbeat now accepts agents: [{agentName, instanceId, state: running|stopped|crashed, restarts}], validated and capped in the service, replaced wholesale per report. An absent array preserves the last report (a Phase-1 daemon keeps working); an explicit empty array is itself a report. States serialize on every machine view, so the UI can render "nothing is running gavin-codex" truthfully.

Verification

31 tests green across the four daemon suites: 13 new (placement directive semantics, work-list machine+owner scoping, mint lineage/rotation totality/wrong-machine refusal, heartbeat state normalization + preserve-vs-clear), plus the existing adoption CAS suite untouched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EtwYLMJAYuZ3grLQoXWMWT

…untime mint, agent-state heartbeats

ADR-026 Phase 2, slice 1 (server side). Four additions, all driver-layer:

- POST /api/agent-binding/request (owner JWT): the UI's "run it on <machine>"
  choice, stored as a DIRECTIVE (botMetadata.requestedMachineId) — never a
  binding. The adopt CAS remains the only binding writer; a successful adopt
  consumes the request, and release withdraws it.
- GET /api/agent-binding/assigned (daemon token): the daemon's work list —
  identities bound to or requested onto THIS machine (credential-derived
  machineId), scoped by the owner's active installation set, each row carrying
  its runtime config so the daemon can provision without another read.
- POST /api/agent-binding/runtime-token (daemon token): mints the cm_agent_*
  credential for an agent BOUND here, as a child of the machine's daemon
  credential (D4.5 lineage — machine removal cascade-revokes it). An existing
  token 409s unless rotate:true, and rotation is total: ledger row revoked plus
  both legacy stores cleared, or the old bearer survives via the auth fallback.
- Heartbeat now carries per-agent supervisor state (D5): running|stopped|
  crashed + restarts, replaced wholesale per report; an absent array preserves
  the last report so Phase-1 daemons keep working.

Tests: 13 new (route + service tiers), all four daemon suites green.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EtwYLMJAYuZ3grLQoXWMWT
@lilyshen0722
lilyshen0722 merged commit 950cb57 into main Sep 6, 2026
14 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/daemon-phase2-work-surface branch September 6, 2026 02:50
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