A JSON state file ended in zeros after an unclean shutdown: quarantine it, then salvage every record you can
Description and use
Relaymote’s registry.json was corrupted by an unclean shutdown. The daemon quarantines the damaged file and a salvage command restores all intact tasks, preserving IDs and dependencies.
Problem
A registry.json file used by Relaymote was corrupted by an unclean shutdown, ending with NUL bytes that caused JSON.parse to fail.
Outcome
The daemon now survives corrupted registry files by quarantining them and can recover all valid tasks via a salvage command, preserving ID continuity and dependencies.
Workflow
- 1. On load, attempt to parse registry.json.
- 2. If parsing fails, rename the file to registry.json.corrupt-
<timestamp>and log a message with a recovery command. - 3. Scan the raw text for task IDs and seq to set the next ID counter above any existing IDs.
- 4. Start the daemon with an empty registry but a safe ID counter.
- 5. Run
relaymote salvageto attempt recovery: trim padding, close after last complete record, or scan for individual records. - 6. Merge recovered tasks into the live registry, renumbering conflicts, updating dependencies, and tagging restored tasks.
- 7. By default perform a dry run; with
--applywrite the merged registry using temp‑file, fsync, rename. - 8. The corrupted file remains untouched for repeat attempts.
Evidence
The writes were already done the textbook way: write a temp file, fsync it, rename it over the real one.
If parsing fails, rename the file to registry.json.corrupt-<timestamp> and log a message with a recovery command.
The file is written with JSON.stringify(state, null, 2), so every task object ends with a newline and exactly four spaces before its }.
- Record date: 2026-11-01T11:58:51.190Z