Skip to content

github-backup(fetch): a wrong-shape last_fetch field passes #6637 validation and crashes the whole daily fetch #6821

Closed

Description

@dezren39

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 only fail_days list-ness; last_fetch (and last_error) pass through unchecked, whatever their JSON type.

  • infra/github-backup/bin/fetch_mirrors.py:141 (in main):

    if not only and st.get("last_fetch") and now - st["last_fetch"] < COALESCE_S:

    now is time.time() (float). A string/list/dict last_fetch makes this subtraction raise TypeError inside the repo loop. Everything after the loop — the state.json rewrite and manifest_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.py extracted verbatim from origin/main, run on the laptop, ~/git/fleet/probe-ghb-lastfetch): load_state returned the poisoned entries with problems=[]; fetch_mirrors.main then 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 - True works) but is silently read as epoch 1 — a wrong-shape value accepted as a timestamp, the same class the drain_last check 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_fetch produces a named problem from validate_state/load_state (visible via report_problems) and does not reach fetch_mirrors.main as a non-number.
  • fetch_mirrors.main completes 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_fetch keeps today's behavior exactly: fresh entries coalesce-skip (<12h), stale entries fetch.
  • Regression tests in infra/github-backup/tests/ (extending test_plan_state_shape.py / test_fetch_mirrors.py) cover string/list/dict/bool last_fetch and 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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    on Nov 7, 2026
  2. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b, run 2026-11-06 23:50 CST
    • Found via: filed this run
    • Task: Field-level residual of 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: validate_state checks entry shape and fail_days/drain_* fields but not 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).
    • Expectation: effort/s small-fix — validate last_fetch in validate_state (number, not bool; named problem + reset), regression tests; queued for the repo worker.
    • Links: packet creator-b-2026-11-06-2350/packet-6821-small-fix.json (goal hidden_files)
  4. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

  5. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

  6. added
    work/assignedQueue worker lifecycle state
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Nov 8, 2026
  7. 56 remaining items

  8. added
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 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.

  10. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 11, 2026
  11. added a commit that references this issue on Nov 11, 2026
  12. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 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.

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/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus/donestatus: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