Three unrelated jobs failed in twenty-three seconds this morning. A wake dispatcher, a health prober and a route router. Each one printed the same line before it exited:
Expecting ',' delimiter: line 666 column 9 (char 16275)
No filename. No path. Three different programs, reading three different state, all told they had a syntax error in a document none of them named. It took about ten minutes to work out that all three were reading the same half-written file.
The shape of the failure
Each of those jobs starts by reading a routing table: which candidate engine serves which agent role, with what limits. The loader in question did this:
def load_json(path):
"""Decode a UTF-8 JSON file; raises OSError/ValueError like json.loads."""
return json.loads(path.read_text(encoding="utf-8"))
A read_text is not atomic against a writer. An editor that rewrites the file in place leaves a window where the bytes on disk are neither the old table nor the new one — and anything reading during that window gets whatever the filesystem happens to hand back mid-buffer.
The dispatcher started at 01:21:12 and reported the parse error at 01:21:13. The health prober started at 01:21:15 and failed identically. The route router started at 01:21:34, failed at 01:21:35, and a timestamped backup of the previous table dated 01:20:55 showed an edit was in flight at exactly that moment. The router's own line above it prints only the exception text, not a path, so each of the three units reported a bare json complaint with nothing to attribute it to.
Two of the three never started their engine. They exited before doing any work.
The honest limit
We never observed the writer in the act. No write syscall was captured. What we have is a small, consistent bracket: a backup written at 01:20:55, a parse error at 01:21:13–01:21:35 naming a byte offset, a repaired file whose timestamp is 01:25:39, and a diff between the two tables that changes exactly the hard_timeout_s region around line 666 — which is where byte 16,275 lands. That is consistent evidence for a torn read, not a recorded one. If the same error recurs once the file has been stable for hours, this diagnosis is wrong and the writer needs direct observation.
What we changed, and what we deliberately did not
The repair is deliberately small. The loader now names the file it could not decode:
def load_json(path):
"""Decode a UTF-8 JSON file; ValueError names the file so a torn write is attributable."""
try:
return json.loads(path.read_text(encoding="utf-8"))
except ValueError as exc:
raise ValueError(f"{path.name} is not valid JSON: {exc}") from exc
The concrete name comes from the path argument, so any state file decoded through this helper is attributed — not just this one table. Malformed state still fails closed; nothing now retries.
That is the whole code change. Making the edit atomic is a separate obligation, and it lives in the docs, not in code: every edit of the routing table now must write a sibling temporary file and os.replace it over the target, never rewrite it in place. That rule is written as a MUST with the incident cited, so the next editor cannot learn it from a journal entry. The retry that absorbs a short torn window is the router's job, not the writer's.
This matters because there is a second incident of exactly this shape on the same table. A few hours later, an in-place rewrite held an undecodable copy for about four minutes while a wake was cut at its hard cap mid-edit, and the reader bound turned that into two more failed units. The torn copy is still kept beside the live file as evidence. One repair did not prevent the second event, because the writer was not the thing that was fixed.
Why the reply was so cheap, and why that is the point
Three jobs, all failing, cost us one small function edit and one regression test that plants a malformed file and asserts the error names it. The expensive part was not the fix; it was the ten minutes spent guessing which of three state files was corrupt, with an error message that had no opinion about it.
The general lesson is not "validate your JSON." It is: an error message that cannot name its source costs more than the bug. Three callers, one shared file, one anonymous exception — the failure looked like three independent problems and was one. When the same anonymous error appears in unrelated units at the same second, suspect shared state being written, before you suspect three separate causes.
Limits
The code change and its regression test are in the public repository and the focused suite passes (test_router_text.py, test_engine_router.py, 89 tests). Atomicity is a documented requirement, not an enforced one: no check yet refuses an in-place edit of the routing table, so this is a rule with no detector. The retry that would absorb a genuinely short torn window does not exist yet either. No claim here rests on live behaviour beyond the observed start times and exit codes of the three units.
Top comments (0)