Repository navigation
Description
github-backup(fetch): a wrong-shape last_fetch field passes #6637 validation and crashes the whole daily fetch
Summary
#6637 hardened infra/github-backup against wrong-shape plan/state entries: validate_state (bin/ghb_common.py) drops a non-object per-repo entry and resets a non-list fail_days, and it validates the drainer's bookkeeping keys by shape (drain_last::<repo> must be a number, bool excluded). But the per-repo entry's own fields are not validated — in particular last_fetch, the one field the daily fetch does arithmetic on.
A state.json entry such as {"owner/a": {"last_fetch": "2026-11-01T00:00:00Z"}} (an ISO string — e.g. from a hand edit, an older/newer writer, or the torn-write shapes #3240 is about) passes validate_state with zero problems reported, and then crashes fetch_mirrors.main before any repo is fetched.
This is the field-level residual of #6637, the same shape as #6757 (field-level residual of #6652) and #6814 (field-level residual of #6716).
Evidence (verified this run, laptop, origin/main c110f92)
-
infra/github-backup/bin/ghb_common.py—validate_state: for a per-repo dict entry it checks onlyfail_dayslist-ness;last_fetch(andlast_error) pass through unchecked, whatever their JSON type. -
infra/github-backup/bin/fetch_mirrors.py:141(inmain):if not only and st.get("last_fetch") and now - st["last_fetch"] < COALESCE_S:
nowistime.time()(float). A string/list/dictlast_fetchmakes this subtraction raiseTypeErrorinside the repo loop. Everything after the loop — the state.json rewrite andmanifest_mod.build(root)— never runs, so the run wedges the same way github-backup(fetch): a valid-JSON but wrong-shape plan/state entry crashes the whole daily fetch — one poison entry in plan.json or state.json wedges every repo, every day #6637 described: every repo, every day, until the field is hand-fixed. -
Probe (real
ghb_common.py+fetch_mirrors.pyextracted verbatim from origin/main, run on the laptop,~/git/fleet/probe-ghb-lastfetch):load_statereturned the poisoned entries withproblems=[];fetch_mirrors.mainthen raised, at fetch_mirrors.py:141:{"last_fetch": "2026-11-01T00:00:00Z"}→TypeError: unsupported operand type(s) for -: 'float' and 'str'{"last_fetch": [1762000000]}→ same TypeError ('list'){"last_fetch": {"ts": 1762000000}}→ same TypeError ('dict')- Control
{"last_fetch": 9999999999}(numeric, fresh) → main returned 0, repo correctly coalesce-skipped. {"last_fetch": true}does not crash (bool is an int subclass;now - Trueworks) but is silently read as epoch 1 — a wrong-shape value accepted as a timestamp, the same class thedrain_lastcheck already excludes bool for.
Why it matters
The daily github-backup fetch is a disaster-recovery input (MANIFEST.json is the DR source, per #6653). One malformed field in one repo's state entry aborts the entire run with a raw traceback — no per-repo report, no state write, no manifest regeneration — and it recurs daily because the poisoned state is never rewritten. #6637's design rule was exactly that one poison entry must not wedge every repo; the fields inside a surviving entry are the remaining hole.
Suggested fix
Validate last_fetch in validate_state the way drain_last::<repo> is already validated: a per-repo last_fetch that is present must be an int/float and not a bool; otherwise report it as a named problem and drop/reset the field (treat the repo as never-fetched) so the fetch proceeds. Mirror the same treatment for any other field a consumer does arithmetic or ordering on, if one exists.
Acceptance criteria
- A state entry with a string, list, dict, or bool
last_fetchproduces a named problem fromvalidate_state/load_state(visible viareport_problems) and does not reachfetch_mirrors.mainas a non-number. -
fetch_mirrors.maincompletes the full repo loop with such a state file: other repos are fetched/skipped normally, state.json is rewritten, and MANIFEST regeneration runs. - A numeric
last_fetchkeeps today's behavior exactly: fresh entries coalesce-skip (<12h), stale entries fetch. - Regression tests in
infra/github-backup/tests/(extendingtest_plan_state_shape.py/test_fetch_mirrors.py) cover string/list/dict/boollast_fetchand the numeric control; the existing github-backup test suite stays green.
Dedup
#6637 (closed) covered entry-level shapes and the fail_days/drain_* fields; #6653 (closed) covered manifest regeneration; #3240 (open) covers non-atomic writes that can produce torn state. None of them validates the last_fetch field inside a surviving entry. Filed by new-issue-creator-code-b, 2026-11-06 run.
Activity
developing-today commentedon Nov 7, 2026
CODE-2094
dezren39 commentedon Nov 7, 2026
🤖 Agent note · filed
last_fetch; a string/list/dict last_fetch passes silently and crashes fetch_mirrors.main at the coalesce subtraction (fetch_mirrors.py:141), wedging the whole daily github-backup fetch. Verified with the real modules verbatim from origin/main c110f92 on the laptop (probe ~/git/fleet/probe-ghb-lastfetch).developing-today commentedon Nov 8, 2026
🤖 Agent note · handed off
developing-today commentedon Nov 8, 2026
🤖 Agent note · handed off
56 remaining items
dezren39 commentedon Nov 11, 2026
🤖 Agent note · picked up — task 11045 (lane any-c): PR #8686 already implements this fix (opened earlier today); this pass verifies it (github-backup test suites) and merges it rather than duplicating the work.
Merge pull request #8686 from developing-today/queue/11045-6821-last-…
dezren39 commentedon Nov 11, 2026
🤖 Agent note · done — PR #8686 merged (5197d73). The implementation already existed when this task was claimed; this pass verified it end-to-end instead of duplicating it: the diff matches the packet (validate_state drops a non-numeric or bool last_fetch under a named problem, drain_* keys exempt), and the full infra/github-backup test tree passes on the PR head, including the two touched suites (test_fetch_mirrors 8/8, test_plan_state_shape 18/18). Note: no Codex review landed on the PR (the reviewer has been silent on all PRs since ~14:45Z); local verification stands in. Issue auto-closed by the merge.