Repository navigation
Description
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 withINSERT INTO sqlite_schema(, every later line is appended tobuffered(:147) until a line ending inSTATEMENT_END(b"');",:33) appears (:148), at which point the joined chunk is emitted throughrepair_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
TestDumpRepairFilterintests/test_export_turso.pypasses unchanged). - A new regression test in
TestDumpRepairFilterpins 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
developing-today commentedon Nov 6, 2026
CODE-1983
dezren39 commentedon Nov 6, 2026
🤖 Agent note · filed
');is split at that line — the fragment is quote-doubled and emitted as the whole statement, the tail passes through raw, and the filtered stream fails the stock sqlite3 rebuild (control: the identical statement on one line repairs and loads cleanly). Distinct from issue 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 (same filter, unterminated-candidate memory growth; output byte-identical there).');line; existing TestDumpRepairFilter cases stay byte-identical.dezren39 commentedon Nov 6, 2026
🤖 Agent note · handed off
12 remaining items
dezren39 commentedon Nov 6, 2026
🤖 Agent note · picked up
repo-worker-code, laneaea12c82-c5af-4e5a-9b66-f8e360f87177)dezren39 commentedon Nov 6, 2026
🤖 Agent note · done
repo-worker-code, laneaea12c82-c5af-4e5a-9b66-f8e360f87177)Fixes #6531); full cold-store-reaper tests pass locally.dezren39 commentedon Nov 8, 2026
🤖 Agent note · picked up
Merge pull request #6543 from developing-today/queue/11206-6531-repai…
dezren39 commentedon Nov 8, 2026
🤖 Agent note · done
');'line) at current main.Triage verdict (2026-11-07): already done — fix landed while this triage was in flight.
ends_statement()inpkgs/cold-store-reaper/scripts/repair_dump.pynow ends a candidate only when the buffered text parses as a complete statement or the next line begins a new top-level statement (or EOF); docstring updated to match; regression tests inTestDumpRepairFilterpin the interior-');'case with a stock-sqlite3 load oracle.dezren39 commentedon Nov 8, 2026
🤖 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.