Skip to content

cold-store-reaper(repair_dump): a multi-line schema statement is terminated by the first interior line ending in ');' — the fragment is rewritten as the whole statement and the tail passes through raw #6531

Closed

Description

@dezren39

cold-store-reaper(repair_dump): a multi-line schema statement is terminated by the first interior line ending in '); — the fragment is rewritten as the whole statement and the tail passes through raw

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 — decides where a multi-line INSERT INTO sqlite_schema(...) candidate ends purely by line shape: the first buffered line ending in '); is taken as the statement's end. A schema object's SQL can itself contain such a line (a CREATE TRIGGER whose body has a statement ending in a string literal, e.g. SELECT RAISE(ABORT, 'bad');, is the natural case — SQLite stores the CREATE text as written, newlines included). When that happens the filter splits the statement at the interior line, "repairs" the fragment as if it were the whole statement, and passes the remaining lines through unfiltered — corrupting the filtered dump so the sqlite3 rebuild fails, where the identical statement on one line repairs and loads correctly.

Evidence (file:line, origin/main 2bcd46e0dc)

  • repair_dump.py:142-161 (main): once a line starts with INSERT INTO sqlite_schema(, every later line is appended to buffered (:147) until a line ending in STATEMENT_END (b"');", :33) appears (:148), at which point the joined chunk is emitted through repair_chunk. Nothing checks that the accumulated text is actually one complete statement — the line shape is the only terminator test.
  • repair_dump.py:90-128 (repair_statement): the fragment verifies as a "complete" statement — its final literal, after quote-doubling, parses exactly to the chunk end with ");" remaining (:124-127) — because the fragment genuinely is indistinguishable from a complete statement whose SQL is just the fragment. The rewrite therefore fires on the fragment.
  • The docstring (:22-25) states the assumption outright: it "buffers only the lines of one candidate statement (which ends at a line ending in ');)" — the assumption is the bug: a line ending in '); inside the embedded SQL is not the statement's end.

Verification (laptop probe, this run)

Probe ~/git/fleet/probe-repair-dump-earlyflush/probe.py against the real script at origin/main 2bcd46e0dc. Input (the final value's SQL spans two lines; line 1 ends in '); via the trigger body's RAISE(ABORT, 'bad');):

PRAGMA writable_schema=ON;
INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES('table','ft','ft',0,'CREATE TRIGGER tr AFTER INSERT ON ft BEGIN SELECT RAISE(ABORT, 'bad');
 INSERT INTO log VALUES('x'); END');
PRAGMA writable_schema=OFF;

Filtered output — the first line is emitted as a complete, rewritten statement (note ''bad'), the tail line passes through raw:

INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES('table','ft','ft',0,'CREATE TRIGGER tr AFTER INSERT ON ft BEGIN SELECT RAISE(ABORT, ''bad');
 INSERT INTO log VALUES('x'); END');

Oracle (stock sqlite3 load of the filtered stream, the same rebuild export-turso.sh performs): FAILS — the orphaned tail executes as a top-level statement (OperationalError: no such table: log) and the schema row that does land carries only the truncated first line of the trigger SQL. Control: the identical statement on a single line is repaired by the same filter and loads cleanly (schema row ft present). Filter exit code is 0 in both cases — the corruption is silent.

Why it matters

This filter is the Turso export path's only defense against the libsql mis-escaping quirk (#1391); its output feeds a sqlite3 -bail rebuild of the only portable backup. A dump containing a multi-line trigger (or any schema SQL with an interior '); line end) is silently mangled: the rebuild either dies (backup export fails) or, worse, a truncated schema statement lands in the restored database. Distinct from #6525 (same file: an unterminated candidate is buffered whole — a memory failure with byte-identical output); this is the opposite terminator failure — termination too early — and it breaks correctness, not just memory.

Acceptance criteria

  • A candidate statement is not terminated by an interior line ending in '); when more of the statement follows: the two-line probe statement above (and equivalents) is repaired as one statement and the filtered stream loads in stock sqlite3 with the full schema SQL intact.
  • 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 case: a multi-line schema statement whose embedded SQL contains an interior line ending in '); round-trips through the filter and a sqlite3 rebuild.
  • The docstring's statement-end description matches the implemented termination rule.

Filed by the new-issue-creator (lane A) after verification this run; not a duplicate of #1391 (the mis-escaping quirk) or #6525 (the same filter's unbounded-buffer memory issue — this one terminates too early and corrupts output).

Activity

  1. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    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
  3. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

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

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  6. 12 remaining items

  7. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: OpenChamber scheduled lane (repo-worker-code, lane aea12c82-c5af-4e5a-9b66-f8e360f87177)
    • Session / ID: task 11206
    • Task: small_fix; worktree ~/git/fleet/queue-11206, branch queue/11206-6531-repair-dump-early-flush.
  8. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  9. added a commit that references this issue on Nov 8, 2026
  10. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    Triage verdict (2026-11-07): already done — fix landed while this triage was in flight.

  11. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    Review evidence: diff matches the issue's intent (statement end is now decided by parsing the buffered literal / next-top-level-statement, not line shape alone; docstring updated); new tests cover the two-line trigger statement in both mis-escaped and correctly-escaped forms with a stock sqlite3 load oracle; CI on the PR was green (basic: scripts-test 3.12 and 3.14 SUCCESS); no Codex review findings were posted on PR #6543; the PR's documented known limit (a mis-escaped statement whose interior '); line is followed by an unindented continuation line) is recorded in its body and remains a theoretical remainder, not a blocker for the reported case.

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