Skip to content

github-backup(drain): drain_queue reads plan.json/state.json with bare json.load — the one consumer bypassing validate_plan/validate_state, and its own drain_* keys crash it #6835

Closed

Description

@dezren39

github-backup(drain): drain_queue reads plan.json/state.json with bare json.load — the one consumer bypassing validate_plan/validate_state, and its own drain_* keys crash it

Evidence

Verified on the laptop at origin/main e380645a3b7c94e47dabda544564d7fd89c75416. Every other github-backup consumer of plan.json/state.json now goes through the #6637 shared gates (ghb_common.load_plan / load_state → validate_plan / validate_state): fetch_mirrors, clone_all, manifest, and (after #6831 is fixed) reconcile. infra/github-backup/bin/drain_queue.py — the 5-minute webhook drainer — imports only load_config, backup_root from ghb_common and reads both files raw:

  • drain_queue.py:217 — state = json.load(open(state_path)) with no shape check.
  • drain_queue.py:227 — planned = {p["repo"] for p in json.load(open(plan_path))} subscripts every plan entry unguarded, before any event is processed.

Crash sites on wrong-shape (valid JSON) input:

  • Plan entry "o/r1" (string) → TypeError: string indices must be integers; entry 123 → TypeError: 'int' object is not subscriptable; top-level dict → same string-indices error. The planned set never builds, so no queued event is fetched, acked, or even logged — every 5-minute drain tick re-crashes identically until plan.json is hand-fixed.
  • State top-level [] → AttributeError: 'list' object has no attribute 'get' at drain_queue.py:275 (state.get(key, 0)).
  • drain_last::<repo> as a string or dict → TypeError: unsupported operand type(s) for -: 'float' and 'str' at drain_queue.py:275 (now - state.get(key, 0)). This is the drainer's OWN key: validate_state already validates drain_last::* as a non-bool number and drain_fail::* as an object (ghb_common.py, 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) — the drainer is the one consumer that never calls it.
  • drain_fail::<repo> as an int or string, on a fetch failure → state.setdefault(fkey, {...}) at drain_queue.py:288 returns the poisoned value, then fs["count"] += 1 raises TypeError: 'int' object is not subscriptable / string indices must be integers. The failure is never counted, the DRAIN-CHRONIC escalation never fires, state.json is never rewritten, and the event's ack decision is lost with the run.

Probe (laptop, ~/git/fleet/probe-ghb-drain-plan-state/probe.py, real drain_queue.main from origin/main with config/root/queue stubbed to temp files and one queued event for a planned repo; fetch stubbed only where noted):

  • Control (valid plan + {} state) → rc=0, event fetched+acked.
  • Plan entry string / int / top-level dict → the three TypeErrors above.
  • State top-level list → AttributeError; drain_last string/dict → TypeError at the coalesce subtraction.
  • drain_fail int/string with fetch returning "fail" → TypeError at the failure counter; drain_fail dict control → rc=0, consecutive_failures=2 recorded correctly.

Why it matters

The drainer is the estate's highest-frequency consumer (every 5 minutes) and the only path that turns webhook events into fetches. A single poison entry in plan.json or state.json — hand edit, older/newer writer, torn write per #3240 — wedges every tick: mirrors stop reflecting pushes, the Worker queue grows unbounded, and because the crash precedes all logging/acking, the failure presents as silence rather than an alarm. The irony is load-bearing: the shared validators were extended in #6637 specifically to cover the drainer's drain_last::/drain_fail:: key shapes, and fetch/clone/manifest all use them — the drainer itself is the remaining bypass, the same pattern as #6831 (reconcile's previous-plan read) but in the live event path.

Distinct from: #6575 (queue EVENT shape inside the drainer — validated separately), #6831 (reconcile.py's previous-plan read), #6637 (built the validators + fixed fetch), #6821 (fetch's last_fetch arithmetic on validated state). None touches drain_queue's plan/state loading.

Acceptance criteria

  • drain_queue.main loads plan and state through ghb_common.load_plan / load_state (or equivalent validation with report_problems), so a wrong-shape entry is named on stderr and skipped/reset instead of crashing the tick.
  • With a poisoned plan entry, the drainer still processes events for the valid planned repos (fetch/ack/coalesce behavior unchanged) and prints its JSON summary.
  • With a wrong-shape drain_last::<repo> or drain_fail::<repo>, the entry is reported and treated as absent (coalesce window not applied / failure count starts fresh), state.json is rewritten clean at the end of the run, and the DRAIN-CHRONIC path still works for genuine repeated failures.
  • Regression tests in infra/github-backup/tests/ cover the probed shapes (string/int plan entry, dict top-level plan, list top-level state, string/dict drain_last, int/string drain_fail) against the real drain_queue.main, plus the valid controls; the existing github-backup suite stays green.

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-07 00:20 CST
    • Found via: filed this run
    • Task: drain_queue.py is the one github-backup consumer bypassing the 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 shared gates: bare json.load for state (:217) and plan (:227), so a wrong-shape plan entry crashes the planned-set build before any event is processed, a non-dict state / string drain_last crashes the coalesce subtraction (:275), and a non-dict drain_fail crashes the failure counter (:288) — even though validate_state already validates exactly those drain_* key shapes for the other consumers. Verified with the real drain_queue.main from origin/main e380645 on the laptop (probe ~/git/fleet/probe-ghb-drain-plan-state).
    • Expectation: effort/s small-fix — load plan/state via ghb_common.load_plan/load_state with report_problems, regression tests; queued for the repo worker.
    • Links: packet creator-b-2026-11-07-0020/packet-6835-small-fix.json (goal hidden_files)
  4. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · picked up

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

  7. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · correction

  8. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · picked up

  9. 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 8, 2026
  10. added a commit that references this issue on Nov 8, 2026
  11. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 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 jobtask/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