a deploy whose remote switch dies reports only the downstream 502 — nothing harvests the switch unit's journal, so exit 101 arrives with no cause attached #862

Closed
opened 2026-08-25 22:49:02 +00:00 by matou-build-agent · 3 comments

Follow-up from #858 (secondary half — the primary fix landed; this is the fail-loud gap it exposed, with one correction to how #858 framed it).

The gap

When the gateway's self-deploy switch died, nothing in the run recorded WHY. The deploy fault carried deploy failed (setup-error): control plane responded 502 and the journal carried a bare clan-switch-gateway-e1e73dab.service: Main process exited, code=exited, status=101. Diagnosing it took hand-reading three drives' journals side by side. A deploy fault should name its own cause (ADR 0027, fail-loud).

Correction to #858's proposed shape

#858 suggested "fold the transient unit's own journal (journalctl -u 'clan-switch-gateway-*') into the deploy fault so the next recurrence names the panic instead of a bare exit code."

It will not name the panic. clan-core wraps the remote activation in systemd-run --pipe --wait --collect (see internal/clan/enrollment.go:1083), so switch-to-configuration's stdout/stderr go to the pipe, not the journal. When the panic is itself caused by that pipe breaking, the panic text is written to the broken pipe and lost. That is why grep -i panic over all three drives' journals (20260825T071850Z, 20260825T164507Z, 20260825T212849Z) returns nothing but an unrelated DRM message.

What the journal DOES carry is still the whole diagnosis, and is worth harvesting:

21:39:17 systemd: Stopping idss-control-plane.service...
21:39:17 systemd: clan-switch-gateway-e1e73dab.service: Main process exited, code=exited, status=101

— the stop and the death, one second apart, with no finished switching. Naming that in the fault would have made #858 a five-minute read.

Why it did not land with #858

The harvest needs a per-operation SSH target for the node being deployed. deploy.updateNode (internal/clan/adapter.go:318) has no target — clan machines update resolves its own — and the target resolver is the ADR 0039 / #163 deferral the deploy seam already declines to fabricate (adapter.go:285-292 says exactly this for explicit unit restarts). So this is a real seam extension, not a quick add, and #858 chose not to smuggle it in.

What it needs

  • A bounded, redacted journalctl -u 'clan-switch-gateway-*' --since <deploy start> harvest over the node's own ssh door, attached to the Failure a deploy update returns when the switch dies non-zero.
  • Reuse the transport + host-key discipline Adapter.probeCurrentSystem / UnitActive already use (internal/clan/enrollment.go:1122), rather than a new one.
  • Bound the output like excerpt does, and keep secrets out — a gateway journal carries unit env.
  • Seam-testable with a scripted CLI double; the end-to-end proof is any droplet drive whose switch fails.

Lower bound, if the above is too big

Even with no remote harvest, the classifier could recognise a switch-to-configuration exit 101 and say so in words — "the remote switch died at 101 (a switch-to-configuration panic), which on the self-deploy path means it was killed with the unit it stopped — see GOTCHAS #86" — instead of surfacing only the downstream 502. Cheap, no new transport, and it points the next reader at the right entry.

Follow-up from #858 (secondary half — the primary fix landed; this is the fail-loud gap it exposed, with one correction to how #858 framed it). ## The gap When the gateway's self-deploy switch died, **nothing in the run recorded WHY**. The deploy fault carried `deploy failed (setup-error): control plane responded 502` and the journal carried a bare `clan-switch-gateway-e1e73dab.service: Main process exited, code=exited, status=101`. Diagnosing it took hand-reading three drives' journals side by side. A deploy fault should name its own cause (ADR 0027, fail-loud). ## Correction to #858's proposed shape #858 suggested "fold the transient unit's own journal (`journalctl -u 'clan-switch-gateway-*'`) into the deploy fault so the next recurrence names the panic instead of a bare exit code." **It will not name the panic.** clan-core wraps the remote activation in `systemd-run --pipe --wait --collect` (see `internal/clan/enrollment.go:1083`), so `switch-to-configuration`'s stdout/stderr go to the **pipe**, not the journal. When the panic is itself caused by that pipe breaking, the panic text is written to the broken pipe and lost. That is why `grep -i panic` over all three drives' journals (`20260825T071850Z`, `20260825T164507Z`, `20260825T212849Z`) returns nothing but an unrelated DRM message. What the journal DOES carry is still the whole diagnosis, and is worth harvesting: ``` 21:39:17 systemd: Stopping idss-control-plane.service... 21:39:17 systemd: clan-switch-gateway-e1e73dab.service: Main process exited, code=exited, status=101 ``` — the stop and the death, one second apart, with no `finished switching`. Naming *that* in the fault would have made #858 a five-minute read. ## Why it did not land with #858 The harvest needs a per-operation SSH target for the node being deployed. `deploy.updateNode` (`internal/clan/adapter.go:318`) has no target — `clan machines update` resolves its own — and the target resolver is the ADR 0039 / #163 deferral the deploy seam already declines to fabricate (`adapter.go:285-292` says exactly this for explicit unit restarts). So this is a real seam extension, not a quick add, and #858 chose not to smuggle it in. ## What it needs - A bounded, redacted `journalctl -u 'clan-switch-gateway-*' --since <deploy start>` harvest over the node's own ssh door, attached to the `Failure` a deploy update returns when the switch dies non-zero. - Reuse the transport + host-key discipline `Adapter.probeCurrentSystem` / `UnitActive` already use (`internal/clan/enrollment.go:1122`), rather than a new one. - Bound the output like `excerpt` does, and keep secrets out — a gateway journal carries unit env. - Seam-testable with a scripted CLI double; the end-to-end proof is any droplet drive whose switch fails. ## Lower bound, if the above is too big Even with no remote harvest, the classifier could recognise a `switch-to-configuration` exit 101 and say so in words — "the remote switch died at 101 (a switch-to-configuration panic), which on the self-deploy path means it was killed with the unit it stopped — see GOTCHAS #86" — instead of surfacing only the downstream 502. Cheap, no new transport, and it points the next reader at the right entry.
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime

Ruling: route to ready-for-agent for the full journal-harvest (not just the "lower bound" fallback this issue offers) — the per-operation SSH target this issue says is missing already exists for the case this bug actually reports.

Correction to the issue's framing: the deploy seam already resolves a per-node SSH target from the clan inventory — the same Deploy.TargetHost field Adapter.UnitActive reads today to reach a node over "the SAME SSH target the deploy reaches it at". That resolution is not gated behind the ADR-0039/#163 mesh-target resolver. #163 (closed) is about Netbird-mesh-enrolled household nodes; the case this issue reports — the gateway's own self-deploy, clan-switch-gateway-* — targets itself at a static loopback address (the box "deploys to its OWN node at root@127.0.0.1"), the exact own-VPS forward-loopback case UnitActive's own doc comment already covers. So the failing clan machines update invocation can resolve the SAME target it just used and open the SAME kind of ssh transport UnitActive already opens for that node — no new resolver needed.

Why this is a two-way door: which transport the harvest reuses is an implementation-shape call, reversible by a later commit, and provable by the seam's own tests — UnitActive's existing contract tests already prove the transport works for exactly this target class; the harvest gets an equivalent seam test with a scripted CLI/ssh double.

What proves it: the inventory-backed target resolution Adapter.UnitActive already uses and documents (own-VPS forward loopback included), and the gateway's own self-deploy render, which sets the gateway's deploy target to its own loopback address.


Agent Brief

Category: bug
Summary: A deploy fault from a died remote switch names only the downstream symptom (e.g. a 502 / setup-error), never the switch unit's own death — diagnosing it today means hand-reading a node's journal out of band.

Current behavior: When a node's switch-to-configuration dies non-zero during a deploy update (see GOTCHAS #86 — the self-deploy exit-101 panic), the deploy's Failure carries only the caller-visible symptom (e.g. "control plane responded 502"). The failing unit's own journal — which names the stop/death sequence — is never captured by the deploy itself, so a recurrence needs cross-referencing journals by hand.

Desired behavior: When a deploy update's switch step fails non-zero, the resulting Failure should also carry a bounded, redacted excerpt of the failing switch unit's own journal for the deploy's own time window, harvested over the SAME per-node SSH target and host-key/identity discipline the deploy already uses to reach that node (the target Adapter.UnitActive resolves from the inventory). The harvest must be bounded in size (mirroring the seam's existing output-bounding helpers) and must never surface raw unit environment values (a gateway journal can carry unit env).

At minimum, if the full harvest proves impractical for some node/deploy shape, the failure classifier should at least recognize a switch-to-configuration non-zero exit and name it in the Failure's message — e.g. "the remote switch died at exit <n> (a switch-to-configuration panic) — see GOTCHAS #86" — instead of surfacing only the downstream symptom.

Key interfaces:

  • The Failure type's Detail/Tail fields — where the harvested journal excerpt (or the corrected classifier message) should land.
  • Whichever helper already opens an ssh session to a node's own inventory-resolved deploy target (the one UnitActive uses) should be reused for the harvest, not duplicated.
  • The harvest should scope to the switch-related unit(s) for the node being deployed, bounded to a --since <deploy start>-style window.

Acceptance criteria:

  • A deploy update whose switch step exits non-zero produces a Failure whose Detail/Tail names the switch unit's own stop/death journal lines (not just the downstream symptom), at least for the self-deploy (own-VPS) case.
  • The harvested output is bounded in size and never includes raw unit environment values.
  • The harvest reuses the deploy's existing per-node SSH target/transport discipline rather than introducing a second ssh code path.
  • Covered by a seam test using a scripted CLI/ssh double — no live node required.
  • Any case where the full harvest is judged impractical still names the switch-to-configuration non-zero exit as the cause in the Failure's message, rather than surfacing only the downstream symptom.

Out of scope:

  • A general per-operation SSH-target resolver for arbitrary mesh-enrolled (non-self-deploy) nodes — only the case this issue reports (a target the deploy already knows) needs solving here.
  • Recovering the original panic text itself (documented as unrecoverable — it's written to a pipe that's already broken by the time it fires).
  • Changing clan-core's own remote-activation wrapping.
> *This was generated by AI during triage.* Ruled by agent under ADR 0174 — veto anytime **Ruling:** route to `ready-for-agent` for the full journal-harvest (not just the "lower bound" fallback this issue offers) — the per-operation SSH target this issue says is missing already exists for the case this bug actually reports. **Correction to the issue's framing:** the deploy seam already resolves a per-node SSH target from the clan inventory — the same `Deploy.TargetHost` field `Adapter.UnitActive` reads today to reach a node over "the SAME SSH target the deploy reaches it at". That resolution is not gated behind the ADR-0039/#163 mesh-target resolver. #163 (closed) is about Netbird-mesh-enrolled household nodes; the case this issue reports — the gateway's own self-deploy, `clan-switch-gateway-*` — targets itself at a static loopback address (the box "deploys to its OWN node at root@127.0.0.1"), the exact own-VPS forward-loopback case `UnitActive`'s own doc comment already covers. So the failing `clan machines update` invocation can resolve the SAME target it just used and open the SAME kind of ssh transport `UnitActive` already opens for that node — no new resolver needed. **Why this is a two-way door:** which transport the harvest reuses is an implementation-shape call, reversible by a later commit, and provable by the seam's own tests — `UnitActive`'s existing contract tests already prove the transport works for exactly this target class; the harvest gets an equivalent seam test with a scripted CLI/ssh double. **What proves it:** the inventory-backed target resolution `Adapter.UnitActive` already uses and documents (own-VPS forward loopback included), and the gateway's own self-deploy render, which sets the gateway's deploy target to its own loopback address. --- ## Agent Brief **Category:** bug **Summary:** A deploy fault from a died remote switch names only the downstream symptom (e.g. a 502 / setup-error), never the switch unit's own death — diagnosing it today means hand-reading a node's journal out of band. **Current behavior:** When a node's `switch-to-configuration` dies non-zero during a deploy update (see GOTCHAS #86 — the self-deploy exit-101 panic), the deploy's Failure carries only the caller-visible symptom (e.g. "control plane responded 502"). The failing unit's own journal — which names the stop/death sequence — is never captured by the deploy itself, so a recurrence needs cross-referencing journals by hand. **Desired behavior:** When a deploy update's switch step fails non-zero, the resulting Failure should also carry a bounded, redacted excerpt of the failing switch unit's own journal for the deploy's own time window, harvested over the SAME per-node SSH target and host-key/identity discipline the deploy already uses to reach that node (the target `Adapter.UnitActive` resolves from the inventory). The harvest must be bounded in size (mirroring the seam's existing output-bounding helpers) and must never surface raw unit environment values (a gateway journal can carry unit env). At minimum, if the full harvest proves impractical for some node/deploy shape, the failure classifier should at least recognize a `switch-to-configuration` non-zero exit and name it in the Failure's message — e.g. "the remote switch died at exit `<n>` (a switch-to-configuration panic) — see GOTCHAS #86" — instead of surfacing only the downstream symptom. **Key interfaces:** - The `Failure` type's `Detail`/`Tail` fields — where the harvested journal excerpt (or the corrected classifier message) should land. - Whichever helper already opens an ssh session to a node's own inventory-resolved deploy target (the one `UnitActive` uses) should be reused for the harvest, not duplicated. - The harvest should scope to the switch-related unit(s) for the node being deployed, bounded to a `--since <deploy start>`-style window. **Acceptance criteria:** - [ ] A deploy update whose switch step exits non-zero produces a Failure whose Detail/Tail names the switch unit's own stop/death journal lines (not just the downstream symptom), at least for the self-deploy (own-VPS) case. - [ ] The harvested output is bounded in size and never includes raw unit environment values. - [ ] The harvest reuses the deploy's existing per-node SSH target/transport discipline rather than introducing a second ssh code path. - [ ] Covered by a seam test using a scripted CLI/ssh double — no live node required. - [ ] Any case where the full harvest is judged impractical still names the `switch-to-configuration` non-zero exit as the cause in the Failure's message, rather than surfacing only the downstream symptom. **Out of scope:** - A general per-operation SSH-target resolver for arbitrary mesh-enrolled (non-self-deploy) nodes — only the case this issue reports (a target the deploy already knows) needs solving here. - Recovering the original panic text itself (documented as unrecoverable — it's written to a pipe that's already broken by the time it fires). - Changing clan-core's own remote-activation wrapping.
Author
Member

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

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

close-report for #862 — status success

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

envelope
{
  "issue": 862,
  "status": "success",
  "commits": [
    "3557b8a774cf1b404657ab731d12fabafc6e299c"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "internal/clan/adapter.go",
    "internal/clan/deploy_switch_journal_test.go"
  ],
  "tests": [
    {
      "command": "go test ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "go vet ./internal/clan/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A deploy update whose switch step exits non-zero produces a Failure whose Detail/Tail names the switch unit's own stop/death journal lines (not just the downstream symptom), at least for the self-deploy (own-VPS) case": "deploy.Run -> enrichSwitchDeath harvests journalctl -u 'clan-switch-<node>-*' over the node's inventory deploy target and folds the stop/death lines into Failure.Tail + names the exit in Detail (internal/clan/adapter.go); proven by TestDeploy_SwitchDeathHarvestsJournalAndNamesExit (Tail carries 'Stopping idss-control-plane.service' + 'status=101', Detail names 'switch-to-configuration' 'exit 101', recovered from the journal alone when the CLI carried only the ssh close)",
    "The harvested output is bounded in size and never includes raw unit environment values": "harvestSwitchJournal bounds via remote journalctl -n <switchJournalLines> + local lastLines, and redactUnitEnv masks every uppercase KEY=value; TestDeploy_SwitchDeathHarvestsJournalAndNamesExit asserts 'hunter2secret' absent and 'IDSS_NEXTCLOUD_ADMIN_PASSWORD=<redacted>' present",
    "The harvest reuses the deploy's existing per-node SSH target/transport discipline rather than introducing a second ssh code path": "harvestSwitchJournal builds the same BatchMode + StrictHostKeyChecking=accept-new + optional UserKnownHostsFile/IdentityFile argv over a.sshRun that Adapter.UnitActive uses, reading the target from the inventory Deploy.TargetHost; test asserts the argv rode ssh://<target> + the scoped known-hosts pin",
    "Covered by a seam test using a scripted CLI/ssh double — no live node required": "internal/clan/deploy_switch_journal_test.go drives the production Adapter over the scriptCLI double and an injected a.sshRun; go test ./internal/clan green",
    "Any case where the full harvest is judged impractical still names the switch-to-configuration non-zero exit as the cause in the Failure's message, rather than surfacing only the downstream symptom": "when the harvest returns empty/errored, switchExitFromLog falls back to the CLI output's Tail; TestDeploy_SwitchDeathLowerBoundNamesExitWithoutHarvest (no deploy target) asserts Detail still names 'switch-to-configuration' 'exit 101', and TestDeploy_NonSwitchFailureNoFalsePositive proves an eval death is never miscalled a panic"
  },
  "summary": "A deploy whose remote switch dies now harvests the clan-switch-<node>-* unit's own journal (redacted, bounded) over the node's own ssh door and names the switch-to-configuration exit in the Failure, closing #858's fail-loud residue.",
  "blockers": []
}
**close-report** for #862 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 862, "status": "success", "commits": [ "3557b8a774cf1b404657ab731d12fabafc6e299c" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "internal/clan/adapter.go", "internal/clan/deploy_switch_journal_test.go" ], "tests": [ { "command": "go test ./internal/clan/", "exit_code": 0 }, { "command": "go vet ./internal/clan/", "exit_code": 0 } ], "criteria": { "A deploy update whose switch step exits non-zero produces a Failure whose Detail/Tail names the switch unit's own stop/death journal lines (not just the downstream symptom), at least for the self-deploy (own-VPS) case": "deploy.Run -> enrichSwitchDeath harvests journalctl -u 'clan-switch-<node>-*' over the node's inventory deploy target and folds the stop/death lines into Failure.Tail + names the exit in Detail (internal/clan/adapter.go); proven by TestDeploy_SwitchDeathHarvestsJournalAndNamesExit (Tail carries 'Stopping idss-control-plane.service' + 'status=101', Detail names 'switch-to-configuration' 'exit 101', recovered from the journal alone when the CLI carried only the ssh close)", "The harvested output is bounded in size and never includes raw unit environment values": "harvestSwitchJournal bounds via remote journalctl -n <switchJournalLines> + local lastLines, and redactUnitEnv masks every uppercase KEY=value; TestDeploy_SwitchDeathHarvestsJournalAndNamesExit asserts 'hunter2secret' absent and 'IDSS_NEXTCLOUD_ADMIN_PASSWORD=<redacted>' present", "The harvest reuses the deploy's existing per-node SSH target/transport discipline rather than introducing a second ssh code path": "harvestSwitchJournal builds the same BatchMode + StrictHostKeyChecking=accept-new + optional UserKnownHostsFile/IdentityFile argv over a.sshRun that Adapter.UnitActive uses, reading the target from the inventory Deploy.TargetHost; test asserts the argv rode ssh://<target> + the scoped known-hosts pin", "Covered by a seam test using a scripted CLI/ssh double — no live node required": "internal/clan/deploy_switch_journal_test.go drives the production Adapter over the scriptCLI double and an injected a.sshRun; go test ./internal/clan green", "Any case where the full harvest is judged impractical still names the switch-to-configuration non-zero exit as the cause in the Failure's message, rather than surfacing only the downstream symptom": "when the harvest returns empty/errored, switchExitFromLog falls back to the CLI output's Tail; TestDeploy_SwitchDeathLowerBoundNamesExitWithoutHarvest (no deploy target) asserts Detail still names 'switch-to-configuration' 'exit 101', and TestDeploy_NonSwitchFailureNoFalsePositive proves an eval death is never miscalled a panic" }, "summary": "A deploy whose remote switch dies now harvests the clan-switch-<node>-* unit's own journal (redacted, bounded) over the node's own ssh door and names the switch-to-configuration exit in the Failure, closing #858's fail-loud residue.", "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.

Dependencies

No dependencies set.

Reference
Matou/idss#862
No description provided.