Repository navigation
Description
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
Problem
infra/github-backup/bin/fetch_mirrors.py loads plan.json and state.json with json.load and then subscripts / .get()s the results with no shape check anywhere. A file that is valid JSON but the wrong shape — the class #3240 does not cover (that issue is torn / unparseable JSON) — crashes the daily fetch before it fetches anything, and the same poison entry re-crashes every subsequent daily run until a human repairs the file by hand.
Sites (all on current main de90338c42):
fetch_mirrors.py:83-85—iter_plan_repos:return [p["repo"] for p in plan]. A plan entry of123,"a/b", or{"name": "x"}(norepo), or a top-level plan that is an object instead of a list, raisesTypeError/KeyErrorand killsmain()at startup.fetch_mirrors.py:92+:100—main:state = json.load(...), thenst = state.get(repo) or {}andst.get("last_fetch"). A top-level list, or a per-repo entry that is a string / int ({"owner/repo": "oops"}), raisesAttributeError: 'str' object has no attribute 'get'— before any fetch, state write, or manifest regeneration.fetch_mirrors.py:64-77—fetch_repo:st = state.setdefault(repo, {})returns a pre-existing non-dict entry unchanged, sost.setdefault("fail_days", [])/st["last_error"] = ...raises on the same poison entry even if the main loop is reached another way.fetch_mirrors.py:22—record_failure_day(days, today): itstrycatches onlyTypeError, ValueError, IndexErroraround the date walk, but a non-listfail_daysescapes anyway: a string raisesTypeError: 'str' object does not support item assignmentat thedays[:] = ...write after the walk, an int raisesTypeErroronlen(), and a dict raisesKeyError: 0(not in the caught set).
Sibling consumers of the same plan.json repeat the unguarded pattern and should be checked in the same pass: manifest.py:41-42 (item["repo"]) and clone_all.py:185-188 (p["repo"]). Note the contrast inside the same system: clone_all.py's clone-status.jsonl reader (the oracle cited in #6606) wraps each line in try/except Exception and skips bad lines, and reconcile.py's _clone_status_entries was the subject of #6606 for the same shape class one level down.
Evidence (verified this run, laptop @ de90338c42 == origin/main)
Probe ~/git/fleet/probe-ghb-fetch-shape/probe.py on the laptop, importing the real fetch_mirrors module from the repo tree (controls + malformed shapes, main() driven with the same patched helpers the in-tree test_fetch_mirrors.py uses):
- Control — valid plan:
iter_plan_repos→['a/b', 'c/d']OK. - Plan entry
123→TypeError: 'int' object is not subscriptable; entry"a/b"→TypeError: string indices must be integers; entry{"name": "x"}→KeyError: 'repo'; plan as a top-level object →TypeError: string indices must be integers. - Control —
record_failure_day(["2026-01-01"], "2026-01-02")→['2026-01-01', '2026-01-02']OK. fail_daysas string →TypeError: 'str' object does not support item assignment; as int →TypeError: object of type 'int' has no len(); as dict →KeyError: 0.- Control —
main()with{"owner/repo": {"last_fetch": 0}}→ exit 0,{"results": {"missing": 1, ...}, "chronic_failures": []}. main()with state entry"oops"or123→AttributeError: 'str'/'int' object has no attribute 'get'; state as a top-level list →AttributeError: 'list' object has no attribute 'get'. No fetch attempted, no state/manifest written.
Why it matters
state.json is shared mutable state (the 5-minute drainer writes it too) and plan.json is generated by the weekly reconcile sweep — neither is hand-audited before the daily fetch consumes it. One wrong-shape entry (a bad reconcile emit, a partial hand edit, a future schema change landing in one writer before the reader) does not degrade the backup for one repo: it takes the whole daily mirror fetch down, silently (a traceback in a timer log), and it is self-perpetuating — the crashing run never rewrites the file, so tomorrow's run hits the identical entry. For a backup system, a poison entry must cost at most that entry, never the estate.
Acceptance criteria
-
fetch_mirrorsvalidates the shape ofplan.jsonandstate.jsonat load: a non-list plan, a plan entry that is not an object with a stringrepo, a non-object state, or a non-object per-repo state entry is reported by name (repo / entry index) and skipped or failed as a single named error — never an unhandledTypeError/KeyError/AttributeErrortraceback that aborts the run for every other repo. - A non-list
fail_days(string / number / object) is treated as a malformed entry under the same rule instead of crashingrecord_failure_day/fetch_repo. - Valid plan/state behaviour is unchanged: coalescing, failure-streak / chronic-failure accounting, and manifest regeneration all work exactly as before on well-formed files (in-tree
test_fetch_mirrors.pystill passes). - Regression tests in the github-backup test suite cover at least: plan entry
123, plan entry missingrepo, state entry as a string, state as a top-level list, andfail_daysas a string — each fails on current code with the exceptions above and passes after the fix. - The sibling
plan.jsonconsumers (manifest.py,clone_all.py) are checked in the same pass and either fixed under the same rule or explicitly recorded as out of scope with a reason.
Dedup: distinct from #3240 (torn/unparseable JSON + non-atomic writes; these files parse fine), #6606 (reconcile's clone-status.jsonl non-dict lines), #6575 (drain queue-event shape), and #3270 (missing mirror never records fail_days). Title/keyword searches for fetch_mirrors + plan/state shape return no covering issue.
Activity
developing-today commentedon Nov 6, 2026
CODE-2043
dezren39 commentedon Nov 6, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 7, 2026
Picked up by
repo-worker-code-a— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-aposts progress markers; after 30 minutes of silence any other worker may pick this up.)14 remaining items
dezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-l: branch_created: worktree ~/git/fleet/fallback-6637 on branch queue/fallback-6637-ghb-shape-validation @717a5108f4; design: shared validate/load helpers in ghb_common (validate_plan/validate_state/load_plan/load_state/report_problems), fetch_mirrors + manifest + clone_all consume them, record_failure_day raises a named ValueError on non-list fail_days, fetch_repo sanitizes per-repo state; next: implement + regression testsdezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-l: implementation_complete: ghb_common validate/load helpers landed; fetch_mirrors, manifest, clone_all consume them; record_failure_day named ValueError; new tests/test_plan_state_shape.py 15/15 pass, 14/15 error on clean main (control passes), full github-backup suite green; next: commit, push, PRdezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-l: still working: PR #6696 open; fixing the Codex P2 finding (validate_state must preserve drain_last::/drain_fail:: bookkeeping entries); note: sandbox /tmp was wiped by a service restart mid-shift — fallback helper recreated in a new per-lane scratch dir per §0b, claim state re-derived from fresh marker reads (live, held by repo-worker-code-l)fix(github-backup): preserve drainer bookkeeping entries in state val…
test(github-backup): property tests for plan/state shape validators (#…
dezren39 commentedon Nov 7, 2026
Progress from
repo-worker-code-l: pr_opened: PR #6696 head 23bd465 — both Codex findings fixed and replied (P2 drain bookkeeping preserved in 2e06082; P1 property tests added in 23bd465); full github-backup suite green on laptop; next: Codex re-review of new head, then merge under standing criteria (PR-tier CI for this suite is dispatch-only by workflow design)Merge pull request #6696 from developing-today/queue/fallback-6637-gh…
dezren39 commentedon Nov 7, 2026
Released by
repo-worker-code-l(outcome: done). Issue #6637 FIXED and merged: PR #6696 #6696 (branch queue/fallback-6637-ghb-shape-validation, head 23bd465, merge commit bc96489). Shared plan/state shape validation landed once in ghb_common (validate_plan/validate_state/load_plan/load_state/report_problems); fetch_mirrors, manifest, and clone_all all consume it; record_failure_day raises a named ValueError on non-list fail_days; fetch_repo sanitizes poison entries. Codex P2 (drain_last::/drain_fail:: bookkeeping must be preserved) and P1 (property tests per testing doctrine) both fixed and replied; final Codex review: zero findings. Tests on laptop: full infra/github-backup suite green at final head (11 files), new test_plan_state_shape.py 20/20 incl. seeded property tests with independent oracles, 14/15 example tests error on clean main. Issue auto-closed by the PR.🤖 Agent note · done