Skip to content

cold-store: repair filter for libsql /dump's unescaped virtual-table schema literals (#1391) - #1398

Merged
dezren39 merged 2 commits into
mainfrom
cold-store-turso-dump-quirk
Oct 27, 2026
Merged

dezren39 merged 2 commits into
mainfrom
cold-store-turso-dump-quirk

Conversation

@dezren39

@dezren39 dezren39 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What

Implements the workaround documented in #1391: a streaming repair filter between the Turso /dump download and the sqlite3 -bail rebuild in scripts/export-turso.sh.

libsql registers virtual tables via INSERT INTO sqlite_schema(...) inside a writable_schema block, emitting the embedded SQL verbatim — single quotes (an FTS5 content='chunks' is the common case) are not doubled, so the literal terminates early and every stock SQLite parser fails with near "chunks": syntax error. Any database with a quoted virtual-table definition (found live on atlas, 2026-10-27) could never be filed.

How

  • New scripts/repair_dump.py: a line-oriented, constant-memory filter (buffers only the current candidate statement, which ends at a line ending in ');). All lines pass through byte-identical except INSERT INTO sqlite_schema(...) statements whose final SQL literal is verifiably mis-escaped — parse-based detection: the literal, read with proper '' escaping, must close exactly at the statement's final quote; if it closes early or never closes, the raw SQL between the opening quote and the closing '); is re-emitted with every ' doubled, and the rewrite is re-parsed before being emitted (anything that does not verify passes through unchanged). Correctly-escaped statements and quote-free SQL pass through untouched.
  • export-turso.sh: download → repair filter → truncation guard (now applied to the filtered stream; the filter passes the trailing COMMIT; through undisturbed) → sqlite3 -bail rebuild → integrity/≥1-user-table checks, exactly as cold-store: harden turso export for GB-class databases #1383 left them. Per-DB failure isolation unchanged.

Tests

  • TestTursoExportScript (fake-server): a new atlas-shaped fixture — FTS5 external-content table registered by the exact broken writable_schema INSERT, plus its shadow tables and real FTS index rows — files successfully; the built .db has the virtual table in sqlite_master with its SQL exactly as authored, and a fresh-connection MATCH 'hello' returns the seeded row. A correctly-escaped variant files with identical registered SQL.
  • TestDumpRepairFilter (unit): broken literal → exactly the doubled-quote form; correctly-escaped, quote-free, and unrelated input byte-identical; an unterminated statement at EOF flushes unchanged for the caller's truncation guard.
  • Full pkgs/cold-store-reaper suite green; shellcheck shows only the pre-existing SC2310 infos; shfmt -i 2 -s and ruff format clean.

Refs #1391


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner October 27, 2026 11:09
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 47af0d10-7a87-4805-9178-772bc761acac
Commits

Reviewing files that changed from the base of the PR and between 452d69e and 57a6aab.

Files selected for processing: 4
  • pkgs/cold-store-reaper/scripts/export-turso.sh
  • pkgs/cold-store-reaper/scripts/repair_dump.py
  • pkgs/cold-store-reaper/tests/test_cold_store.py
  • pkgs/cold-store-reaper/tests/test_export_turso.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T11:12:56.507119Z 57a6aab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 9f86ddb into main Oct 27, 2026
4 checks passed
@dezren39
dezren39 deleted the cold-store-turso-dump-quirk branch October 27, 2026 11:11

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57a6aabf5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +152 to +154
if line.lstrip().startswith(SCHEMA_INSERT):
if line.rstrip(b"\r\n").endswith(STATEMENT_END):
out.write(repair_chunk(line))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track SQL literal boundaries before recognizing schema inserts

When a text column contains multiline SQL, this check can mistake a line inside the dumped data literal for a schema statement and rewrite it. For example, dumping a text value containing a newline followed by INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES("table","t","t",0,'CREATE VIRTUAL TABLE t USING fts5(x)'); produces a valid dump, but this filter changes the escaped quotes around the embedded CREATE statement and restoration then fails with near "CREATE": syntax error. Because the filter now runs on every export, previously exportable databases containing such text lose their backups. Track whether the stream is inside a string literal or another statement before treating a line as a repair candidate.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant