watchtower-pre-update.sh's 48h ledger trim aborts on any non-JSON line, permanently disabling trimming for that file
Id: TD-PPagop-26082931 · Status: open · Filed: 2026-08-29
record_verdict’s trim runs jq -c --arg cutoff … 'select(…)' "$f" > "$tmp" over the whole ledger without -R/fromjson?, so a single non-JSON line anywhere in the file makes jq exit non-zero (verified: exit 5, ‘Invalid numeric literal’) and the else-branch discards the partial tmp — the file is left untouched. Since this trim is the only thing that ever removes lines from a container’s own ledger (the 7-day find-prune explicitly excludes the own file), one corrupt non-JSON line disables the 48h bound for the life of the container: the file then grows by one line per WATCHTOWER_POLL_INTERVAL indefinitely, and every updater_status call scans the whole ever-growing file. Why it matters: it is the same family as review-of-#929 finding 2’s second half — that fix (the ISO-8601 shape test in the filter) only covers a corrupt timestamp inside valid JSON; a line that is not JSON at all defeats the filter before select() runs. Severity is low: verdict correctness is unaffected (lib/updater-health.sh’s single-pass -R/try-catch reader skips such lines, verified on this branch), growth is ~50 bytes per poll, the hook’s exit status is untouched (best-effort 2>/dev/null throughout), and non-JSON corruption in a file only jq ever writes should be rare. Where: deploy/docker/watchtower-pre-update.sh, record_verdict’s allow-path trim. Suggested fix: make the filter corruption-tolerant, e.g. jq -cR 'fromjson? | select(…)' — which also deletes the corrupt line itself on the next allow, restoring the bound; decide deliberately whether silently dropping unparseable lines during trim is acceptable (it matches the reader’s skip semantics, and TD-PPagop-26082931’s suggested reader fix would remove the last consumer of corrupt lines). Distinct from TD-PPagop-26082931 (reader routing on a corrupt last line) and TD-PPagop-26082913 (a node whose watchtower stops polling): this one is about the writer’s housekeeping being wedged by a line it can never remove. Noticed while approving https://github.com/Poetic-Poems/agent-ops/pull/929.
Noticed while the Approver was judging https://github.com/Poetic-Poems/agent-ops/pull/929.
Migrated to https://github.com/Pullwright/agent-ops/issues/2000.