device-add: wire join.Orchestrator.Resume into the standing agent — a join whose terminal truly dies must be picked back up, not stranded #953

Closed
opened 2026-08-28 19:43:12 +00:00 by matou-build-agent · 2 comments

Split from #952 (the causative await-hardening landed there; this is the remaining defense-in-depth).

The gap

join.Orchestrator.Resume (internal/join/resume.go) was written for exactly this — "a crash or reboot mid-join must never … strand the device" (#68) — but has no production caller: grep -rn '\.Resume(' --include=*.go outside _test.go hits founding, clan, backup, monitor and never internal/join. The standing idss-agent.service (join socket listening) does nothing when the foreground install/enroll terminal that owns a Pending join goes away (a real crash, reboot, or lost SSH). So once the terminal is gone, an operator's approval is stranded permanently: the grant is minted, the code is spent, and the strip sits at approved-joining forever with no path to Enrolled and no error.

#952 hardened AwaitDecision so a transient poll blip no longer ends the join (the proximate cause of drive 20260828T185311Z). This ticket closes the other half: when the terminal genuinely dies, nothing resumes.

The main.go comments already PROMISE this behaviour — runEnroll/runInstall say SIGINT "leaves the request Pending for the standing agent join service to resume (ADR 0209)" — but that service/loop does not exist. The promise is currently false.

Why it's blocked on a ruling

Resume(code) needs the code (and the request id) after the foreground process is gone. Deciding what the agent persists about an in-flight request, and where is the ruling this needs (ADR 0209 territory).

Proposed default ruling (adoptable by a session under ADR 0174 — revertible + provable offline)

  1. The agent persists a minimal durable resume anchor — {code, requestID} — to a root-owned file under the agent's existing durable state home (beside the device key / SSH host key that deviceKey() / sshHostKey() already persist), mode 0600, written the moment Pair reaches Pending, and cleared at any terminal outcome (Enrolled, Declined, or a teardown).
  2. The standing idss-agent.service runs a resume loop at startup: if the anchor exists, call Orchestrator.Resume(code) and continue the same AwaitAndLand walk the foreground terminal would have — so a join whose terminal died is picked back up by the standing agent, landed or torn down, never stranded.
  3. Fail-loud preserved (ADR 0100): a code that no longer rejoins anything (revoked/another device's) is a typed error the resume surfaces, not a silent spin.

Proof (offline seam): persist the anchor → drop the orchestrator → a fresh orchestrator resumes from the file and lands a since-approved request; and assert the anchor is gone after a terminal outcome. No live drive needed to prove the mechanism.

Rejected alternatives to name in the ruling

  • Persisting nothing and re-deriving from the operator's dashboard (the device end is the only holder of its own code; the dashboard cannot hand it back).
  • A second request on restart (breaks the (code, KeyID) idempotency anchor #68 exists to protect).

Refs: ADR 0209 (device-add landing goes live), ADR 0100 (fail-loud), #68 (crash-safe resume), #952 (the transient-blip half, landed).

Split from #952 (the causative await-hardening landed there; this is the remaining defense-in-depth). ## The gap `join.Orchestrator.Resume` (`internal/join/resume.go`) was written for exactly this — "a crash or reboot mid-join must never … strand the device" (#68) — but has **no production caller**: `grep -rn '\.Resume(' --include=*.go` outside `_test.go` hits `founding`, `clan`, `backup`, `monitor` and never `internal/join`. The standing `idss-agent.service` (`join socket listening`) does nothing when the foreground `install`/`enroll` terminal that owns a Pending join goes away (a real crash, reboot, or lost SSH). So once the terminal is gone, an operator's approval is stranded permanently: the grant is minted, the code is spent, and the strip sits at `approved-joining` forever with no path to `Enrolled` and no error. #952 hardened `AwaitDecision` so a *transient poll blip* no longer ends the join (the proximate cause of drive `20260828T185311Z`). This ticket closes the *other* half: when the terminal genuinely dies, nothing resumes. The main.go comments already PROMISE this behaviour — `runEnroll`/`runInstall` say SIGINT "leaves the request Pending for the standing `agent join` service to resume (ADR 0209)" — but that service/loop does not exist. The promise is currently false. ## Why it's blocked on a ruling `Resume(code)` needs the code (and the request id) after the foreground process is gone. Deciding **what the agent persists about an in-flight request, and where** is the ruling this needs (ADR 0209 territory). ## Proposed default ruling (adoptable by a session under ADR 0174 — revertible + provable offline) 1. The agent persists a minimal durable **resume anchor** — `{code, requestID}` — to a root-owned file under the agent's existing durable state home (beside the device key / SSH host key that `deviceKey()` / `sshHostKey()` already persist), mode 0600, written the moment Pair reaches Pending, and **cleared at any terminal outcome** (Enrolled, Declined, or a teardown). 2. The standing `idss-agent.service` runs a **resume loop at startup**: if the anchor exists, call `Orchestrator.Resume(code)` and continue the same `AwaitAndLand` walk the foreground terminal would have — so a join whose terminal died is picked back up by the standing agent, landed or torn down, never stranded. 3. Fail-loud preserved (ADR 0100): a code that no longer rejoins anything (revoked/another device's) is a typed error the resume surfaces, not a silent spin. Proof (offline seam): persist the anchor → drop the orchestrator → a fresh orchestrator resumes from the file and lands a since-approved request; and assert the anchor is gone after a terminal outcome. No live drive needed to prove the mechanism. ## Rejected alternatives to name in the ruling - Persisting nothing and re-deriving from the operator's dashboard (the device end is the only holder of its own code; the dashboard cannot hand it back). - A second request on restart (breaks the (code, KeyID) idempotency anchor #68 exists to protect). Refs: ADR 0209 (device-add landing goes live), ADR 0100 (fail-loud), #68 (crash-safe resume), #952 (the transient-blip half, landed).
Author
Member

Ruled by agent under ADR 0174 — veto anytime.

Adopting the ticket's proposed default ruling verbatim (ADR 0209 territory), which qualifies under ADR 0174 rule 1: it is (a) revertible — a commit adding a durable-state file + wiring, nothing widened; (b) provable offline — a join-seam test persists an anchor, drops the orchestrator, and a fresh orchestrator resumes from the file and lands a since-approved request, plus asserts the anchor is gone after any terminal outcome; (c) not on the one-way-door list — the {code, requestID} anchor lives in the SAME root-owned durable-state home (0600) the device key and SSH host key already occupy (deviceKey()/sshHostKey()), same trust domain, no new surface, no auth loosened, no data destroyed.

The ruling (DDR-shaped, under ADR 0209):

  1. The agent persists a minimal durable resume anchor — {code, requestID} — beside the device key, mode 0600, written the moment Pair reaches Pending (Consent), and cleared at any terminal outcome (Enrolled via Enroll, or a teardown via tearDown — Declined/Expired/Revoked).
  2. The standing agent join service runs a resume check at startup: if the anchor exists, it calls Orchestrator.Resume(code) and continues the same await-and-land walk the foreground terminal would have — so a join whose terminal died is picked back up, landed or torn down, never stranded.
  3. Fail-loud preserved (ADR 0100): a code that no longer rejoins anything is the typed error Resume already surfaces, logged, never a silent spin.

Rejected alternatives (as the ticket names them): re-deriving from the dashboard (the device is the only holder of its own code); a second request on restart (breaks the (code, KeyID) idempotency anchor #68 protects).

Named residue (honest scope): the startup check covers crash + reboot definitively (a reboot restarts the service; a service crash is systemd-restarted). A lost-SSH-without-reboot death — where the foreground enroll dies but the already-running standing service does not restart — is only picked up at the next service restart. Widening to a continuous watch is deliberately out of scope here (it races the live foreground landing on the same request); filing a follow-up rather than expanding this two-way door.

**Ruled by agent under ADR 0174 — veto anytime.** Adopting the ticket's **proposed default ruling** verbatim (ADR 0209 territory), which qualifies under ADR 0174 rule 1: it is (a) **revertible** — a commit adding a durable-state file + wiring, nothing widened; (b) **provable offline** — a join-seam test persists an anchor, drops the orchestrator, and a fresh orchestrator resumes from the file and lands a since-approved request, plus asserts the anchor is gone after any terminal outcome; (c) **not on the one-way-door list** — the `{code, requestID}` anchor lives in the SAME root-owned durable-state home (0600) the device key and SSH host key already occupy (`deviceKey()`/`sshHostKey()`), same trust domain, no new surface, no auth loosened, no data destroyed. **The ruling (DDR-shaped, under ADR 0209):** 1. The agent persists a minimal durable **resume anchor** — `{code, requestID}` — beside the device key, mode 0600, written the moment Pair reaches Pending (`Consent`), and **cleared at any terminal outcome** (Enrolled via `Enroll`, or a teardown via `tearDown` — Declined/Expired/Revoked). 2. The standing `agent join` service runs a **resume check at startup**: if the anchor exists, it calls `Orchestrator.Resume(code)` and continues the same await-and-land walk the foreground terminal would have — so a join whose terminal died is picked back up, landed or torn down, never stranded. 3. Fail-loud preserved (ADR 0100): a code that no longer rejoins anything is the typed error `Resume` already surfaces, logged, never a silent spin. **Rejected alternatives** (as the ticket names them): re-deriving from the dashboard (the device is the only holder of its own code); a second request on restart (breaks the (code, KeyID) idempotency anchor #68 protects). **Named residue (honest scope):** the startup check covers crash + reboot definitively (a reboot restarts the service; a service crash is systemd-restarted). A *lost-SSH-without-reboot* death — where the foreground `enroll` dies but the already-running standing service does not restart — is only picked up at the next service restart. Widening to a continuous watch is deliberately out of scope here (it races the live foreground landing on the same request); filing a follow-up rather than expanding this two-way door.
Author
Member

Close report — landed & proven (ADR 0174)

What landed (commit 17ccb4c9, on origin/main):

  • internal/resumeanchor — a file-backed join.AnchorStore persisting the minimal durable resume anchor {code, requestID} to a 0600 file beside the device key (IDSS_RESUME_ANCHOR / /var/lib/idss/resume.json): atomic write (temp+rename), absent → ok:false, corrupt → a loud read error (never a silent "no join in flight", ADR 0100).
  • internal/join — Config.Anchor + the ResumeAnchor/AnchorStore types; saveAnchor the moment Pair reaches Pending (Consent, before the VM guest stands up), clearAnchor at any terminal outcome (Enroll on Enrolled, tearDown on Declined/Expired/Revoked). New Orchestrator.ResumeAndLand drives a resumed join to a terminal outcome via the shared land walk extracted from AwaitAndLand (lost approval → land now; still Pending → resume the same long-poll; already terminal → the teardown Resume already ran). A nil Anchor (app socket path, seam tests) is a no-op — only the standing agent wires the store.
  • agent/cmd/agent/main.go — resumeStrandedJoin runs at agent join startup: if the anchor holds an in-flight join it ResumeAndLands it in a goroutine (so a still-Pending long-poll never blocks the socket coming up), logging a landed join, a torn-down decline, or a fail-loud resume error (LOGGED, not fatal — the socket must still serve fresh joins). The anchor store is wired into runJoin/runEnroll/runInstall. The runEnroll/runInstall comments that promised "the standing agent join service to resume (ADR 0209)" are now true.

Proof — red-first, entirely offline (no live drive), exactly the seam the ticket specified:

  • internal/join/resume_anchor_test.go — TestAnchor_FileStore_DropAndResume: persist the anchor → drop the orchestrator → a fresh orchestrator resumes from the file store and lands a since-approved request to Enrolled; plus lost-approval, declined-while-down (teardown ran, ErrDeclined), still-Pending-waits-then-lands, and anchor gone after every terminal outcome.
  • internal/resumeanchor/resumeanchor_test.go — store round-trip, 0600, overwrite, idempotent Clear, corrupt-file rejection.
  • go build (+-tags dev) / go vet / full go test ./... — green.

Ruling: the ticket's proposed default, adopted under ADR 0174 (see the ruling comment above) — a two-way door: revertible, offline-provable, same trust domain as the device key, no surface widened, no auth loosened.

Named residue → follow-up #958: a lost-SSH death where the box stays up and the standing service never restarts is only resumed at the next service restart (a continuous watch races the live foreground landing on the same request — out of scope for this door). Crash + reboot are covered definitively.

Closing: work is done and proven. Advances #953.

## Close report — landed & proven (ADR 0174) **What landed** (commit `17ccb4c9`, on `origin/main`): - **`internal/resumeanchor`** — a file-backed `join.AnchorStore` persisting the minimal durable resume anchor `{code, requestID}` to a 0600 file beside the device key (`IDSS_RESUME_ANCHOR` / `/var/lib/idss/resume.json`): atomic write (temp+rename), absent → `ok:false`, corrupt → a loud read error (never a silent "no join in flight", ADR 0100). - **`internal/join`** — `Config.Anchor` + the `ResumeAnchor`/`AnchorStore` types; `saveAnchor` the moment `Pair` reaches Pending (`Consent`, before the VM guest stands up), `clearAnchor` at any terminal outcome (`Enroll` on Enrolled, `tearDown` on Declined/Expired/Revoked). New `Orchestrator.ResumeAndLand` drives a resumed join to a terminal outcome via the shared `land` walk extracted from `AwaitAndLand` (lost approval → land now; still Pending → resume the same long-poll; already terminal → the teardown `Resume` already ran). A nil `Anchor` (app socket path, seam tests) is a no-op — only the standing agent wires the store. - **`agent/cmd/agent/main.go`** — `resumeStrandedJoin` runs at `agent join` startup: if the anchor holds an in-flight join it `ResumeAndLand`s it **in a goroutine** (so a still-Pending long-poll never blocks the socket coming up), logging a landed join, a torn-down decline, or a fail-loud resume error (LOGGED, not fatal — the socket must still serve fresh joins). The anchor store is wired into `runJoin`/`runEnroll`/`runInstall`. The `runEnroll`/`runInstall` comments that promised "the standing `agent join` service to resume (ADR 0209)" are now true. **Proof** — red-first, entirely offline (no live drive), exactly the seam the ticket specified: - `internal/join/resume_anchor_test.go` — `TestAnchor_FileStore_DropAndResume`: persist the anchor → **drop the orchestrator** → a fresh orchestrator resumes **from the file store** and lands a since-approved request to Enrolled; plus lost-approval, declined-while-down (teardown ran, `ErrDeclined`), still-Pending-waits-then-lands, and **anchor gone after every terminal outcome**. - `internal/resumeanchor/resumeanchor_test.go` — store round-trip, **0600**, overwrite, idempotent Clear, corrupt-file rejection. - `go build` (+`-tags dev`) / `go vet` / full `go test ./...` — green. **Ruling:** the ticket's proposed default, adopted under ADR 0174 (see the ruling comment above) — a two-way door: revertible, offline-provable, same trust domain as the device key, no surface widened, no auth loosened. **Named residue → follow-up #958:** a lost-SSH death where the box stays up and the standing service never restarts is only resumed at the next service restart (a continuous watch races the live foreground landing on the same request — out of scope for this door). Crash + reboot are covered definitively. Closing: work is done and proven. Advances #953.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#953
No description provided.