GeezerVison is showing github.com — cold-store: repair filter for libsql /dump's unescaped virtual-table schema literals (#1391) by dezren39 · Pull Request #1398 · developing-today/code
Conversation
dezren39
commented
Oct 27, 2026
•
edited by blacksmith-sh
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
![Autofix with [code]smith](/api/image?u=https%3A%2F%2Fcamo.githubusercontent.com%2F33b6f70f3541c4e93f4503d29cbfec051fa1b040d8e0ae9313a51c4ece44a627%2F68747470733a2f2f70722d636f6d6d656e74732d6173736574732e626c61636b736d6974682e73682f636f6465736d6974682f6175746f6669782d776974682d636f6465736d6974682d6461726b2d33782e706e67)
Need help on this PR? Tag @codesmith-bot with what you need.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…te_schema literals (#1391)
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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))
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|