rented gateway: enroll-activate restarts the whole cloud-init unit set on an already-initialised box — the concurrent stages race /var/lib/cloud/instance into a real directory and poison cloud-init permanently #892

Closed
opened 2026-08-27 07:11:40 +00:00 by matou-build-agent · 1 comment

Drive 20260827T065053Z red at leg standing / journey leg enroll-activate (sig 25304f657c24), commit 5d64bee7. This is the furthest a device drive has reached — wizard-rent through enroll-copy all green (artifacts/legs.json), so the #884/#885 prefix work and the prior heal hold. The fault is new and it is real: the masked_exit detector is behaving correctly here.

Failure

founding: stand up the rented server: clan: masked_exit on gateway:
[gateway] Failed to start cloud-init.service
[gateway] Failed to start cloud-config.target
[gateway] cloud-init[2304]: IsADirectoryError: [Errno 21] Is a directory: '/var/lib/cloud/instance'

artifacts/legs.json (leg enroll-activate, 235022ms), artifacts/verdict.json (firstRedLeg: standing, 11 green / 2 red), logs/founding-state.log (the enroll-activate stage events and the terminal fault).

Mechanism — proven on the box, timestamp by timestamp

The standing gateway is never released on a device drive (scripts/smoke-private-path.sh:643-650), so 168.144.173.213 is still up. Its journal, read over the app's rent-operator key (test-results/standing-rented/state/rent-operator/id_ed25519), pins the race exactly:

time event
07:03:56 switch-to-configuration restarts cloud-init-local (2110) and cloud-config (2113) concurrently
07:03:58 cloud-final and cloud-init (2304) start too — all four stages in flight at once
07:03:58.262 2110: Creating symbolic link from '/var/lib/cloud/instance' => '/var/lib/cloud/instances/595525745'
07:03:58.281 /var/lib/cloud/instance birth as a directory (stat -c %w → 2026-08-27 07:03:58.281330793)
07:03:58.286 2110: Writing to /var/lib/cloud/instance/obj.pkl — write_file's ensure_dir() is what made it a dir
07:03:58.32 2113 writes instances/iid-datasource-none/sem/{config_mounts,config_set_passwords,config_ssh} — a second cloud-init that resolved no datasource and whose own _reflect_cur_instance unlinked the symlink in the gap
07:03:59.617 2304: del_file(instance_link) → os.unlink() on a directory → IsADirectoryError, cloud-init.service exits 2
07:03:59.803 cloud-final (2301) writes boot-finished into the directory, cementing it
07:04:11 systemd retries cloud-init.service, identical crash

Upstream path: cloudinit/stages.py:469 (_reflect_cur_instance → util.del_file(self.paths.instance_link)) → cloudinit/util.py:2072 (os.unlink). cloud-init 25.2, cloudinit.distros.nixos.Distro, DataSourceConfigDrive [net,ver=2][source=/dev/vdb].

_reflect_cur_instance is unlink-then-symlink with no lock. Any concurrent stage that writes through instance_link in that window recreates the path as a plain directory — and from then on the box is permanently poisoned: every subsequent cloud-init init crashes on the same line.

Suspected layer

The deployed rented-gateway config keeps the full cloud-init unit set enabled:

  • internal/clan/vmguest.go:361-375 — rentedHostNetworking() splices networking.useNetworkd = true plus services.cloud-init = { enable = true; network.enable = true; settings.ssh_deletekeys = false; }
  • rendered verbatim into the community flake at state/clan-config/machines/gateway/gateway-guest.nix:155-165 (the captured flake for this run)

Because the community generation resolves a different cloud-init store path than the golden image, activation sees all four units as changed and restarts them — concurrently, on a box whose cloud-init completed at 06:52. Re-running the init/config/final stages against already-written state is what opens the race. This will recur on every converge onto a rented droplet, not just this one.

GOTCHAS #64 / #703 is why the block exists, but read it closely: the load-bearing half is networking.useNetworkd = true — cloud-init's /etc/systemd/network/10-cloud-init-ens3.network is a runtime file in /etc that activation does not touch, so the address and default route survive without cloud-init re-running. The services.cloud-init half is what re-runs and poisons. Note the guarding test internal/clan/vmguest_test.go:45 (TestRenderGatewayGuest_PublicGatewayKeepsNetworkdAndCloudInit) asserts all five lines are present, so it must move with any change.

What plugging it needs

  1. Stop activation re-running cloud-init on an already-initialised rented box. Candidates, in preference order: (a) keep networking.useNetworkd = true and drop services.cloud-init from the deployed config, relying on the already-written .network file as GOTCHAS #64 itself describes — verify live that the default route survives activation; (b) keep cloud-init declared but make the units not restart on switch (restartIfChanged = false / X-RestartIfChanged=false on the four units); (c) leave the units but make the state idempotent. (a) and (b) both need a live converge to prove; (b) is the smaller step and does not touch #64's ruling at all, so it is probably where to start.
  2. Repair the poisoned standing gateway. 168.144.173.213 has cloud-init.service in failed right now and /var/lib/cloud/instance as a directory holding boot-finished + obj.pkl. Until it is replaced with a symlink to /var/lib/cloud/instances/595525745 (whose real contents are intact), every re-drive that adopts this standing community reds at enroll-activate again — the box is the fault, not the code path under test. Either repair on-box or re-found the standing community.
  3. Harvest the droplet journal on the device target. scripts/smoke-private-path.sh:623-650 takes the target == device branch, which runs oc_device_teardown and gathers no droplet-side evidence at all — it never reads artifacts/droplet-ip.txt (written by app/tests/e2e/fixtures/rentedPrefix.ts:291) nor sets OC_E2E_DROPLET_IP. The rented branch at :651-661 does exactly that before oc_rented_cleanup. Result: the run dir has no logs/droplet-journal.txt despite the prompt naming one, and the whole mechanism above was only recoverable because the standing gateway happens to outlive the drive. oc_droplet_gather_evidence (scripts/lib/rehearsal-droplet.sh:425-470) already does the work; the device branch just needs to reach it.
  4. Add a GOTCHAS entry for the unlink-then-symlink race once the fix lands — it is the third distinct way cloud-init on a rented gateway has bitten this repo (#63 host keys, #64 networkd, this).

The masked_exit detector needs no change: logSaysFailed (internal/clan/errors.go:268-345) correctly refused to exempt a line where two systemd units genuinely failed.

drive 20260827T065053Z red at standing: journey leg "enroll-activate" went red: founding: stand up the rented server: clan: masked_exit on gateway: clan reported success but the log shows a real failure: [gateway] Failed to start cloud-init
evidence: /home/swarm/swarm/Matou/idss/test-results/drive-device/20260827T065053Z on matou-workstation (legs.json and whatever else the drive harvested there) — a representative screenshot is attached here if one was captured

Drive `20260827T065053Z` red at leg `standing` / journey leg `enroll-activate` (sig `25304f657c24`), commit `5d64bee7`. This is the furthest a device drive has reached — `wizard-rent` through `enroll-copy` all green (`artifacts/legs.json`), so the #884/#885 prefix work and the prior heal hold. The fault is new and it is real: the masked_exit detector is behaving correctly here. ## Failure ``` founding: stand up the rented server: clan: masked_exit on gateway: [gateway] Failed to start cloud-init.service [gateway] Failed to start cloud-config.target [gateway] cloud-init[2304]: IsADirectoryError: [Errno 21] Is a directory: '/var/lib/cloud/instance' ``` `artifacts/legs.json` (leg `enroll-activate`, 235022ms), `artifacts/verdict.json` (`firstRedLeg: standing`, 11 green / 2 red), `logs/founding-state.log` (the `enroll-activate` stage events and the terminal `fault`). ## Mechanism — proven on the box, timestamp by timestamp The standing gateway is never released on a device drive (`scripts/smoke-private-path.sh:643-650`), so `168.144.173.213` is still up. Its journal, read over the app's rent-operator key (`test-results/standing-rented/state/rent-operator/id_ed25519`), pins the race exactly: | time | event | |---|---| | 07:03:56 | `switch-to-configuration` restarts `cloud-init-local` (2110) and `cloud-config` (2113) **concurrently** | | 07:03:58 | `cloud-final` and `cloud-init` (2304) start too — all four stages in flight at once | | 07:03:58.262 | 2110: `Creating symbolic link from '/var/lib/cloud/instance' => '/var/lib/cloud/instances/595525745'` | | 07:03:58.281 | `/var/lib/cloud/instance` **birth as a directory** (`stat -c %w` → `2026-08-27 07:03:58.281330793`) | | 07:03:58.286 | 2110: `Writing to /var/lib/cloud/instance/obj.pkl` — `write_file`'s `ensure_dir()` is what made it a dir | | 07:03:58.32 | 2113 writes `instances/iid-datasource-none/sem/{config_mounts,config_set_passwords,config_ssh}` — a second cloud-init that resolved **no datasource** and whose own `_reflect_cur_instance` unlinked the symlink in the gap | | 07:03:59.617 | 2304: `del_file(instance_link)` → `os.unlink()` on a directory → `IsADirectoryError`, `cloud-init.service` exits 2 | | 07:03:59.803 | `cloud-final` (2301) writes `boot-finished` into the directory, cementing it | | 07:04:11 | systemd retries `cloud-init.service`, identical crash | Upstream path: `cloudinit/stages.py:469` (`_reflect_cur_instance` → `util.del_file(self.paths.instance_link)`) → `cloudinit/util.py:2072` (`os.unlink`). cloud-init 25.2, `cloudinit.distros.nixos.Distro`, `DataSourceConfigDrive [net,ver=2][source=/dev/vdb]`. `_reflect_cur_instance` is unlink-then-symlink with no lock. Any concurrent stage that writes through `instance_link` in that window recreates the path as a plain directory — and from then on the box is **permanently poisoned**: every subsequent `cloud-init init` crashes on the same line. ## Suspected layer The deployed rented-gateway config keeps the full cloud-init unit set enabled: - `internal/clan/vmguest.go:361-375` — `rentedHostNetworking()` splices `networking.useNetworkd = true` **plus** `services.cloud-init = { enable = true; network.enable = true; settings.ssh_deletekeys = false; }` - rendered verbatim into the community flake at `state/clan-config/machines/gateway/gateway-guest.nix:155-165` (the captured flake for this run) Because the community generation resolves a different cloud-init store path than the golden image, activation sees all four units as changed and restarts them — concurrently, on a box whose cloud-init completed at 06:52. Re-running the init/config/final stages against already-written state is what opens the race. This will recur on **every** converge onto a rented droplet, not just this one. GOTCHAS #64 / #703 is why the block exists, but read it closely: the load-bearing half is `networking.useNetworkd = true` — cloud-init's `/etc/systemd/network/10-cloud-init-ens3.network` is a runtime file in `/etc` that activation does not touch, so the address and default route survive without cloud-init *re-running*. The `services.cloud-init` half is what re-runs and poisons. Note the guarding test `internal/clan/vmguest_test.go:45` (`TestRenderGatewayGuest_PublicGatewayKeepsNetworkdAndCloudInit`) asserts all five lines are present, so it must move with any change. ## What plugging it needs 1. **Stop activation re-running cloud-init on an already-initialised rented box.** Candidates, in preference order: (a) keep `networking.useNetworkd = true` and drop `services.cloud-init` from the deployed config, relying on the already-written `.network` file as GOTCHAS #64 itself describes — verify live that the default route survives activation; (b) keep cloud-init declared but make the units not restart on switch (`restartIfChanged = false` / `X-RestartIfChanged=false` on the four units); (c) leave the units but make the state idempotent. (a) and (b) both need a live converge to prove; (b) is the smaller step and does not touch #64's ruling at all, so it is probably where to start. 2. **Repair the poisoned standing gateway.** `168.144.173.213` has `cloud-init.service` in `failed` right now and `/var/lib/cloud/instance` as a directory holding `boot-finished` + `obj.pkl`. Until it is replaced with a symlink to `/var/lib/cloud/instances/595525745` (whose real contents are intact), **every re-drive that adopts this standing community reds at `enroll-activate` again** — the box is the fault, not the code path under test. Either repair on-box or re-found the standing community. 3. **Harvest the droplet journal on the device target.** `scripts/smoke-private-path.sh:623-650` takes the `target == device` branch, which runs `oc_device_teardown` and gathers **no droplet-side evidence at all** — it never reads `artifacts/droplet-ip.txt` (written by `app/tests/e2e/fixtures/rentedPrefix.ts:291`) nor sets `OC_E2E_DROPLET_IP`. The `rented` branch at `:651-661` does exactly that before `oc_rented_cleanup`. Result: the run dir has no `logs/droplet-journal.txt` despite the prompt naming one, and the whole mechanism above was only recoverable because the standing gateway happens to outlive the drive. `oc_droplet_gather_evidence` (`scripts/lib/rehearsal-droplet.sh:425-470`) already does the work; the device branch just needs to reach it. 4. **Add a GOTCHAS entry** for the unlink-then-symlink race once the fix lands — it is the third distinct way cloud-init on a rented gateway has bitten this repo (#63 host keys, #64 networkd, this). The masked_exit detector needs no change: `logSaysFailed` (`internal/clan/errors.go:268-345`) correctly refused to exempt a line where two systemd units genuinely failed. drive `20260827T065053Z` red at `standing`: `journey leg "enroll-activate" went red: founding: stand up the rented server: clan: masked_exit on gateway: clan reported success but the log shows a real failure: [gateway] Failed to start cloud-init` evidence: `/home/swarm/swarm/Matou/idss/test-results/drive-device/20260827T065053Z` on matou-workstation (legs.json and whatever else the drive harvested there) — a representative screenshot is attached here if one was captured <!-- rehearsal-sig: 25304f657c24 -->
Author
Member

close-report for #892 — status success

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

envelope
{
  "issue": 892,
  "status": "success",
  "commits": [
    "0ebee23"
  ],
  "changed_files": [
    "internal/clan/vmguest.go",
    "internal/clan/vmguest_test.go",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci -c go test ./internal/clan/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "DUPLICATE of #893": "same drive 20260827T065053Z, same masked_exit on gateway / IsADirectoryError on /var/lib/cloud/instance / enroll-activate red; #892 is the deeper timestamp-by-timestamp diagnosis of the same fault. Resolved by the same commit 0ebee23 (closed #893).",
    "Stop activation re-running cloud-init on an already-initialised rented box (candidate b — restartIfChanged=false, the preferred smaller step)": "rentedHostNetworking() in internal/clan/vmguest.go now sets systemd.services.{cloud-init-local,cloud-init,cloud-config,cloud-final}.restartIfChanged = false, so switch-to-configuration leaves the four units alone across a converge — no restart, no concurrent re-run, no race on instance_link. GOTCHAS #64's networking.useNetworkd ruling untouched (commit 0ebee23).",
    "Guarding test moved with the change (vmguest_test.go:45 asserted all five lines)": "TestRenderGatewayGuest_PublicGatewayKeepsNetworkdAndCloudInit now also asserts the four restartIfChanged lines; red before, green after (go test ./internal/clan/ exit 0)",
    "Add a GOTCHAS entry for the unlink-then-symlink race": "docs/GOTCHAS.md entry #104 added (the third cloud-init-on-rented-gateway hazard alongside #63 host keys and #64 networkd)",
    "Harvest the droplet journal on the device target (item 3)": "out of this render slice; filed as its own issue #894 (scripts/lib/rehearsal-droplet.sh oc_droplet_gather_evidence unreached by the device teardown branch)",
    "Repair the poisoned standing gateway (item 2)": "operational residue, not a code change: 168.144.173.213 must be re-founded or /var/lib/cloud/instance restored to a symlink into instances/595525745 before the next drive, else it reds on the box's state not the code"
  },
  "summary": "Duplicate of #893 (same drive/root cause); resolved by commit 0ebee23 which marks the four rented-gateway cloud-init units restartIfChanged=false (candidate b), moves the guarding test, and adds GOTCHAS #104; item 3 filed as #894, item 2 is operational residue.",
  "reason": "",
  "blockers": []
}
**close-report** for #892 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 892, "status": "success", "commits": [ "0ebee23" ], "changed_files": [ "internal/clan/vmguest.go", "internal/clan/vmguest_test.go", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "nix develop .#go-ci -c go test ./internal/clan/", "exit_code": 0 } ], "criteria": { "DUPLICATE of #893": "same drive 20260827T065053Z, same masked_exit on gateway / IsADirectoryError on /var/lib/cloud/instance / enroll-activate red; #892 is the deeper timestamp-by-timestamp diagnosis of the same fault. Resolved by the same commit 0ebee23 (closed #893).", "Stop activation re-running cloud-init on an already-initialised rented box (candidate b — restartIfChanged=false, the preferred smaller step)": "rentedHostNetworking() in internal/clan/vmguest.go now sets systemd.services.{cloud-init-local,cloud-init,cloud-config,cloud-final}.restartIfChanged = false, so switch-to-configuration leaves the four units alone across a converge — no restart, no concurrent re-run, no race on instance_link. GOTCHAS #64's networking.useNetworkd ruling untouched (commit 0ebee23).", "Guarding test moved with the change (vmguest_test.go:45 asserted all five lines)": "TestRenderGatewayGuest_PublicGatewayKeepsNetworkdAndCloudInit now also asserts the four restartIfChanged lines; red before, green after (go test ./internal/clan/ exit 0)", "Add a GOTCHAS entry for the unlink-then-symlink race": "docs/GOTCHAS.md entry #104 added (the third cloud-init-on-rented-gateway hazard alongside #63 host keys and #64 networkd)", "Harvest the droplet journal on the device target (item 3)": "out of this render slice; filed as its own issue #894 (scripts/lib/rehearsal-droplet.sh oc_droplet_gather_evidence unreached by the device teardown branch)", "Repair the poisoned standing gateway (item 2)": "operational residue, not a code change: 168.144.173.213 must be re-founded or /var/lib/cloud/instance restored to a symlink into instances/595525745 before the next drive, else it reds on the box's state not the code" }, "summary": "Duplicate of #893 (same drive/root cause); resolved by commit 0ebee23 which marks the four rented-gateway cloud-init units restartIfChanged=false (candidate b), moves the guarding test, and adds GOTCHAS #104; item 3 filed as #894, item 2 is operational residue.", "reason": "", "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#892
No description provided.