second-phase remote nix build dies with ssh exit 255 mid-deploy — transport death misclassified as a build failure, no retry #563

Closed
opened 2026-08-15 04:54:02 +00:00 by ben · 3 comments
Owner

Symptom

Headed e2e drive 20260815T043248Z (post-#558/#561, all identity fixes verified in-flight by live process capture): the deploy's control-plane row failed with

[gateway] failed with error: nix build failed for 'gateway' (exit code 255).

Exit 255 is the ssh client's own failure code, not a nix verdict. Timeline from the capture: first-phase upload/build/boot/switch all green (identity present throughout) → second-phase sops upload over a FRESH ControlMaster socket succeeded → second-phase nix build over that same master died 255 mid-run. The guest was healthy before and after: the spec's evidence harvest ssh'd in fine moments later (systemctl --failed clean), no earlyoom (host journal clean, clean systemd stops only), swap never filled.

The strongest suspect is the post-switch sshd restart racing the live multiplexed session: the switch settles service restarts asynchronously, and a session opened just before sshd bounces dies mid-command with 255. The same second-phase build succeeded on the manual drive hours earlier — an intermittent race, not a deterministic wall.

Rule

A remote build/apply step that dies with ssh's transport code (255) must be classified as TRANSPORT, not as a build failure — and the deploy's one sanctioned resumable retry (the pattern the enroll legs already carry) should cover it: reconnect (fresh master) and re-drive the step; the second attempt is idempotent (nix builds are). Misclassifying it as "nix build failed" points the operator at evaluation problems that do not exist.

Also (again — #546): the step's failure detail persisted only the one-line summary; the actual clan stderr for the failed call is nowhere on disk.

Proof

Kill the ssh session under a remote build mid-deploy (or restart the guest sshd during it): the deploy classifies transport, retries once on a fresh connection, and the row completes.

Evidence: run dir test-results/private-path/20260815T043248Z (state/founding-state.json events, artifacts/trace.zip), session ssh-capture log 2026-08-15.

## Symptom Headed e2e drive `20260815T043248Z` (post-#558/#561, all identity fixes verified in-flight by live process capture): the deploy's control-plane row failed with ``` [gateway] failed with error: nix build failed for 'gateway' (exit code 255). ``` **Exit 255 is the ssh client's own failure code, not a nix verdict.** Timeline from the capture: first-phase upload/build/boot/switch all green (identity present throughout) → second-phase sops upload over a FRESH ControlMaster socket succeeded → second-phase `nix build` over that same master died 255 mid-run. The guest was healthy before and after: the spec's evidence harvest ssh'd in fine moments later (`systemctl --failed` clean), no earlyoom (host journal clean, clean systemd stops only), swap never filled. The strongest suspect is the **post-switch sshd restart racing the live multiplexed session**: the switch settles service restarts asynchronously, and a session opened just before sshd bounces dies mid-command with 255. The same second-phase build succeeded on the manual drive hours earlier — an intermittent race, not a deterministic wall. ## Rule A remote build/apply step that dies with ssh's transport code (255) must be classified as TRANSPORT, not as a build failure — and the deploy's one sanctioned resumable retry (the pattern the enroll legs already carry) should cover it: reconnect (fresh master) and re-drive the step; the second attempt is idempotent (nix builds are). Misclassifying it as "nix build failed" points the operator at evaluation problems that do not exist. Also (again — #546): the step's failure detail persisted only the one-line summary; the actual clan stderr for the failed call is nowhere on disk. ## Proof Kill the ssh session under a remote build mid-deploy (or restart the guest sshd during it): the deploy classifies transport, retries once on a fresh connection, and the row completes. Evidence: run dir `test-results/private-path/20260815T043248Z` (state/founding-state.json events, artifacts/trace.zip), session ssh-capture log 2026-08-15.
Author
Owner

This was generated by AI during triage.

Verification: Codebase check confirms the misclassification mechanism. Classify in the clan package's error-classification path orders its checks: interrupted → connectivity (matches on substrings like "ssh:", "connection refused", "host key") → config-eval (matches on "failed assertions" or, further down, the generic "error: " / "evaluation" / "attribute" / "does not evaluate" substrings). The reported failure line [gateway] failed with error: nix build failed for 'gateway' (exit code 255). contains "error: " but no "ssh:" token, so it falls through the connectivity case and lands in the generic eval case — exactly the "operator pointed at evaluation problems that do not exist" misclassification described. The exit code itself (255) is never consulted as a classification signal, only the message/log text is. This confirms the bug is real and precisely reproducible against the current classifier, in the same failure family as #558/#561 (same drive lineage, both closed ready-for-agent).

Agent Brief

Category: bug
Summary: A remote build/apply step whose process exits with ssh's own transport code (255) must classify as a transport/connectivity failure, not a build/eval failure — and get one resumable retry over a fresh connection.

Current behavior:
The clan failure classifier derives its FailureKind purely from matching substrings in the invocation's message/log text, never from the raw process exit code. When an ssh-transported remote build dies with exit 255 (the ssh client's own failure code — e.g. because the target's sshd restarts mid-session after a NixOS switch) but the surfaced message is a generic wrapper like "nix build failed for '<node>' (exit code 255)" with no "ssh:"/"connection"/"host key" substring in the visible text, the classifier falls through connectivity-detection and lands in the config-eval bucket. The operator sees "the node's config does not evaluate" and a remedy pointing at fixing Nix config — which is wrong; the guest and its config are both healthy, and the failure is retriable by nature (the underlying build step is idempotent). There is also no retry: every current resumable remedy is driven by classification, so a mis-set kind means no retry happens where one is warranted.

Separately (already flagged once, #546): a failed step currently persists only the one-line summary. The full stderr from the failed invocation is not retained anywhere durable, so post-hoc diagnosis of why a step failed has no evidence trail once the operator navigates away.

Desired behavior:

  • An invocation's raw process exit code participates in classification, not just message/log text-matching. Specifically, ssh's own transport exit code (255) — when it did not already match a more specific interrupted/signal-kill case — classifies as the connectivity/transport kind, with the existing resumable remedy shape (the same one connectivity failures already carry: reconnect and retry, Resumable: true).
  • The deploy orchestration honors that resumable classification for this step class the same way the enrollment legs already do for their resumable failures: on a transport classification, it reconnects (fresh control connection/master) and re-drives the step exactly once before surfacing a failure to the operator. Because the underlying build is idempotent, a single retry is safe.
  • The full raw stderr/output of a failed invocation is retained as part of the failure's persisted detail (not just the one-line summary), so a later evidence-harvest or operator drill-in can read the actual failure text, not just a truncated headline. (This mirrors the existing Tail-style field pattern used elsewhere in the failure structure for exactly this reason — extend that pattern to this step rather than inventing a new one.)

Key interfaces:

  • The clan failure classifier (Classify-shaped function, node/exit/message/logExcerpt → *Failure) — needs an exit-code-driven branch that runs before (or takes precedence over) the generic eval/"error: " substring match, at minimum for exit 255. Consider whether other well-known transport-only exit codes deserve the same treatment, but scope this ticket to 255 unless the fix is trivially general.
  • Whatever orchestrates a resumable retry for the enrollment legs (search for the existing "reconnect on a resumable connectivity failure" pattern) — the second-phase remote build/apply step needs to be wired into the same resumable-retry path when its failure classifies as connectivity/transport.
  • The Failure struct (or equivalent) — already carries a bounded Tail field for exactly this "full diagnostic text survives even though the summary is short" purpose; use it (or its equivalent) for this step's stderr rather than adding a parallel mechanism.

Acceptance criteria:

  • An invocation that exits 255 with a message that does not itself contain a connectivity-indicating substring (e.g. a bare "nix build failed for '<node>' (exit code 255)") classifies as connectivity/transport, not config-eval.
  • A connectivity/transport classification arising from this step triggers exactly one resumable retry over a fresh connection before the failure surfaces to the operator; the retry is not looped indefinitely.
  • The retried step succeeding produces a normal green outcome with no residual fault state.
  • The retried step failing again surfaces the classified (connectivity) kind, not eval, with the full stderr from the failing invocation available in the persisted failure detail (not just the one-line summary).
  • Existing classification behavior for other exit codes / message shapes (config-eval, missing-var, disk, masked-exit, interrupted) is unchanged — add a test asserting each existing class still routes correctly.
  • Unit test coverage for the new exit-255 branch: at least one case with a connectivity-indicating substring already present (must still classify connectivity, unchanged), and one case with a bare "(exit code 255)" message and no other connectivity token (the new case).

Out of scope:

  • Reclassifying any exit code other than 255 unless the same fix trivially generalizes.
  • Building a general N-retry or backoff policy — this is a single, fixed one-shot retry matching the existing enrollment-leg pattern.
  • The #564 UI-transition bug (separate ticket) — this ticket is the backend classification/retry fix only.
  • Root-causing why the target's sshd restarts mid-session (the switch-restart race) — that's a lower layer; this ticket only needs the failure correctly classified and retried, not the race eliminated.

Ruling (ADR 0174): two-way door — revertible by commit, provable by the existing unit-test suite around the classifier plus the standing rehearsal-drive cron, which will re-exercise this exact deploy path on its next cycle. Same failure family as #558/#561, which were ruled ready-for-agent and closed. Ruled by agent under ADR 0174 — veto anytime.

> *This was generated by AI during triage.* **Verification:** Codebase check confirms the misclassification mechanism. `Classify` in the `clan` package's error-classification path orders its checks: interrupted → connectivity (matches on substrings like `"ssh:"`, `"connection refused"`, `"host key"`) → config-eval (matches on `"failed assertions"` or, further down, the generic `"error: "` / `"evaluation"` / `"attribute"` / `"does not evaluate"` substrings). The reported failure line `[gateway] failed with error: nix build failed for 'gateway' (exit code 255).` contains `"error: "` but no `"ssh:"` token, so it falls through the connectivity case and lands in the generic eval case — exactly the "operator pointed at evaluation problems that do not exist" misclassification described. The exit code itself (255) is never consulted as a classification signal, only the message/log text is. This confirms the bug is real and precisely reproducible against the current classifier, in the same failure family as #558/#561 (same drive lineage, both closed `ready-for-agent`). ## Agent Brief **Category:** bug **Summary:** A remote build/apply step whose process exits with ssh's own transport code (255) must classify as a transport/connectivity failure, not a build/eval failure — and get one resumable retry over a fresh connection. **Current behavior:** The clan failure classifier derives its `FailureKind` purely from matching substrings in the invocation's message/log text, never from the raw process exit code. When an ssh-transported remote build dies with exit 255 (the ssh client's own failure code — e.g. because the target's sshd restarts mid-session after a NixOS switch) but the surfaced message is a generic wrapper like `"nix build failed for '<node>' (exit code 255)"` with no `"ssh:"`/`"connection"`/`"host key"` substring in the visible text, the classifier falls through connectivity-detection and lands in the config-eval bucket. The operator sees "the node's config does not evaluate" and a remedy pointing at fixing Nix config — which is wrong; the guest and its config are both healthy, and the failure is retriable by nature (the underlying build step is idempotent). There is also no retry: every current resumable remedy is driven by classification, so a mis-set kind means no retry happens where one is warranted. Separately (already flagged once, #546): a failed step currently persists only the one-line summary. The full stderr from the failed invocation is not retained anywhere durable, so post-hoc diagnosis of *why* a step failed has no evidence trail once the operator navigates away. **Desired behavior:** - An invocation's raw process exit code participates in classification, not just message/log text-matching. Specifically, ssh's own transport exit code (255) — when it did not already match a more specific interrupted/signal-kill case — classifies as the connectivity/transport kind, with the existing resumable remedy shape (the same one connectivity failures already carry: reconnect and retry, `Resumable: true`). - The deploy orchestration honors that resumable classification for this step class the same way the enrollment legs already do for their resumable failures: on a transport classification, it reconnects (fresh control connection/master) and re-drives the step exactly once before surfacing a failure to the operator. Because the underlying build is idempotent, a single retry is safe. - The full raw stderr/output of a failed invocation is retained as part of the failure's persisted detail (not just the one-line summary), so a later evidence-harvest or operator drill-in can read the actual failure text, not just a truncated headline. (This mirrors the existing `Tail`-style field pattern used elsewhere in the failure structure for exactly this reason — extend that pattern to this step rather than inventing a new one.) **Key interfaces:** - The clan failure classifier (`Classify`-shaped function, `node/exit/message/logExcerpt → *Failure`) — needs an exit-code-driven branch that runs before (or takes precedence over) the generic eval/`"error: "` substring match, at minimum for exit 255. Consider whether other well-known transport-only exit codes deserve the same treatment, but scope this ticket to 255 unless the fix is trivially general. - Whatever orchestrates a resumable retry for the enrollment legs (search for the existing "reconnect on a resumable connectivity failure" pattern) — the second-phase remote build/apply step needs to be wired into the same resumable-retry path when its failure classifies as connectivity/transport. - The `Failure` struct (or equivalent) — already carries a bounded `Tail` field for exactly this "full diagnostic text survives even though the summary is short" purpose; use it (or its equivalent) for this step's stderr rather than adding a parallel mechanism. **Acceptance criteria:** - [ ] An invocation that exits 255 with a message that does not itself contain a connectivity-indicating substring (e.g. a bare `"nix build failed for '<node>' (exit code 255)"`) classifies as connectivity/transport, not config-eval. - [ ] A connectivity/transport classification arising from this step triggers exactly one resumable retry over a fresh connection before the failure surfaces to the operator; the retry is not looped indefinitely. - [ ] The retried step succeeding produces a normal green outcome with no residual fault state. - [ ] The retried step failing again surfaces the classified (connectivity) kind, not eval, with the full stderr from the failing invocation available in the persisted failure detail (not just the one-line summary). - [ ] Existing classification behavior for other exit codes / message shapes (config-eval, missing-var, disk, masked-exit, interrupted) is unchanged — add a test asserting each existing class still routes correctly. - [ ] Unit test coverage for the new exit-255 branch: at least one case with a connectivity-indicating substring already present (must still classify connectivity, unchanged), and one case with a bare "(exit code 255)" message and no other connectivity token (the new case). **Out of scope:** - Reclassifying any exit code other than 255 unless the same fix trivially generalizes. - Building a general N-retry or backoff policy — this is a single, fixed one-shot retry matching the existing enrollment-leg pattern. - The #564 UI-transition bug (separate ticket) — this ticket is the backend classification/retry fix only. - Root-causing *why* the target's sshd restarts mid-session (the switch-restart race) — that's a lower layer; this ticket only needs the failure correctly classified and retried, not the race eliminated. --- **Ruling (ADR 0174):** two-way door — revertible by commit, provable by the existing unit-test suite around the classifier plus the standing rehearsal-drive cron, which will re-exercise this exact deploy path on its next cycle. Same failure family as #558/#561, which were ruled `ready-for-agent` and closed. Ruled by agent under ADR 0174 — veto anytime.
Author
Owner

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

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

close-report for #563 — status success

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

envelope
{
  "issue": 563,
  "status": "success",
  "commits": [
    "0e46eedfd7f94bc41d530dce4dd231ebef975728"
  ],
  "changed_files": [
    "STATUS.md",
    "internal/clan/adapter.go",
    "internal/clan/adapter_test.go",
    "internal/clan/deploy_transport_retry_test.go",
    "internal/clan/errors.go",
    "internal/clan/errors_transport_test.go"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci -c go test ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci -c go build ./...",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci -c go vet ./internal/clan/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "An invocation that exits 255 with a message that does not itself contain a connectivity-indicating substring classifies as connectivity/transport, not config-eval": "internal/clan/errors.go adds `case exit == 255:` returning FailConnectivity before the generic eval case; proven by TestClassify_Exit255BareMessageIsTransport (errors_transport_test.go)",
    "A connectivity/transport classification from this step triggers exactly one resumable retry over a fresh connection before the failure surfaces; the retry is not looped": "internal/clan/adapter.go deploy.updateNode re-drives `clan machines update` once on FailConnectivity; proven by TestDeploy_TransportDeathRetriesOnceAndGreens and TestDeploy_TransportDeathRetriedOnceThenSurfacesConnectivity (exactly 2 apply calls)",
    "The retried step succeeding produces a normal green outcome with no residual fault state": "TestDeploy_TransportDeathRetriesOnceAndGreens: first apply exit 255, retry exit 0, node reconciled, err nil (deploy_transport_retry_test.go)",
    "The retried step failing again surfaces the classified (connectivity) kind, not eval, with the full stderr in the persisted failure detail": "TestDeploy_TransportDeathRetriedOnceThenSurfacesConnectivity asserts FailConnectivity and Failure.Tail contains the raw stderr ('exit code 255'); classify() fills Tail via tail() (adapter.go)",
    "Existing classification behavior for other exit codes / message shapes is unchanged — add a test asserting each existing class still routes correctly": "TestClassify_ExistingClassesStillRoute covers config_eval, assertion, missing_var, disk, interrupted(signal+ctx), masked_exit (errors_transport_test.go); TestDeploy_EvalFailureDoesNotRetry proves eval failures take no retry",
    "Unit test coverage for the new exit-255 branch: one case with a connectivity substring already present (still connectivity), and one bare (exit code 255) message with no other token (the new case)": "TestClassify_Exit255WithConnectivityTokenUnchanged (substring present) and TestClassify_Exit255BareMessageIsTransport (bare message) in errors_transport_test.go"
  },
  "summary": "Exit-255 remote-build deaths now classify as transport (connectivity), not build/eval failures, and deploy.Run retries the apply once over a fresh connection with the full stderr persisted in Failure.Tail.",
  "reason": "Fixes the #563 misclassification and missing retry for ssh transport deaths (exit 255) during second-phase remote builds.",
  "blockers": []
}
**close-report** for #563 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 563, "status": "success", "commits": [ "0e46eedfd7f94bc41d530dce4dd231ebef975728" ], "changed_files": [ "STATUS.md", "internal/clan/adapter.go", "internal/clan/adapter_test.go", "internal/clan/deploy_transport_retry_test.go", "internal/clan/errors.go", "internal/clan/errors_transport_test.go" ], "tests": [ { "command": "nix develop .#go-ci -c go test ./internal/clan/", "exit_code": 0 }, { "command": "nix develop .#go-ci -c go build ./...", "exit_code": 0 }, { "command": "nix develop .#go-ci -c go vet ./internal/clan/", "exit_code": 0 } ], "criteria": { "An invocation that exits 255 with a message that does not itself contain a connectivity-indicating substring classifies as connectivity/transport, not config-eval": "internal/clan/errors.go adds `case exit == 255:` returning FailConnectivity before the generic eval case; proven by TestClassify_Exit255BareMessageIsTransport (errors_transport_test.go)", "A connectivity/transport classification from this step triggers exactly one resumable retry over a fresh connection before the failure surfaces; the retry is not looped": "internal/clan/adapter.go deploy.updateNode re-drives `clan machines update` once on FailConnectivity; proven by TestDeploy_TransportDeathRetriesOnceAndGreens and TestDeploy_TransportDeathRetriedOnceThenSurfacesConnectivity (exactly 2 apply calls)", "The retried step succeeding produces a normal green outcome with no residual fault state": "TestDeploy_TransportDeathRetriesOnceAndGreens: first apply exit 255, retry exit 0, node reconciled, err nil (deploy_transport_retry_test.go)", "The retried step failing again surfaces the classified (connectivity) kind, not eval, with the full stderr in the persisted failure detail": "TestDeploy_TransportDeathRetriedOnceThenSurfacesConnectivity asserts FailConnectivity and Failure.Tail contains the raw stderr ('exit code 255'); classify() fills Tail via tail() (adapter.go)", "Existing classification behavior for other exit codes / message shapes is unchanged — add a test asserting each existing class still routes correctly": "TestClassify_ExistingClassesStillRoute covers config_eval, assertion, missing_var, disk, interrupted(signal+ctx), masked_exit (errors_transport_test.go); TestDeploy_EvalFailureDoesNotRetry proves eval failures take no retry", "Unit test coverage for the new exit-255 branch: one case with a connectivity substring already present (still connectivity), and one bare (exit code 255) message with no other token (the new case)": "TestClassify_Exit255WithConnectivityTokenUnchanged (substring present) and TestClassify_Exit255BareMessageIsTransport (bare message) in errors_transport_test.go" }, "summary": "Exit-255 remote-build deaths now classify as transport (connectivity), not build/eval failures, and deploy.Run retries the apply once over a fresh connection with the full stderr persisted in Failure.Tail.", "reason": "Fixes the #563 misclassification and missing retry for ssh transport deaths (exit 255) during second-phase remote builds.", "blockers": [] } ``` </details>
ben closed this issue 2026-08-15 06:19:59 +00:00
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#563
No description provided.