03 §12a item 7: a cut write of the agent's config is repaired at start (R-1380); red-proofs
gates / gates (push) Successful in 2m7s

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
admin committed 2026-11-15 08:20:49 +01:00
1 parent fffbb40ce0
commit bbecdd9195
2 files changed
+82 -3

No files matched your search

+16 -3
View File
@@ -1015,9 +1015,22 @@ the new root alone. Checked with the real openssl and a real TLS server in the w
(`Ensure` is called from the start, the timer, a failed collect and a bundle install), and the root step has a
90-second deadline — it runs on the daemon's start path and inside the report loop. (c) **One lock for every writer
of `agent.json`** in the process (`config.FileMu`: the trust move, the PBS seed, the backup-target move): each reads
the whole file and writes the whole file. **Left open, low:** the write is in place (not a rename), and nothing reads
the parked copy `agent.json.pre-pve-trust` back by itself — on a full disk a failed write and a failed put-back can
leave an empty config; the hand repair is to copy the parked file back.
the whole file and writes the whole file.
**7. A cut write cannot leave a blind box (2026-11-15, before the release; R-1380).** The agent cannot rename a new
file into the config's folder (root owns it), so the write is in place: truncate, write, sync. A power cut in between
left an empty or half config, the agent did not start, and a box whose agent does not start cannot be repaired from
the hub. Now the three writers use `config.ReplaceInPlace`: (1) the OLD bytes go into a journal file in the agent's
own state folder (`/var/lib/felhom-agent/agent.json.write-in-flight`; a new file, synced, renamed, the folder synced
— the agent can do that there); (2) the config is written, synced and read back; (3) the journal is removed. **At
every daemon start, before the config is read,** `config.RecoverCutWrite`: a journal beside a config that does not
parse → the old bytes go back; a journal beside a config that parses → the file is whole (old or new), only the
journal goes. No journal folder → no write. A selftest never repairs (it can run beside a live agent that is in the
middle of a write). So after a cut the agent starts with the old file or the new file; with the old one it is a
pinned box again and the move runs again. Tested with a cut staged at each of the four steps
(`TestRecoverCutWrite_AfterACutAtEveryStepTheConfigIsWholeAndLoads`); the wiring is pinned
(`TestMainCallsTheConfigRepairBeforeItLoadsTheConfig`, `TestAgentJSONWritersUseTheJournalledWrite`). **Not proven: a
real power cut on a box.** The copy `agent.json.pre-pve-trust` stays, for a person; nothing reads it.
**What changes for a pinned box when Proxmox makes a new certificate:** the first failed call names
`pinned_cert_changed`, runs the order above, and the next call works — the box is blind for one report cycle at most,