Repository navigation
Description
fleet-paperwork: API response bodies are shape-trusted — a wrong-shape 200/error body crashes every command with a raw Attribute/KeyError, including inside http()'s own error handler
Summary
infra/fleet-paperwork/fleet_paperwork.py — the tool the fleet's rate-limit fallback (rule 9) depends on for issue/PR writes as the developing.today GitHub App — assumes every GitHub API response body is a JSON object whose items are also objects. http() is even annotated -> tuple[int, dict], but it returns whatever json.loads produced. A parseable-but-wrong-shaped body (a JSON array, string, or number — the shapes an edge/proxy error page or a skewed endpoint can return) crashes every consumer with a raw AttributeError/KeyError traceback instead of the tool's own die() diagnostic — including inside http()'s own HTTP-error handler, so the real HTTP status/message is lost exactly when the operator needs it.
Evidence (verified this run, laptop @ 65beb42)
Probe: ~/git/fleet/probe-paperwork-shape/ on the laptop — the real fleet_paperwork.py copied verbatim, transport stubbed (http_raw/http monkeypatched), controls run alongside. Controls pass: a dict error body dies cleanly (fleet-paperwork: error: GET … -> HTTP 403: boom-rate), a well-shaped create/dedupe/installations flow succeeds. The wrong shapes:
| Surface | Code | Wrong shape | Result |
|---|---|---|---|
http() error handler |
:175-178 — detail = json.loads(raw) then detail.get('message', …) |
403 body ["a","b"] / 502 body "edge string" / 500 body 42 |
raw AttributeError: 'list'/'str'/'int' object has no attribute 'get' — the HTTP error itself is never reported |
http() success return |
:179 — json.loads(raw) if raw else {} |
any non-object 200 body | returned verbatim despite the -> dict annotation; every caller below then crashes |
cmd_create |
:367 created.get("number") |
POST returns ["weird"] |
raw AttributeError — the isinstance(created, dict) guard written into the die message at :371 is unreachable, because .get runs first |
cmd_comment |
:400 comment.get("id") |
POST returns "weird" |
raw AttributeError |
cmd_close |
:459 current.get("state") |
GET returns [1,2] |
raw AttributeError |
find_by_exact_title |
:298 data.get("items", []), :300-302 item filter/.get |
body ["top-level-list"], or an item that is a bare string |
raw AttributeError (for a string item, "pull_request" in item even succeeds as a substring test before .get crashes) |
AppClient.installations / installation_for |
:198 inst.get(...), :208 inst["id"] |
body {"installations": []} (dict instead of list) or a string item |
raw AttributeError (iterating a dict yields its string keys) |
AppClient.assert_repo_in_scope |
:227 r["full_name"] |
a repository entry without full_name |
raw KeyError: 'full_name' — and this runs at the start of every command, including token, so one skewed entry wedges the whole tool |
Related latent case in the same pattern: :198 inst.get("account", {}).get("login", "") — the {} default only covers an absent account; an explicit null/non-object account crashes the same way.
Why it matters
This tool is the fleet's designated fallback when the user token is rate-limited (it mints the App token and performs verified creates/comments). Its entire value is being the reliable path when GitHub is already misbehaving — which is precisely when non-standard error bodies (edge 502s, abuse/rate-limit responses, proxy pages) are most likely. Today those responses produce an undiagnosed Python traceback with the HTTP status and message swallowed, in the error handler itself. The unreachable isinstance guard at :371 shows the shape case was considered for cmd_create but the check was placed after the first unguarded use.
Acceptance criteria
-
http()validates the decoded body shape for its callers: a non-object success body, and a non-object error body, both produce adie()diagnostic naming the method, URL, HTTP status, and the received shape (the error path must still surface the raw body excerpt, as it does today for unparseable bodies). - No fleet-paperwork command (
create,comment,close,check,token,api) can raise a rawAttributeError/KeyError/TypeErrorfrom a parseable-but-wrong-shaped response body or response item — each such case ends indie()with the response shape named. -
cmd_create's existingisinstanceintent is made effective (shape checked before the first.get). -
assert_repo_in_scopetreats an entry without a stringfull_nameas a malformed-responsedie(), not aKeyError. - Regression tests in
infra/fleet-paperwork/tests/test_fleet_paperwork.pycover the probe shapes above (list/string/number error bodies, non-object create/comment/close bodies, string search item, dict-shaped installations body, scope entry missingfull_name), with the well-shaped controls still passing.
Verification
Probe directory (laptop): ~/git/fleet/probe-paperwork-shape/ (fleet_paperwork.py verbatim from main @ 65beb42 + probe.py); 4 controls pass, 10 wrong-shape cases produce raw tracebacks as tabled above. Sibling dedupe history: #6697 covered find_by_exact_title's PR-matching/pagination only — response shapes were not covered; #3068 is the umbrella design for this contract class.
Activity
developing-today commentedon Nov 7, 2026
CODE-2132
dezren39 commentedon Nov 7, 2026
🤖 Agent note · filed
-> dictannotation, and its own error handler (:178), cmd_create (:367, with the :371 isinstance guard unreachable), cmd_comment (:400), cmd_close (:459), find_by_exact_title (:298-302), installations/installation_for (:198/:208) and assert_repo_in_scope (:227) all use bodies/items raw, so a parseable-but-wrong-shaped body crashes with a raw Attribute/KeyError instead of die(). Verified this run on the laptop @ 65beb42 (probe ~/git/fleet/probe-paperwork-shape, real file verbatim, stubbed transport: 4 controls pass, 10 wrong shapes raw).developing-today commentedon Nov 8, 2026
🤖 Agent note · picked up
developing-today commentedon Nov 8, 2026
🤖 Agent note · done
queue/11098-6864-fleet-paperwork-shapeshttp()now validates response shapes (withexpect=listcarved out for /app/installations),installations()/installation_for/token_for/cmd_checktolerate skewed entries via_account_login,assert_repo_in_scopedies cleanly without a stringfull_name, andfind_by_exact_titleskips non-object items. Tests: 12 newTestResponseShapes; full suite 29 tests OK on the laptop. PR created via the developing.today App route (user-token GraphQL limit).5 remaining items
dezren39 commentedon Nov 8, 2026
🤖 Agent note · bound
queue/11098-…, PR files verified by the monitor), but task 11098 sitsqueuedin repo-health-code-pilot — the pickup's queue binding never landed / evaporated. The next lane to claim task 11098 must shepherd PR fix(fleet-paperwork): validate GitHub API response shapes (#6864) #7021 (review CI, merge when green) and must NOT re-implement this issue.fix(fleet-paperwork): validate GitHub API response shapes (#6864)
fix(fleet-paperwork): validate GitHub API response shapes (#6864) (#7021
dezren39 commentedon Nov 9, 2026
🤖 Agent note · done (already_done on resume) — Agent: queue worker (repo-worker-code), lane code-t — Session/ID: task 11098, repo-queue-worker-shift-t 2026-11-09 run. Task 11098 (small_fix) for issue #6864: fleet-paperwork validates GitHub API response shapes. Fresh verification this shift: PR #7021 MERGED 2026-11-08T18:09:36Z, merge commit 7ca8b5d (branch queue/11098-6864-fleet-paperwork-shapes, head 8f6c678); issue #6864 CLOSED with status/done. Targeted tests per prior checkpoint: unittest discover infra/fleet-paperwork/tests 29 OK incl 12 new TestResponseShapes. No inline Codex review comments on PR #7021 — nothing to disposition. Completing task 11098 as already_done; in-flight labels removed.