Skip to content

cold-store-reaper(repair_dump): an unterminated sqlite_schema candidate is buffered whole — the 'constant-memory' filter grows to the size of the remaining dump #6525

Closed

Description

@dezren39

Summary

pkgs/cold-store-reaper/scripts/repair_dump.py — the streaming repair filter between the libsql /dump download and the sqlite3 rebuild in scripts/export-turso.sh — is documented as constant-memory, but a candidate INSERT INTO sqlite_schema( statement whose terminating line never arrives is buffered in full, without any bound, so the filter's memory grows to the size of the remaining dump and nothing is emitted until EOF.

Evidence (file:line, origin/main 6b9e1ec081ac)

  • The promise: repair_dump.py:22-25 — "The filter is line-oriented and constant-memory: it buffers only the lines of one candidate statement (which ends at a line ending in ');)"; export-turso.sh:187-191 repeats it: "streams the dump (constant memory, one statement buffered)".
  • The code: repair_dump.py:142-161 (main). Once a line starts with INSERT INTO sqlite_schema( and does not end in ');, every later line is appended to buffered (:146-151) until a line ending in '); appears; there is no size cap, no spill, and no flush-through. The accumulated list is only joined and emitted at the terminator (:149) or at EOF (:159-160).

Verification (laptop probe, this run)

Probe ~/git/fleet/probe-repair-dump/ (driver2.py) against the real script exported from origin/main 6b9e1ec081ac, stdin held open while measuring stdout and RSS:

  • Control — 32 MiB of ordinary lines: streamed through; 33,488,896 B already on stdout before EOF; RSS 13,148 KiB.
  • Unterminated candidate — the same 32 MiB after one INSERT INTO sqlite_schema(... 'CREATE TABLE t ( line with no '); line: 0 B on stdout before EOF; RSS 47,604 KiB (≈ the full 32 MiB input held in memory, +34 MB over the control). Output after EOF is byte-identical (33,554,534 B, rc 0) — the failure is memory, not correctness.
  • Functional controls on the real script: a verifiably mis-escaped FTS5 schema literal is repaired (quotes doubled), and an unterminated statement at EOF flushes unchanged — both pass, matching the existing TestDumpRepairFilter expectations.

Why it matters

The filter sits in the Turso export path (export-turso.sh:191) precisely so large dumps can be processed without holding them in memory — the same package's recent #6233 work bounded memory when Drive ignores Range requests. A dump whose schema statement is cut or re-shaped so its terminator line never matches (truncated/corrupt download, a libsql format change such as trailing whitespace after ');, or a genuinely huge multi-line schema statement) turns the "constant-memory" filter into a whole-dump buffer: on the backup host that is an avoidable OOM risk in the one job whose job is keeping backups restorable, and it fails silently — output stays byte-correct, just unbounded. This is the same shape as the fleet-proxy single-line head bound filed as #6511 (check exists, but only after the unbounded accumulation).

Acceptance criteria

  • A candidate statement that exceeds a stated, generous bound (well above any real schema statement) is no longer accumulated without limit: e.g. flush the buffered lines through unchanged and resume line-oriented passthrough, or another design that keeps peak memory independent of the remaining dump size.
  • Byte-identical output is preserved in every currently-correct case: mis-escaped literals still repaired, valid literals untouched, unterminated-at-EOF still flushed unchanged (existing TestDumpRepairFilter in tests/test_export_turso.py passes unchanged).
  • A new regression test in TestDumpRepairFilter pins the bound: an unterminated candidate larger than the bound produces output before EOF / bounded memory, with the full stream still byte-identical end-to-end.
  • The docstring and the export-turso.sh comment match the implemented bound (name the cap).

Filed by the new-issue-creator (lane A) after verification this run; not a duplicate of #1391 (the original mis-escaping quirk this filter works around) — this is the filter's own memory contract.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 6, 2026
  2. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  3. added
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/cold-store-reaperPackage/app: cold-store-reaper (pkgs/ or apps/ in this repo)
    on Nov 6, 2026
  4. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 6, 2026
  6. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  7. 181 remaining items

  8. added
    status/parkedDeliberately paused with a recorded resume condition
    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 11, 2026
  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Agent note — lane tmp-code-t, task 14417 — DONE fixed_merged

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-reaperPackage/app: cold-store-reaper (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions