self-hosted consent leg: terminal enroll redeem races the relay carrier's own backoff — no readiness handshake between /run/ourcloud/enroll-relay.sock's bind and the dial onto it #599

Closed
opened 2026-08-19 21:53:11 +00:00 by matou-build-agent · 3 comments

Failure

Drive 20260819T214706Z, leg consent, red: the terminal join exited 1 with:

enrollwire: POST http://enroll-relay/api/v1/enroll/redeem: Post "http://enroll-relay/api/v1/enroll/redeem": dial unix /run/ourcloud/enroll-relay.sock: connect: no such file or directory

This is the same error text #597 (95c428f) fixed once by making listenUnixSocket() (agent/cmd/agent/main.go:193-201) MkdirAll /run/ourcloud before the agent's first bind. That fix IS present and working here: droplet-journal.txt:1156 shows ourcloud-agent.service starting and main.go's own join socket listening log firing at 21:48:27.666Z, proving /run/ourcloud existed by then. #597's own STATUS.md entry named live-drive reconfirmation as an honest residual (get.idss.nz was unreachable at fix time) — this run is that reconfirmation, and it surfaces a different, deeper defect the directory fix didn't touch.

Root cause: an unsynchronized race between two independent retry loops

  1. The self-hosted relay's ssh -N -R forward (internal/fleetwire/relay.go:161-190 supervise()) only starts once the S7b screen begins polling (internal/founding/selfhostedcarrier.go:107 ensureRelay), and retries on a fixed 2s backoff (relay.go:165-168, RelayConfig.Backoff). droplet-journal.txt:1125 and :1146 show its first two -R bind attempts failing with unix_listener: cannot bind to path /run/ourcloud/enroll-relay.sock: No such file or directory at 21:48:24 and 21:48:26 — both before the directory existed (created at 27.666). Its third attempt wasn't due until ~21:48:28, and a fresh ssh TCP handshake + auth + bind over a real DigitalOcean droplet easily costs several hundred ms.
  2. The terminal ourcloud-agent enroll <code> command (app/tests/e2e/journey.selfhosted.spec.ts:263-288, invoked immediately after the agent-install leg's systemctl is-active check passes — i.e. essentially the same instant /run/ourcloud first appears) calls Redeem → internal/enrollwire/client.go:53-57, which is a single-shot HTTP POST via client.go:94-121 do() with no retry and no backoff at all.

At 21:48:28.504Z the terminal's one-shot redeem dialed the box socket before the relay's own backoff-delayed reconnect had finished re-binding it, hit ENOENT once, and the whole agent enroll process exited 1 — no second chance, per agent/cmd/agent/main.go:155-165.

Suspected layer / what plugging it needs

This is a design decision, not a mechanical patch — candidates a swarm worker should weigh:

  • Give the terminal's redeem step its own short retry/backoff against exactly this dial-ENOENT condition (in runEnroll/RunTerminal or a wrapper around the first Redeem call), bounded well inside CEILING.consent (app/tests/e2e/journey.selfhosted.spec.ts:60, which has ample headroom for a few seconds of retry).
  • Or have the relay carrier signal readiness (forward actually bound) that the box side can poll/wait on before invoking agent enroll — but the box-side terminal join is device-driven and has no channel back to the app-side carrier today (ADR 0181's whole point is the box has no control plane yet).
  • A blanket retry inside internal/enrollwire/client.go's generic do() would affect every Redeem/Pair/Poll/ConfirmEnrolled caller, not just this self-hosted relay path — probably too broad; the fix likely belongs closer to the self-hosted terminal join call site.

Not self-fixed: this needs a retry/backoff policy decision spanning agent/cmd/agent, internal/enrollwire, and/or internal/fleetwire/internal/founding, and the same error signature already resisted one prior fix attempt (#597) — reappearing on exactly the reconfirmation drive that fix called for.

drive 20260819T214706Z red at consent: the terminal join exited N --- transcript --- Warning: Permanently added 'N.N.N.N' (EDN) to the list of known hosts. time=N-N-NTN:N:N.NZ level=ERROR msg="enroll did not reach Pending" component=agent err="enrollwire: POST http://enroll-relay/api/vN/enroll/redeem: Post \"http://enroll-relay/api/vN/enroll/redeem\": di Connection to N.N.N.N closed.
evidence: test-results/…/20260819T214706Z/ on matou-workstation (legs.json, droplet-journal.txt, trace)

## Failure Drive `20260819T214706Z`, leg `consent`, red: `the terminal join exited 1` with: ``` enrollwire: POST http://enroll-relay/api/v1/enroll/redeem: Post "http://enroll-relay/api/v1/enroll/redeem": dial unix /run/ourcloud/enroll-relay.sock: connect: no such file or directory ``` This is the same error text #597 (`95c428f`) fixed once by making `listenUnixSocket()` (`agent/cmd/agent/main.go:193-201`) `MkdirAll` `/run/ourcloud` before the agent's first bind. That fix IS present and working here: `droplet-journal.txt:1156` shows `ourcloud-agent.service` starting and `main.go`'s own `join socket listening` log firing at `21:48:27.666Z`, proving `/run/ourcloud` existed by then. #597's own STATUS.md entry named live-drive reconfirmation as an honest residual (`get.idss.nz` was unreachable at fix time) — this run is that reconfirmation, and it surfaces a **different, deeper** defect the directory fix didn't touch. ## Root cause: an unsynchronized race between two independent retry loops 1. The self-hosted relay's `ssh -N -R` forward (`internal/fleetwire/relay.go:161-190` `supervise()`) only starts once the S7b screen begins polling (`internal/founding/selfhostedcarrier.go:107` `ensureRelay`), and retries on a fixed **2s backoff** (`relay.go:165-168`, `RelayConfig.Backoff`). `droplet-journal.txt:1125` and `:1146` show its first two `-R` bind attempts failing with `unix_listener: cannot bind to path /run/ourcloud/enroll-relay.sock: No such file or directory` at `21:48:24` and `21:48:26` — both before the directory existed (created at `27.666`). Its third attempt wasn't due until `~21:48:28`, and a fresh `ssh` TCP handshake + auth + bind over a real DigitalOcean droplet easily costs several hundred ms. 2. The terminal `ourcloud-agent enroll <code>` command (`app/tests/e2e/journey.selfhosted.spec.ts:263-288`, invoked immediately after the agent-install leg's `systemctl is-active` check passes — i.e. essentially the same instant `/run/ourcloud` first appears) calls `Redeem` → `internal/enrollwire/client.go:53-57`, which is a **single-shot HTTP POST** via `client.go:94-121` `do()` with **no retry and no backoff at all**. At `21:48:28.504Z` the terminal's one-shot redeem dialed the box socket before the relay's own backoff-delayed reconnect had finished re-binding it, hit `ENOENT` once, and the whole `agent enroll` process exited 1 — no second chance, per `agent/cmd/agent/main.go:155-165`. ## Suspected layer / what plugging it needs This is a design decision, not a mechanical patch — candidates a swarm worker should weigh: - Give the terminal's redeem step its own short retry/backoff against exactly this dial-`ENOENT` condition (in `runEnroll`/`RunTerminal` or a wrapper around the first `Redeem` call), bounded well inside `CEILING.consent` (`app/tests/e2e/journey.selfhosted.spec.ts:60`, which has ample headroom for a few seconds of retry). - Or have the relay carrier signal readiness (forward actually bound) that the box side can poll/wait on before invoking `agent enroll` — but the box-side terminal join is device-driven and has no channel back to the app-side carrier today (ADR 0181's whole point is the box has no control plane yet). - A blanket retry inside `internal/enrollwire/client.go`'s generic `do()` would affect every `Redeem`/`Pair`/`Poll`/`ConfirmEnrolled` caller, not just this self-hosted relay path — probably too broad; the fix likely belongs closer to the self-hosted terminal join call site. Not self-fixed: this needs a retry/backoff policy decision spanning `agent/cmd/agent`, `internal/enrollwire`, and/or `internal/fleetwire`/`internal/founding`, and the same error signature already resisted one prior fix attempt (#597) — reappearing on exactly the reconfirmation drive that fix called for. drive `20260819T214706Z` red at `consent`: `the terminal join exited N --- transcript --- Warning: Permanently added 'N.N.N.N' (EDN) to the list of known hosts. time=N-N-NTN:N:N.NZ level=ERROR msg="enroll did not reach Pending" component=agent err="enrollwire: POST http://enroll-relay/api/vN/enroll/redeem: Post \"http://enroll-relay/api/vN/enroll/redeem\": di Connection to N.N.N.N closed. ` evidence: `test-results/…/20260819T214706Z/` on matou-workstation (legs.json, droplet-journal.txt, trace) <!-- rehearsal-sig: 28ff46f6d26f -->
Author
Member

swarm-claim host=matou-dev-server-01 run=7834
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=7834 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #599 — status success

⛔ close-report gates REFUSED this close — the following claims did not verify:

  • commit ec89a8ca is not a valid commit object (fabricated, or never pushed)
  • changed_files: 'STATUS.md' is not in the diff of the claimed commits
  • changed_files: 'agent/cmd/agent/wiring_prod.go' is not in the diff of the claimed commits
  • changed_files: 'agent/cmd/agent/wiring_test.go' is not in the diff of the claimed commits
envelope
{
  "issue": 599,
  "status": "success",
  "commits": [
    "ec89a8ca"
  ],
  "changed_files": [
    "STATUS.md",
    "agent/cmd/agent/wiring_prod.go",
    "agent/cmd/agent/wiring_test.go"
  ],
  "tests": [
    {
      "command": "go test ./agent/cmd/agent/ -run 'RelayDial|EnrollTransport|ListenUnixSocket' -v",
      "exit_code": 0
    },
    {
      "command": "go build ./... && go vet ./agent/... ./internal/enrollwire/... ./internal/fleetwire/...",
      "exit_code": 0
    },
    {
      "command": "go test ./agent/... ./internal/enrollwire/... ./internal/fleetwire/... ./internal/founding/... ./internal/join/...",
      "exit_code": 0
    }
  ],
  "criteria": {
    "The terminal redeem must survive the relay carrier's backoff-delayed (re)bind instead of failing ENOENT once and exiting 1": "agent/cmd/agent/wiring_prod.go: relayHTTPClient now dials via dialRelay/dialRelayWithin, which retries the relay-not-ready ENOENT/ECONNREFUSED signals (250ms backoff, 30s budget) — proven by TestRelayDial_RidesTheCarriersLateBind (a socket that binds at 400ms, on which the pre-#599 single-shot dial fails ENOENT)",
    "The fix must stay bounded and still fail loud on a genuinely-absent relay (ADR 0100), never a fake": "dialRelayWithin returns the last honest dial error once its budget elapses — proven by TestRelayDial_AbsentRelayFailsLoudWithinBudget",
    "The fix must be scoped to the self-hosted founding relay path, not a blanket retry across every enrollwire caller": "the change lives only in wiring_prod.go's founding relayHTTPClient; the gateway/add-device path over http.DefaultClient and enrollwire.do() are untouched"
  },
  "summary": "Bounded relay-socket dial retry (dialRelay) rides the founding carrier's backoff-delayed enroll-relay.sock (re)bind so the box-end terminal redeem stops racing it, while still failing loud on a genuinely-absent relay.",
  "blockers": []
}
**close-report** for #599 — status `success` :no_entry: **close-report gates REFUSED this close** — the following claims did not verify: - commit ec89a8ca is not a valid commit object (fabricated, or never pushed) - changed_files: 'STATUS.md' is not in the diff of the claimed commits - changed_files: 'agent/cmd/agent/wiring_prod.go' is not in the diff of the claimed commits - changed_files: 'agent/cmd/agent/wiring_test.go' is not in the diff of the claimed commits <details><summary>envelope</summary> ```json { "issue": 599, "status": "success", "commits": [ "ec89a8ca" ], "changed_files": [ "STATUS.md", "agent/cmd/agent/wiring_prod.go", "agent/cmd/agent/wiring_test.go" ], "tests": [ { "command": "go test ./agent/cmd/agent/ -run 'RelayDial|EnrollTransport|ListenUnixSocket' -v", "exit_code": 0 }, { "command": "go build ./... && go vet ./agent/... ./internal/enrollwire/... ./internal/fleetwire/...", "exit_code": 0 }, { "command": "go test ./agent/... ./internal/enrollwire/... ./internal/fleetwire/... ./internal/founding/... ./internal/join/...", "exit_code": 0 } ], "criteria": { "The terminal redeem must survive the relay carrier's backoff-delayed (re)bind instead of failing ENOENT once and exiting 1": "agent/cmd/agent/wiring_prod.go: relayHTTPClient now dials via dialRelay/dialRelayWithin, which retries the relay-not-ready ENOENT/ECONNREFUSED signals (250ms backoff, 30s budget) — proven by TestRelayDial_RidesTheCarriersLateBind (a socket that binds at 400ms, on which the pre-#599 single-shot dial fails ENOENT)", "The fix must stay bounded and still fail loud on a genuinely-absent relay (ADR 0100), never a fake": "dialRelayWithin returns the last honest dial error once its budget elapses — proven by TestRelayDial_AbsentRelayFailsLoudWithinBudget", "The fix must be scoped to the self-hosted founding relay path, not a blanket retry across every enrollwire caller": "the change lives only in wiring_prod.go's founding relayHTTPClient; the gateway/add-device path over http.DefaultClient and enrollwire.do() are untouched" }, "summary": "Bounded relay-socket dial retry (dialRelay) rides the founding carrier's backoff-delayed enroll-relay.sock (re)bind so the box-end terminal redeem stops racing it, while still failing loud on a genuinely-absent relay.", "blockers": [] } ``` </details>
Author
Member

close-report for #599 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 599,
  "status": "success",
  "commits": [
    "ec89a8cb8598998fdc08e0cb045aa9eb95ca59b2"
  ],
  "changed_files": [
    "STATUS.md",
    "agent/cmd/agent/wiring_prod.go",
    "agent/cmd/agent/wiring_test.go"
  ],
  "tests": [
    {
      "command": "go test ./agent/cmd/agent/ -run 'RelayDial|EnrollTransport|ListenUnixSocket' -v",
      "exit_code": 0
    },
    {
      "command": "go build ./... && go vet ./agent/... ./internal/enrollwire/... ./internal/fleetwire/...",
      "exit_code": 0
    },
    {
      "command": "go test ./agent/... ./internal/enrollwire/... ./internal/fleetwire/... ./internal/founding/... ./internal/join/...",
      "exit_code": 0
    }
  ],
  "criteria": {
    "The terminal redeem must survive the relay carrier's backoff-delayed (re)bind instead of failing ENOENT once and exiting 1": "agent/cmd/agent/wiring_prod.go: relayHTTPClient now dials via dialRelay/dialRelayWithin, which retries the relay-not-ready ENOENT/ECONNREFUSED signals (250ms backoff, 30s budget) — proven by TestRelayDial_RidesTheCarriersLateBind (a socket that binds at 400ms, on which the pre-#599 single-shot dial fails ENOENT)",
    "The fix must stay bounded and still fail loud on a genuinely-absent relay (ADR 0100), never a fake": "dialRelayWithin returns the last honest dial error once its budget elapses — proven by TestRelayDial_AbsentRelayFailsLoudWithinBudget",
    "The fix must be scoped to the self-hosted founding relay path, not a blanket retry across every enrollwire caller": "the change lives only in wiring_prod.go's founding relayHTTPClient; the gateway/add-device path over http.DefaultClient and enrollwire.do() are untouched"
  },
  "summary": "Bounded relay-socket dial retry (dialRelay) rides the founding carrier's backoff-delayed enroll-relay.sock (re)bind so the box-end terminal redeem stops racing it, while still failing loud on a genuinely-absent relay.",
  "blockers": []
}
**close-report** for #599 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 599, "status": "success", "commits": [ "ec89a8cb8598998fdc08e0cb045aa9eb95ca59b2" ], "changed_files": [ "STATUS.md", "agent/cmd/agent/wiring_prod.go", "agent/cmd/agent/wiring_test.go" ], "tests": [ { "command": "go test ./agent/cmd/agent/ -run 'RelayDial|EnrollTransport|ListenUnixSocket' -v", "exit_code": 0 }, { "command": "go build ./... && go vet ./agent/... ./internal/enrollwire/... ./internal/fleetwire/...", "exit_code": 0 }, { "command": "go test ./agent/... ./internal/enrollwire/... ./internal/fleetwire/... ./internal/founding/... ./internal/join/...", "exit_code": 0 } ], "criteria": { "The terminal redeem must survive the relay carrier's backoff-delayed (re)bind instead of failing ENOENT once and exiting 1": "agent/cmd/agent/wiring_prod.go: relayHTTPClient now dials via dialRelay/dialRelayWithin, which retries the relay-not-ready ENOENT/ECONNREFUSED signals (250ms backoff, 30s budget) — proven by TestRelayDial_RidesTheCarriersLateBind (a socket that binds at 400ms, on which the pre-#599 single-shot dial fails ENOENT)", "The fix must stay bounded and still fail loud on a genuinely-absent relay (ADR 0100), never a fake": "dialRelayWithin returns the last honest dial error once its budget elapses — proven by TestRelayDial_AbsentRelayFailsLoudWithinBudget", "The fix must be scoped to the self-hosted founding relay path, not a blanket retry across every enrollwire caller": "the change lives only in wiring_prod.go's founding relayHTTPClient; the gateway/add-device path over http.DefaultClient and enrollwire.do() are untouched" }, "summary": "Bounded relay-socket dial retry (dialRelay) rides the founding carrier's backoff-delayed enroll-relay.sock (re)bind so the box-end terminal redeem stops racing it, while still failing loud on a genuinely-absent relay.", "blockers": [] } ``` </details>
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.

Reference
Matou/idss#599
No description provided.