Skip to content

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

Closed

Description

@dezren39

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 of 123, "a/b", or {"name": "x"} (no repo), or a top-level plan that is an object instead of a list, raises TypeError / KeyError and kills main() at startup.
  • fetch_mirrors.py:92 + :100 — main: state = json.load(...), then st = state.get(repo) or {} and st.get("last_fetch"). A top-level list, or a per-repo entry that is a string / int ({"owner/repo": "oops"}), raises AttributeError: '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, so st.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): its try catches only TypeError, ValueError, IndexError around the date walk, but a non-list fail_days escapes anyway: a string raises TypeError: 'str' object does not support item assignment at the days[:] = ... write after the walk, an int raises TypeError on len(), and a dict raises KeyError: 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_days as 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" or 123 → 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_mirrors validates the shape of plan.json and state.json at load: a non-list plan, a plan entry that is not an object with a string repo, 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 unhandled TypeError / KeyError / AttributeError traceback 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 crashing record_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.py still passes).
  • Regression tests in the github-backup test suite cover at least: plan entry 123, plan entry missing repo, state entry as a string, state as a top-level list, and fail_days as a string — each fails on current code with the exceptions above and passes after the fix.
  • The sibling plan.json consumers (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

  1. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/github-backupinfra/github-backup estate mirror system
    on Nov 6, 2026
  3. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator-code-b (new-issue-creator job, Lane B)
    • Session / ID: job new-issue-creator-code-b, run 2026-11-06 17:20 CST
    • Found via: filed this run
    • Task: Triage the fetch_mirrors plan/state shape-validation bug: valid-JSON wrong-shape entries in plan.json/state.json (and non-list fail_days) crash the whole daily github-backup fetch with unhandled TypeError/KeyError/AttributeError; verified this run on the laptop @ de90338 with probe ~/git/fleet/probe-ghb-fetch-shape (real fetch_mirrors module; controls pass, every malformed shape raises).
    • Expectation: effort s — done when malformed entries are reported by name and skipped/named-failed without aborting the run for other repos, valid behaviour unchanged, and regression tests cover the malformed shapes.
    • Links: evidence and acceptance criteria in the issue body; sibling plan consumers manifest.py / clone_all.py to be checked in the same pass.
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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 while repo-worker-code-a posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  5. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 7, 2026
  6. 14 remaining items

  7. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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 tests

  8. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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, PR

  9. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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)

  10. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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)

  11. added a commit that references this issue on Nov 7, 2026
  12. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/github-backupinfra/github-backup estate mirror systemkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions