Skip to content

cold-store-reaper: Drive API response bodies are parsed unguarded — a wrong-shape 200 from files.list / files.create / files.get raises raw Attribute/Key/Type/Value/JSONDecode errors, not ColdStoreError #6855

Closed

Description

@dezren39

cold-store-reaper: Drive API response bodies are parsed unguarded — a wrong-shape 200 from files.list / files.create / files.get raises raw Attribute/Key/Type/Value/JSONDecode errors, not ColdStoreError

Summary

pkgs/cold-store-reaper/cold_store.py treats every Google Drive API response body as if it were the exact JSON object the happy path returns. Only HTTP status is checked; the parsed body's shape never is. A 200 response whose body is valid JSON of the wrong shape (or not JSON at all) crashes the caller with a raw builtin exception instead of the module's own ColdStoreError, so the CLI surfaces a traceback and — worse — upload() dies after the bundle has been uploaded and marked uploading, with no verification verdict recorded.

The module already knows the right pattern: put_backup's identical files.get verification readback wraps its parse in try/except (KeyError, TypeError, ValueError) and re-raises its verification_failed ColdStoreError (cold_store.py:1196-1204). The Drive call sites below never got the same guard. This is the Drive-API sibling of #6846 (token endpoints, cold_store.py:667/708) and #6845 (local state/credentials files); the D1 surface was guarded earlier (#2618). Umbrella: #3068.

Unguarded sites (all at main 65beb42)

  • _find_folder (cold_store.py:735): files = json.loads(resp).get("files", []), then files[0]["id"].
  • _create_folder (cold_store.py:750): return json.loads(resp)["id"].
  • _resumable_upload (cold_store.py:988): file_id = json.loads(resp)["id"] on the 200/201 chunk-completion response.
  • upload verification readback (cold_store.py:1066-1068): info = json.loads(resp); drive_size = int(info.get("size", -1)) — compare the guarded twin in put_backup at :1196-1204.
  • list_backups (cold_store.py:1257-1267): page = json.loads(resp); page.get("files", []); per entry f["id"], f["name"], int(f.get("size") or 0).
  • get_backup (cold_store.py:1431-1435): same .get("files", []) + files[0]["id"] pattern as _find_folder.

Verified this run (laptop probe, real cold_store.py verbatim, stubbed transport, @65beb42c1a)

Probe: ~/git/fleet/probe-cold-store-drive (cold_store.py + schema.sql copied verbatim, http_request stubbed, controls pass). Results:

Call Wrong-shape 200 body Observed
_find_folder control {"files":[{"id":"abc"}]} / {} — returns "abc" / None
_find_folder ["x"] or "hello" raw AttributeError: 'list'/'str' object has no attribute 'get'
_find_folder {"files":"abc"} raw TypeError: string indices must be integers
_find_folder {"files":[123]} raw TypeError: 'int' object is not subscriptable
_find_folder {"files":[{"name":"n"}]} raw KeyError: 'id'
_find_folder not json raw JSONDecodeError
_create_folder control {"id":"new1"} — returns "new1"
_create_folder {} raw KeyError: 'id'
_create_folder ["x"] raw TypeError: list indices must be integers
list_backups control (one well-formed file entry) — returns the entry
list_backups ["x"] (page) raw AttributeError: 'list' object has no attribute 'get'
list_backups {"files":["abc"]} raw TypeError: string indices must be integers
list_backups {"files":[{"name":"n","size":"1"}]} raw KeyError: 'id'
list_backups {"files":[{"id":"f1","name":"n","size":"abc"}]} raw ValueError: invalid literal for int()
get_backup {"files":"abc"} raw TypeError: string indices must be integers
upload readback (real pack()-seeded bundle, _resumable_upload stubbed) ["x"] raw AttributeError: 'list' object has no attribute 'get'
upload readback {"size":"abc","md5Checksum":"x"} raw ValueError: invalid literal for int()
upload readback not json raw JSONDecodeError
upload readback control (correct size + md5) — returns verified: True

Why it matters

  • Every one of these paths is on the nightly backup/restore route: ensure_folders (via _find_folder/_create_folder) runs before uploads, list_backups feeds retention planning in prune_backups, and get_backup is the restore path. A proxy error page, a partial/truncated body, or an API change returning an error object with a 200 turns a diagnosable ColdStoreError into an unhandled traceback that names no endpoint and no expectation.
  • upload() is the worst case: the bundle row is already uploading and the bytes are already in Drive when the readback parse crashes, so the run dies mid-verification — neither verified nor failed — exactly the state ambiguity put_backup's guarded readback (and its trash-on-failure cleanup) was built to avoid.
  • The inconsistency itself is the trap: a reader who checks put_backup reasonably concludes Drive readbacks are guarded everywhere.

Acceptance criteria

  • Every Drive response parse listed above validates the parsed shape (object at top level; files a list of objects; id/name present strings; size numeric) and raises ColdStoreError naming the operation and what was wrong — no raw AttributeError/KeyError/TypeError/ValueError/JSONDecodeError escapes a Drive call site.
  • upload()'s verification readback gets the same treatment as put_backup's: an unparseable/wrong-shape readback is a verification failure (ColdStoreError), not a crash after upload.
  • Well-formed responses behave exactly as today (existing FakeDrive test suite passes unchanged in behavior).
  • New tests in pkgs/cold-store-reaper/tests/test_cold_store.py cover the wrong-shape bodies above for folder find/create, list_backups, get_backup, and the upload readback, asserting ColdStoreError (oracle: the guarded put_backup readback at cold_store.py:1196-1204).

Activity

  1. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  2. added
    queue/queued
    source/creator
    task/small-fix
    status/needs-triage
    priority/normal
    app/cold-store-reaper
    kind/bug
    effort/s
    on Nov 7, 2026
  3. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  5. added
    work/assigned
    queue/claimed
    and removed
    status/needs-triage
    queue/queued
    on Nov 8, 2026
  6. 34 remaining items

  7. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off to opencode claimant

  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off (task 11081, lane code-u)

  9. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off to opencode claimant — Agent: queue worker (repo-worker-code), lane code-w — Session/ID: task 11081, repo-queue-worker-shift-w 2026-11-10 run. Task 11081 (small_fix) for issue #6855: cold-store-reaper: Drive API response bodies are parsed unguarded — a wrong-shape 200 from files.list / files.create / files.get raises raw Attribute/Key/Type/Value/JSONDecode errors, not ColdStoreError; attempts 4/4 on this claim. Fresh check: issue #6855 OPEN, no held/user/owned/do-not-merge/do-not-auto-edit labels, no status/needs-triage. Execution lane row 3552 = opencode. Checkpointed handed_off (handoff reason: scheduled shift is time-bounded; claimant is the persistent execution session); parking task 11081 for 20 minutes for the claimant window.

  10. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  11. added 2 commits that reference this issue on Nov 10, 2026
  12. removed
    status/parked
    queue/parked
    work/assigned
    on Nov 10, 2026
  13. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — task 14672 fixed_merged (lane code-l, 2026-11-10)

  14. added
    priority/low
    and removed
    priority/normal
    on Nov 11, 2026
  15. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done)

    Verified already done on fresh reads: PR #7135 "fix(cold-store): validate Drive response shapes (#6855)" MERGED 2026-11-10T22:38:26Z (shepherded by task 14672, lane code-l), and issue #6855 is CLOSED with status:done. No duplicate work opened. Task 11081 completes as already_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/cold-store-reapereffort/skind/bugpriority/lowsource/creatorstatus:donetask/small-fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions