Skip to content

A raw non-JSON ledger line permanently defeats watchtower-pre-update.sh's 48h trim, which its own comment believes the timestamp shape-check prevents

Id: TD-PPagop-26083002 · Status: open · Filed: 2026-08-30

deploy/docker/watchtower-pre-update.sh’s record_verdict trims the ledger after an allow with jq -c 'select(...)' "$f" > "$tmp" — plain jq over the file, not -R with try/catch as lib/updater-health.sh’s _updater_health_streak_start deliberately uses for the same input. A line that is not JSON at all (a torn write, external corruption — never a line the hook itself writes) aborts that jq pass before the ISO-8601 shape check inside the program can run: reproduced on PR #929’s branch, a three-line ledger with one raw not json at all line makes the trim jq exit 5, so the if guard discards $tmp and the file is kept untrimmed — every time, for ever, for that file. The comment above the trim says the shape check exists so a corrupt line “could otherwise never be trimmed at all”; the shape check handles a JSON line whose ts is garbage (covered by test/watchtower-pre-update.test.sh’s “trims an unparseable timestamp too”), but a non-JSON line defeats the whole pass one layer out.

Why it matters. Severity is low and the blast radius bounded: the file grows one short line per WATCHTOWER_POLL_INTERVAL (~10 MB/year at the 300s default), and a successful roll retires the hostname’s file, which the hook’s own 7-day prune then deletes. But the failure is silent, permanent for the file’s lifetime, and contradicts the code’s stated contract — and the read side already proves the repo knows the right idiom for exactly this input.

Where. deploy/docker/watchtower-pre-update.sh (record_verdict’s trim block); test/watchtower-pre-update.test.sh (no case feeds the trim a raw non-JSON line — adding one would have caught this).

Suggested fix. Run the trim’s jq the same way the library reads the same file: jq -R -c 'try (fromjson | select(...)) catch empty', so an unparseable line is dropped by the trim rather than wedging it. One-line change plus one test case. Distinct from TD-PPagop-26082932, which is about the reader’s routing when the last line is corrupt; this is the writer’s trim never running again while any corrupt line exists anywhere in the file.

Noticed while approving https://github.com/Poetic-Poems/agent-ops/pull/929, which introduces the ledger.

Noticed while the Approver was judging https://github.com/Poetic-Poems/agent-ops/pull/929.

Migrated to https://github.com/Pullwright/agent-ops/issues/2005.