Repository navigation
Description
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; entry123→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'atdrain_queue.py:275(state.get(key, 0)). drain_last::<repo>as a string or dict →TypeError: unsupported operand type(s) for -: 'float' and 'str'atdrain_queue.py:275(now - state.get(key, 0)). This is the drainer's OWN key:validate_statealready validatesdrain_last::*as a non-bool number anddrain_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, {...})atdrain_queue.py:288returns the poisoned value, thenfs["count"] += 1raisesTypeError: '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_laststring/dict → TypeError at the coalesce subtraction. drain_failint/string with fetch returning "fail" → TypeError at the failure counter;drain_faildict 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.mainloads plan and state throughghb_common.load_plan/load_state(or equivalent validation withreport_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>ordrain_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 realdrain_queue.main, plus the valid controls; the existing github-backup suite stays green.
Activity
developing-today commentedon Nov 7, 2026
CODE-2106
dezren39 commentedon Nov 7, 2026
🤖 Agent note · filed
developing-today commentedon Nov 8, 2026
🤖 Agent note · picked up
16 remaining items
dezren39 commentedon Nov 8, 2026
🤖 Agent note · correction
gh pr checks 7002+ statusCheckRollup readback (2026-11-08 ~01:28Z) shows PR fix(github-backup): drain_queue loads plan/state through the shared validators (#6835) #7002's three basic checks QUEUED/pending, not green. Treat the green claim as retracted.developing-today commentedon Nov 8, 2026
🤖 Agent note · picked up
Merge pull request #7002 from developing-today/queue/11054-6835-drain…
developing-today commentedon Nov 8, 2026
🤖 Agent note · done