A single racing occ maintenance:install bricks the files node permanently — the half-written config.php poisons every retry into nixpkgs' dead upgrade branch, and the clean-retry cannot clear it #1022

Closed
opened 2026-08-30 08:15:50 +00:00 by matou-build-agent · 4 comments

Split out of the heal for drive 20260830T074445Z (red at deploy-files, sig 03a7ed69caec). Commit 12676998 fixed the ORDERING that let the first install race the postgres socket. This issue is the separate amplifier that turned that one transient race into an unrecoverable node, and it stands whatever fixes the ordering.

Failure

On that drive nextcloud-setup.service failed four times, and only the first failure was the race:

  • 07:55:43 — occ maintenance:install dies Error while trying to create admin account: … SQLSTATE[08006] [7] connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (logs/droplet-units.txt:102-103, stack at :105-122).
  • 08:00:43, 08:01:11, 08:05:44 — every retry, including the clean-retry, dies with a completely different and much louder error: Nextcloud is not installed - only a limited number of commands are available / Command "upgrade" is not defined (logs/droplet-journal.txt:1423-1429). Postgres had been listening on /run/postgresql for ten minutes by then (logs/droplet-units.txt:65, .postgres-wrapp pid 9977 on 127.0.0.1:5432).

The node never recovers, and the second wording is the one that reaches the operator — so the real cause is hidden behind a symptom that no amount of retrying can clear.

Evidence for the mechanism

nixpkgs' nextcloud-setup script (26.11, nixos/modules/services/web-apps/nextcloud.nix:1446-1450) is:

# Do not install if already installed
if [[ ! -s ${datadir}/config/config.php ]]; then
  ${occInstallCmd}
fi

$OCC_BIN upgrade

The install-vs-upgrade decision is made solely on config.php being non-empty, and Nextcloud writes config.php before it touches the database — the drive's own stack shows Setup.php(386): OC\Setup\PostgreSQL->setupDatabase() being reached from Install.php(82), i.e. after config has been written (logs/droplet-units.txt:113-114). So a maintenance:install that dies at the DB step leaves a non-empty, never-installed config.php behind. From then on the guard skips the install forever and $OCC_BIN upgrade runs against an uninstalled instance, which exits 1 every time. switch-to-configuration exits 4 on that, so the whole deploy reds.

Same boot also shows the two collateral units this drags down: nextcloud-update-db.service (There are no commands defined in the "db" namespace, plus Cannot write into "config" directory!, logs/droplet-journal.txt:1433-1440) and nextcloud-oidc.service, which retried its idempotent provider config ~40 times over four minutes against an instance that could never exist (logs/droplet-journal.txt:17, 57, …, 1477) before dying at the ceiling. All three are named by systemctl --failed (logs/droplet-units.txt:2-4).

Suspected layer

The files render, internal/clan/files.go — the same module that owns renderNextcloudStore / renderFilesFirstActivation. Nothing in this repo currently guards the install's atomicity; we inherit nixpkgs' guard, and that guard is not crash-safe.

What plugging it needs

The node must be able to recover from a failed first install on the next switch, instead of latching. Design ruling needed on which of these the repo wants, because they differ in how destructive they are:

  1. A pre-install guard rendered onto nextcloud-setup (e.g. preStart, or serviceConfig.ExecStartPre) that detects a never-completed install — config.php present but no 'installed' => true — and removes it so the stock guard re-enters the install branch. Needs care: it must be provably unable to fire against a healthy instance, since config.php on a real deployment is data-bearing.
  2. Or make setup's failure non-latching a different way (a sentinel file written only after maintenance:install returns 0, with the guard keying off the sentinel rather than off config.php).

Either way the acceptance criterion is testable at the render level in internal/clan/files_test.go (sibling to TestRenderFiles_SetupRequiresPostgresTarget), and the behavioural criterion is: after a nextcloud-setup failure at the DB step, the NEXT switch installs cleanly rather than reporting Command "upgrade" is not defined.

Worth noting for whoever picks this up: with commit 12676998 in place the ordering race that triggered it should no longer fire, so this is a latent-robustness fix — but it is exactly what cost this drive its clean-retry and a whole paid droplet, and any future first-install hiccup (a slow socket, a vars-not-yet-decrypted dbpassFile, a full disk) re-arms it.

drive 20260830T074445Z red at deploy-files: deploy failed (clean-retry): provision: deploy gateway: clan: deploy failed on 1 node(s): gateway: clan: masked_exit on gateway: clan reported success but the log shows a real failure: the remote swit
evidence: /home/dev/swarm/Matou/idss/test-results/drive-idip/20260830T074445Z on matou-workstation (legs.json and whatever else the drive harvested there) — a representative screenshot is attached here if one was captured

Split out of the heal for drive `20260830T074445Z` (red at `deploy-files`, sig `03a7ed69caec`). Commit `12676998` fixed the ORDERING that let the first install race the postgres socket. This issue is the separate amplifier that turned that one transient race into an unrecoverable node, and it stands whatever fixes the ordering. ## Failure On that drive `nextcloud-setup.service` failed **four** times, and only the first failure was the race: - **07:55:43** — `occ maintenance:install` dies `Error while trying to create admin account: … SQLSTATE[08006] [7] connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory` (`logs/droplet-units.txt:102-103`, stack at `:105-122`). - **08:00:43, 08:01:11, 08:05:44** — every retry, *including the clean-retry*, dies with a completely different and much louder error: `Nextcloud is not installed - only a limited number of commands are available` / `Command "upgrade" is not defined` (`logs/droplet-journal.txt:1423-1429`). Postgres had been listening on `/run/postgresql` for ten minutes by then (`logs/droplet-units.txt:65`, `.postgres-wrapp` pid 9977 on 127.0.0.1:5432). The node never recovers, and the second wording is the one that reaches the operator — so the real cause is hidden behind a symptom that no amount of retrying can clear. ## Evidence for the mechanism nixpkgs' `nextcloud-setup` script (26.11, `nixos/modules/services/web-apps/nextcloud.nix:1446-1450`) is: ```nix # Do not install if already installed if [[ ! -s ${datadir}/config/config.php ]]; then ${occInstallCmd} fi $OCC_BIN upgrade ``` The install-vs-upgrade decision is made **solely on `config.php` being non-empty**, and Nextcloud writes `config.php` *before* it touches the database — the drive's own stack shows `Setup.php(386): OC\Setup\PostgreSQL->setupDatabase()` being reached from `Install.php(82)`, i.e. after config has been written (`logs/droplet-units.txt:113-114`). So a `maintenance:install` that dies at the DB step leaves a non-empty, never-installed `config.php` behind. From then on the guard skips the install forever and `$OCC_BIN upgrade` runs against an uninstalled instance, which exits 1 every time. `switch-to-configuration` exits 4 on that, so the whole deploy reds. Same boot also shows the two collateral units this drags down: `nextcloud-update-db.service` (`There are no commands defined in the "db" namespace`, plus `Cannot write into "config" directory!`, `logs/droplet-journal.txt:1433-1440`) and `nextcloud-oidc.service`, which retried its idempotent provider config ~40 times over four minutes against an instance that could never exist (`logs/droplet-journal.txt:17, 57, …, 1477`) before dying at the ceiling. All three are named by `systemctl --failed` (`logs/droplet-units.txt:2-4`). ## Suspected layer The files render, `internal/clan/files.go` — the same module that owns `renderNextcloudStore` / `renderFilesFirstActivation`. Nothing in this repo currently guards the install's atomicity; we inherit nixpkgs' guard, and that guard is not crash-safe. ## What plugging it needs The node must be able to recover from a failed first install on the next switch, instead of latching. Design ruling needed on which of these the repo wants, because they differ in how destructive they are: 1. A pre-install guard rendered onto `nextcloud-setup` (e.g. `preStart`, or `serviceConfig.ExecStartPre`) that detects a *never-completed* install — `config.php` present but no `'installed' => true` — and removes it so the stock guard re-enters the install branch. Needs care: it must be provably unable to fire against a healthy instance, since `config.php` on a real deployment is data-bearing. 2. Or make setup's failure non-latching a different way (a sentinel file written only after `maintenance:install` returns 0, with the guard keying off the sentinel rather than off `config.php`). Either way the acceptance criterion is testable at the render level in `internal/clan/files_test.go` (sibling to `TestRenderFiles_SetupRequiresPostgresTarget`), and the behavioural criterion is: after a `nextcloud-setup` failure at the DB step, the NEXT switch installs cleanly rather than reporting `Command "upgrade" is not defined`. Worth noting for whoever picks this up: with commit `12676998` in place the ordering race that triggered it should no longer fire, so this is a latent-robustness fix — but it is exactly what cost this drive its clean-retry and a whole paid droplet, and any future first-install hiccup (a slow socket, a vars-not-yet-decrypted `dbpassFile`, a full disk) re-arms it. drive `20260830T074445Z` red at `deploy-files`: `deploy failed (clean-retry): provision: deploy gateway: clan: deploy failed on 1 node(s): gateway: clan: masked_exit on gateway: clan reported success but the log shows a real failure: the remote swit` evidence: `/home/dev/swarm/Matou/idss/test-results/drive-idip/20260830T074445Z` on matou-workstation (legs.json and whatever else the drive harvested there) — a representative screenshot is attached here if one was captured <!-- rehearsal-sig: 03a7ed69caec -->
Author
Member

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

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

Ruled by agent under ADR 0174 — veto anytime.

The issue asks for a design ruling between (1) a pre-install guard on nextcloud-setup that removes a never-completed config.php so the stock guard re-enters the install branch, and (2) a sentinel file the guard keys off instead of config.php.

Ruling: option 1, rendered as a preStart on nextcloud-setup, keyed on the absence of 'installed' => true.

  • Option 2 (sentinel) would require replacing nixpkgs' stock if [[ ! -s config.php ]] guard, i.e. overriding the whole setup script. We inherit that script and only want to make it crash-safe, not fork it.
  • The pinned nixpkgs (nixos-24.11) nextcloud-setup has no preStart of its own and runs as serviceConfig.User = "nextcloud" (owner of config.php), so a preStart we add merges cleanly and can remove the poisoned file.
  • The guard removes config.php only when it is present but lacks 'installed' => true — the exact never-completed state Nextcloud leaves when maintenance:install dies at the DB step (it writes base config before setupDatabase() and only stamps 'installed' => true after the DB succeeds). A completed, data-bearing instance always carries 'installed' => true, so the guard is provably unable to fire against a healthy instance.

Why two-way door: revertible by a later commit (it is a preStart block in the render); provable by a render test (TestRenderFiles_SetupClearsNeverCompletedInstall, sibling to TestRenderFiles_SetupRequiresPostgresTarget) and behaviourally by the next paid drive-idip re-greening deploy-files. It is not the "data destruction" one-way door: it can only ever delete a config that no data was ever written behind (DB never set up), and never touches a healthy one.

**Ruled by agent under ADR 0174 — veto anytime.** The issue asks for a design ruling between (1) a pre-install guard on `nextcloud-setup` that removes a *never-completed* `config.php` so the stock guard re-enters the install branch, and (2) a sentinel file the guard keys off instead of `config.php`. **Ruling: option 1**, rendered as a `preStart` on `nextcloud-setup`, keyed on the absence of `'installed' => true`. - Option 2 (sentinel) would require replacing nixpkgs' stock `if [[ ! -s config.php ]]` guard, i.e. overriding the whole setup `script`. We inherit that script and only want to make it crash-safe, not fork it. - The pinned nixpkgs (`nixos-24.11`) `nextcloud-setup` has **no `preStart` of its own** and runs as `serviceConfig.User = "nextcloud"` (owner of `config.php`), so a `preStart` we add merges cleanly and can remove the poisoned file. - The guard removes `config.php` **only when it is present but lacks `'installed' => true`** — the exact never-completed state Nextcloud leaves when `maintenance:install` dies at the DB step (it writes base config before `setupDatabase()` and only stamps `'installed' => true` after the DB succeeds). A completed, data-bearing instance always carries `'installed' => true`, so the guard is **provably unable to fire against a healthy instance**. **Why two-way door:** revertible by a later commit (it is a `preStart` block in the render); provable by a render test (`TestRenderFiles_SetupClearsNeverCompletedInstall`, sibling to `TestRenderFiles_SetupRequiresPostgresTarget`) and behaviourally by the next paid `drive-idip` re-greening `deploy-files`. It is **not** the "data destruction" one-way door: it can only ever delete a config that no data was ever written behind (DB never set up), and never touches a healthy one.
Author
Member

close-report for #1022 — status success

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

  • commit baf5fbfba4 is not reachable from origin/main (not landed)
  • changed_files: 'internal/clan/files.go' is not in the diff of the claimed commits
  • changed_files: 'internal/clan/files_test.go' is not in the diff of the claimed commits
  • changed_files: 'docs/GOTCHAS.md' is not in the diff of the claimed commits
  • changed_files: 'STATUS.md' is not in the diff of the claimed commits
envelope
{
  "issue": 1022,
  "status": "success",
  "commits": [
    "baf5fbfba4e3d250f44d4c7202359650dd1a0656"
  ],
  "changed_files": [
    "internal/clan/files.go",
    "internal/clan/files_test.go",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci --command go test ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci --command go vet ./internal/clan/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "After a nextcloud-setup failure at the DB step, the NEXT switch installs cleanly rather than reporting Command \"upgrade\" is not defined": "renderNextcloudStore emits a preStart on nextcloud-setup that rm -f's config.php only when it lacks 'installed' => true, so the stock guard re-enters the install branch on the next switch (internal/clan/files.go)",
    "Testable at the render level in internal/clan/files_test.go (sibling to TestRenderFiles_SetupRequiresPostgresTarget)": "TestRenderFiles_SetupClearsNeverCompletedInstall pins the preStart, the config.php path under services.nextcloud.datadir, the negated grep on 'installed' => true, and the rm -f (files_test.go)",
    "Provably unable to fire against a healthy instance": "the guard removes config.php ONLY when '! grep -qs \"'installed' => true\"' — a completed install always stamps that marker after the DB succeeds (files.go + test asserts the negation)"
  },
  "summary": "nextcloud-setup carries a crash-safety preStart that clears a never-completed config.php so a failed first install no longer latches the files node into the dead upgrade branch.",
  "reason": "",
  "blockers": []
}
**close-report** for #1022 — status `success` :no_entry: **close-report gates REFUSED this close** — the following claims did not verify: - commit baf5fbfba4e3d250f44d4c7202359650dd1a0656 is not reachable from origin/main (not landed) - changed_files: 'internal/clan/files.go' is not in the diff of the claimed commits - changed_files: 'internal/clan/files_test.go' is not in the diff of the claimed commits - changed_files: 'docs/GOTCHAS.md' is not in the diff of the claimed commits - changed_files: 'STATUS.md' is not in the diff of the claimed commits <details><summary>envelope</summary> ```json { "issue": 1022, "status": "success", "commits": [ "baf5fbfba4e3d250f44d4c7202359650dd1a0656" ], "changed_files": [ "internal/clan/files.go", "internal/clan/files_test.go", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "nix develop .#go-ci --command go test ./internal/clan/", "exit_code": 0 }, { "command": "nix develop .#go-ci --command go vet ./internal/clan/", "exit_code": 0 } ], "criteria": { "After a nextcloud-setup failure at the DB step, the NEXT switch installs cleanly rather than reporting Command \"upgrade\" is not defined": "renderNextcloudStore emits a preStart on nextcloud-setup that rm -f's config.php only when it lacks 'installed' => true, so the stock guard re-enters the install branch on the next switch (internal/clan/files.go)", "Testable at the render level in internal/clan/files_test.go (sibling to TestRenderFiles_SetupRequiresPostgresTarget)": "TestRenderFiles_SetupClearsNeverCompletedInstall pins the preStart, the config.php path under services.nextcloud.datadir, the negated grep on 'installed' => true, and the rm -f (files_test.go)", "Provably unable to fire against a healthy instance": "the guard removes config.php ONLY when '! grep -qs \"'installed' => true\"' — a completed install always stamps that marker after the DB succeeds (files.go + test asserts the negation)" }, "summary": "nextcloud-setup carries a crash-safety preStart that clears a never-completed config.php so a failed first install no longer latches the files node into the dead upgrade branch.", "reason": "", "blockers": [] } ``` </details>
Author
Member

close-report for #1022 — status success

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

envelope
{
  "issue": 1022,
  "status": "success",
  "commits": [
    "baf5fbfba4e3d250f44d4c7202359650dd1a0656"
  ],
  "changed_files": [
    "internal/clan/files.go",
    "internal/clan/files_test.go",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci --command go test ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci --command go vet ./internal/clan/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "After a nextcloud-setup failure at the DB step, the NEXT switch installs cleanly rather than reporting Command \"upgrade\" is not defined": "renderNextcloudStore emits a preStart on nextcloud-setup that rm -f's config.php only when it lacks 'installed' => true, so the stock guard re-enters the install branch on the next switch (internal/clan/files.go)",
    "Testable at the render level in internal/clan/files_test.go (sibling to TestRenderFiles_SetupRequiresPostgresTarget)": "TestRenderFiles_SetupClearsNeverCompletedInstall pins the preStart, the config.php path under services.nextcloud.datadir, the negated grep on 'installed' => true, and the rm -f (files_test.go)",
    "Provably unable to fire against a healthy instance": "the guard removes config.php ONLY when '! grep -qs \"'installed' => true\"' — a completed install always stamps that marker after the DB succeeds (files.go + test asserts the negation)"
  },
  "summary": "nextcloud-setup carries a crash-safety preStart that clears a never-completed config.php so a failed first install no longer latches the files node into the dead upgrade branch.",
  "reason": "",
  "blockers": []
}
**close-report** for #1022 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1022, "status": "success", "commits": [ "baf5fbfba4e3d250f44d4c7202359650dd1a0656" ], "changed_files": [ "internal/clan/files.go", "internal/clan/files_test.go", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "nix develop .#go-ci --command go test ./internal/clan/", "exit_code": 0 }, { "command": "nix develop .#go-ci --command go vet ./internal/clan/", "exit_code": 0 } ], "criteria": { "After a nextcloud-setup failure at the DB step, the NEXT switch installs cleanly rather than reporting Command \"upgrade\" is not defined": "renderNextcloudStore emits a preStart on nextcloud-setup that rm -f's config.php only when it lacks 'installed' => true, so the stock guard re-enters the install branch on the next switch (internal/clan/files.go)", "Testable at the render level in internal/clan/files_test.go (sibling to TestRenderFiles_SetupRequiresPostgresTarget)": "TestRenderFiles_SetupClearsNeverCompletedInstall pins the preStart, the config.php path under services.nextcloud.datadir, the negated grep on 'installed' => true, and the rm -f (files_test.go)", "Provably unable to fire against a healthy instance": "the guard removes config.php ONLY when '! grep -qs \"'installed' => true\"' — a completed install always stamps that marker after the DB succeeds (files.go + test asserts the negation)" }, "summary": "nextcloud-setup carries a crash-safety preStart that clears a never-completed config.php so a failed first install no longer latches the files node into the dead upgrade branch.", "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#1022
No description provided.