Repository navigation
Description
Problem
The github-backup queue Worker's two authenticated drainer endpoints parse JSON with no shape guard, so a malformed request or a single corrupt queue entry crashes the handler (an unhandled throw in a Worker = a bare 500) or, worse, reports a successful ack that deleted nothing / the wrong keys.
File: infra/github-backup/worker/src/index.js (verified on main 8a5cd8ea75)
1. POST /queue/ack — the request body is shape-trusted (:87-88)
const { ids } = await req.json();
const keys = (ids || []).map((id) => "ev:" + id);Verified with the real file verbatim (probe ~/git/fleet/probe-ghb-worker-ack, node v24, stubbed KV; control {ids:["a","b"]} → 200 {acked:2}, deletes ev:a,ev:b):
| Body | Result today |
|---|---|
null |
throws TypeError: Cannot destructure property 'ids' ... as it is null |
non-JSON (not json) / empty body |
throws SyntaxError from req.json() |
{"ids":"abc"} / {"ids":123} |
throws TypeError: (ids || []).map is not a function |
top-level array ["a","b"] |
200 {"acked":0} — a fake success: the caller's ids are silently dropped, nothing is deleted |
{"ids":[123,null]} |
200 {"acked":2} — deletes the wrong keys ev:123 / ev:null and reports success for ids that never existed |
{} (missing ids) |
200 {"acked":0} — indistinguishable from a legitimate empty ack |
The ack is the drainer's delete path (infra/github-backup/bin/drain_queue.py ack_events, :86-97): events are acked only once the mirror reflects them (#3219 discipline), so an ack response that lies about what it deleted undermines the one signal the drainer has that the queue actually shrank.
2. GET /queue — one corrupt KV value crashes every poll (:76)
if (v) events.push(JSON.parse(v));Verified: with one stored value not-json{, GET /queue throws SyntaxError and returns nothing — every event on the page is lost to the drainer, and because listing is what feeds the ack path, the corrupt entry can never be acked away through the API. The values are normally written by this Worker's own webhook handler (:46-52, whose JSON.parse is guarded — the in-file twin), but KV is shared, mutable state: a manual edit, a future writer, or a partial write leaves a permanent poison pill in the queue. This is the Worker-side mirror of the drainer-side poison pill in #6575.
The existing test suite (infra/github-backup/worker/test/index.test.mjs) covers only well-shaped ack bodies ({ids:["a","b","c"]}) and well-formed KV values — none of the cases above.
Why it matters
- A malformed ack (a buggy/manual caller, a truncated request) produces an opaque 500 instead of a 400 the caller can act on.
- The top-level-array and non-string-id cases are worse than a crash: they return 200 with a count that does not describe what was deleted, so a drain can believe events were retired when they were not (or that foreign keys were).
- One corrupt KV entry wedges the whole queue for the drainer: no listing, no acking, no self-healing path through the API.
Acceptance criteria
-
POST /queue/ackwith a non-JSON, empty, JSON-null, or non-object body returns a 4xx with a clear error message; no exception escapes the handler and no KV delete is attempted. -
POST /queue/ackwithidsmissing, not an array, or containing a non-string/empty entry returns a 4xx naming theidsfield; a well-formed{ids:[...]}behaves exactly as today (bulk-chunked deletes,{acked: n}). - An ack response's
ackedcount always equals the number of keys actually deleted. -
GET /queuewith one corrupt (non-JSON) KV value does not lose the whole page: either the well-formed events are returned with the corrupt key named/signalled in the response, or the endpoint fails with an error naming the corrupt key — never a bareSyntaxError500. (Either disposition is acceptable; silently dropping the entry without any signal is not.) - New cases in
infra/github-backup/worker/test/index.test.mjscover: null body, non-JSON body, stringids, top-level array body, non-string id entries, and a corrupt KV value onGET /queue; the existing 5 tests still pass.
Activity
developing-today commentedon Nov 7, 2026
CODE-2147
dezren39 commentedon Nov 7, 2026
🤖 Agent note · state: filed
dezren39 commentedon Nov 8, 2026
🤖 Agent note · state: picked-up
1 remaining item
dezren39 commentedon Nov 8, 2026
🤖 Agent note · state: handed-off
dezren39 commentedon Nov 8, 2026
🤖 Agent note · state: parked
dezren39 commentedon Nov 9, 2026
🤖 Agent note · blocked — already done