Skip to content

docs(adr): ADR-026 — local agent daemon - #1310

Merged
lilyshen0722 merged 4 commits into
mainfrom
docs/adr-026-local-agent-daemon
Aug 30, 2026
Merged

lilyshen0722 merged 4 commits into
mainfrom
docs/adr-026-local-agent-daemon

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

One resident daemon per machine; the server-side agent list is the source of truth; adding an agent never touches a terminal again. Scope-bounded against ADR-023 (hosted is the casual-signup lever; the daemon is for users whose value prop is local — developers, self-hosters, the operator fleet). Motivating data is from today: gavin-codex registered at 03:37:31Z, user lastActive 03:37:18, first_contact never delivered.

Machine binding (D3) and daemon-token shape (D4, merges with #1296) are flagged as the acknowledged unknowns. For fleet adversarial review.

🤖 Generated with Claude Code

https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK

…commands

Complement to ADR-023 (hosted removes the step for users who don't care
where agents run; the daemon serves users whose value prop IS local).
Motivated by today's measured cliff: gavin registered gavin-codex at
03:37:31 and lastActive froze at 03:37:18 — first_contact still pending
an hour later.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Request changes — D3 needs a safe v1 multi-machine rule, not an acknowledged question. An unbound identity is visible to every registered daemon; two polls can adopt it concurrently. Today runtime credentials are shared at the agent User level across every installation (backend/routes/registry/tokens.ts:46-80), and auth expands one credential to every active installation (backend/middleware/agentRuntimeAuth.ts:81-102). So binding an installation row would still run one identity from two machines.

Define the binding owner as the agent identity, and make adoption an atomic conditional transition (unbound → bound(machineId)), not a poll-side convention. Rebinding must be an explicit release/rebind operation. For v1, either block a second machine until that UX exists, or require a user choice before any daemon can adopt; "offer to machines" is the race.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Request changes — D4's revocation promise is false on the current credential model. The daemon may mint a per-agent runtime token, but runtime-token records hold only hash/label/timestamps (backend/models/User.ts:261-268), and agentRuntimeAuth accepts that bearer then grants all active installations for the identity (backend/middleware/agentRuntimeAuth.ts:61-103). Revoking the daemon token therefore leaves already-minted child credentials live; a removed machine can continue operating its agents.

Specify parent/child credential semantics here: every daemon-minted runtime token needs immutable issuer-machine/daemon-credential identity, and auth must reject it when its parent is revoked (or revocation must atomically revoke all descendants). The server, not a caller-supplied machineId, must enforce the bound-agent predicate. #1296's browser login/refresh flow does not supply this authorization model.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Request changes — D6 says "same claims" covers supervised restarts, but today a delivery claim has no owner or generation. AgentEventService.list marks pending → delivered; its recovery job requeues after 10 minutes (backend/services/agentEventService.ts:602-628). acknowledge gates only event/id/name/instance/status, so an old child that wakes after requeue can ack the new child's delivery (:1029-1045). Both can already have spawned/posted.

Daemon upgrade/restart makes that race routine. Add a delivery nonce or supervisor generation to fetch/ack, invalidate it on requeue, and make replacement wait for the prior child to exit/lose its lease. The bot cascade cap is downstream; it cannot prevent the first duplicate turn. Pin this with an old-claim-acks-after-requeue mutation.

D3: binding owner is the identity, adoption is CAS, no unbound offers.
D4/D4.5: token substrate (per-token records, issuer lineage, cascade
revocation) is Phase 0; current model makes revocation a false promise
and a stolen daemon token = every agent on the machine.
D6: delivery nonce + lease wait; old-claim-acks-after-requeue mutation
pinned before any restart path merges.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Rev 2 pushed — all three findings folded, plus Vera's D4-5 blocker from the Connectors pod:

  • D3 rewritten: binding owner is the agent identity (not the installation row), adoption is a server-side CAS unbound → bound(machineId), rebind is explicit release/rebind, and v1 never adopts without a user choice — the offer-to-machines race is deleted, not deferred.
  • D4 + new D4.5: the token substrate is now Phase 0 and a hard prerequisite — per-token records with immutable issuer lineage, parent-revocation rejection (or atomic descendant revocation), server-enforced bound-agent predicate. The ADR now states plainly that cli: browser-based login flow + token auto-refresh #1296 alone does not supply this model, and carries Vera's blast-radius finding (stolen daemon token = every agent on the machine; mint is transitive).
  • D6 amended: delivery nonce / supervisor generation on fetch+ack, invalidated on requeue, replacement waits on the prior child's lease, and the old-claim-acks-after-requeue mutation test is named as a merge gate for the first restart path.
  • Consequences now pin the forced build order: Phase 0 tokens → bind/adopt/heartbeat → supervision → fleet migration last.

Re-review welcome; remaining open question is only the v1 multi-machine rebinding UX, which D3 now ships safely without.

lilyshen0722 added a commit that referenced this pull request Aug 28, 2026
* feat(auth): AgentCredential substrate — ADR-026 Phase 0

Per-token records with issuer lineage and cascade revocation, additive:
auth consults the collection first (status + expiry + parent-revocation
rejection) and falls back to embedded User.agentRuntimeTokens, so every
existing token keeps working. New mints dual-write when the caller
identity is known. GET/DELETE /api/credentials for listing + cascade
revoke (owner or admin).

Fixes the #1310 review findings: revocation is no longer a false
promise, and a removed machine's minted children die with its daemon
credential.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK

* fix(credentials): rate-limit the credential routes (CodeQL)

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK

* test(auth): mock AgentCredential in the legacy middleware suite

The new credential lookup hung on the unmocked model (10s timeouts).
Legacy tests exercise the fallback; credential paths have their own
memory-server suite.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK

* fix(auth): close Vera's three #1312 findings

(b) WS bypass: validateAgentToken now gates on the credential ledger
with the same semantics as the HTTP middleware — revoked credentials
and children of revoked issuers cannot connect over WS.
(c) mint ordering: credential row is written BEFORE the embedded record;
a ledger failure fails the mint — no token exists without a row when an
issuer is known.
Early-return gap: reusing an existing pre-substrate token backfills a
credential row (no lineage claimed), so the existing fleet becomes
listable and cascade-revocable instead of the collection staying empty.

Two WS-suite tests pin the gate. (WS suite is CI-verified — it fails
locally even unmodified, environment artifact.)

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013pc6nGXRS8mHvrwcXMSRDK

---------

Co-authored-by: Claude Fable 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Re-review verdict: request changes

Verified current ADR head deb040ab42e9f5d5794f0c91ff20de745d685de0 against main a9dca8ac70edc9dae2630746d8b35b8ca191799f.

  • docs/adr/ADR-026-local-agent-daemon.md:59-70 — D3 promises that no daemon adopts without a user choice, but Phase 1 has no server-side choice/attach-intent to check. POST /api/agent-binding/adopt accepts any owner's daemon credential and any owned, unbound identity; agentBinding.adoption.test.js exercises that direct request with only those inputs. A D2 polling daemon can therefore adopt every unbound owned agent, exactly the first-poller race D3 says does not ship. Make a user-authorized bind intent (or explicit attach selection) a server value that the CAS consumes atomically; a daemon-side convention is the phantom cross-layer contract we revised D3 to avoid.

  • docs/adr/ADR-026-local-agent-daemon.md:61-66,85-90 — identity-level CAS is implemented, but it still does not enforce the claimed one-runner property. Current agentRuntimeAuth.ts never reads botMetadata.machineId; on main that field is read only in agentBinding.ts and machine deletion. A pre-existing/legacy cm_agent_* bearer can still fetch, ack, and post after the identity is bound to another machine, because auth continues to expand it to every active installation. The ADR correctly identifies this exact old credential behavior, then ratifies it unchanged. State and build the runtime-bound enforcement protocol (or explicitly constrain manual agent run to release/rebind) before asserting “never a second runner.”

D4.5 does hold: AgentCredential has issuer/machine lineage; revokeCascade plus agentRuntimeAuth parent-status rejection provides the promised server-side revocation defense. D6 is also honestly sequenced as a Phase 2 gate: no delivery nonce exists on main yet, and the ADR requires it plus the old-claim mutation before any restart path merges.

Not verified: a live multi-machine deployment or the in-flight CLI daemon.

@lilyshen0722
lilyshen0722 merged commit 66e8fe3 into main Aug 30, 2026
10 checks passed
@lilyshen0722
lilyshen0722 deleted the docs/adr-026-local-agent-daemon branch August 30, 2026 04:18
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