Repository navigation
fix(cold-store-reaper): bound repair_dump candidate buffer (#6525) - #8415
Conversation
…r-cap statements through (#6525) A candidate INSERT INTO sqlite_schema statement whose terminating line never arrives was buffered whole, so the documented constant-memory filter grew to the size of the remaining dump and emitted nothing until EOF. A candidate is now capped at MAX_CANDIDATE_BYTES (8 MiB default, REPAIR_DUMP_MAX_CANDIDATE_BYTES override). Past the cap the buffered lines are flushed unchanged and the rest of the statement streams through line by line with an explicit flush per line (stdout block buffering alone would hold it back); the statement end is still recognised, so the following statement is processed normally. An over-cap statement is not repaired - repair requires holding it - which matches the filter existing pass-through of anything it cannot verify. Tests: over-cap candidate streams byte-identical and the following broken statement is still repaired; over-cap candidate emits output before EOF with stdin held open. Full cold-store-reaper suite: 158 tests OK.
|
Warning Review limit reachedYou'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 55 minutes. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0fcd1e3a37
ℹ️ 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".
…sed on the terminating line (#6525) Codex P2 on PR #8415: the over-cap flush set passthrough=True unconditionally, so when a candidate first exceeded MAX_CANDIDATE_BYTES on its own terminating line, the FOLLOWING statement streamed through unrepaired even if below the cap and in need of quote repair. The flushed chunk is now checked with the same boundary test (ends_statement) and pass-through is enabled only when the candidate has not ended. Adds test_cap_crossed_on_terminating_line_does_not_leak_passthrough (fails on the unfixed code, passes with the fix); full test_export_turso suite 18/18.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 956bd24561
ℹ️ 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".
| if line.rstrip(b"\r\n").endswith(STATEMENT_END) and ends_statement( | ||
| line, next_line |
There was a problem hiding this comment.
Preserve statement-boundary detection in pass-through mode
If a correctly escaped multiline candidate crosses the cap before its terminating line and a blank line follows the completed statement, pass-through mode never recognizes that boundary. Calling ends_statement with only the terminating line loses its valid-literal parsing path because that line does not start with SCHEMA_INSERT, and the blank lookahead also fails its fallback check. A subsequent broken schema INSERT is therefore emitted unrepaired, causing the rebuild in scripts/export-turso.sh to fail. Preserve enough parsing state to recognize valid statement completion independently of the next line, without retaining the entire over-cap statement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 35aa1b7 (lane tmp-code-t, task 14417).
You were right: in pass-through mode the terminating line was tested with ends_statement() alone -- its valid-literal path needs the statement head (a lone terminating line does not start with SCHEMA_INSERT), and a blank following line fails its top-level fallback, so the boundary was never recognised and the next statement streamed through unrepaired.
Fix: pass-through now preserves exactly the parsing state you named, in O(1) -- a _LiteralTracker fed every streamed byte (seeded from the flushed buffer, or the over-cap first line for the single-line entry) tracks SQL string-literal state, where a '' pair inside a literal is an escaped quote and a lone ' closes it. A terminating line now ends pass-through when the tracker is outside a literal, OR-ed with the existing ends_statement() fallback so mis-escaped candidates (whose literal state is unparseable by design) keep their old boundary test. The over-cap statement itself is still never retained.
Regression test: test_over_cap_valid_candidate_end_recognised_before_blank_line -- correctly escaped over-cap candidate, terminating line, blank line, then a broken schema INSERT that must be repaired. Verified it fails on the pre-fix code and passes now; full cold-store-reaper suite 160 tests OK (1 skipped).
… own bytes (#6525) Codex P2 on PR #8415 (round on 956bd24): in pass-through mode the terminating line was tested with ends_statement() alone, whose valid-literal path needs the statement head -- a lone terminating line has none, and a blank following line fails its top-level fallback, so a correctly escaped over-cap candidate followed by a blank line never ended pass-through and the next statement streamed through unrepaired. Pass-through now feeds every streamed line to an O(1) _LiteralTracker (seeded from the flushed buffer / over-cap first line) that tracks SQL string-literal state ('' = escaped quote) and recognises the end from the statement's own bytes, OR-ed with the existing ends_statement fallback for mis-escaped candidates. Regression test test_over_cap_valid_candidate_end_recognised_before_blank_line fails on the old code and passes now; full cold-store-reaper suite 160 tests OK (1 skipped).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35aa1b7ee3
ℹ️ 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".
| filler = (b"x" * 100 + b"\n") * 100 # 10 KB, no terminator line | ||
| data = opener + filler + b"');\n" + b"\n" + BROKEN_SCHEMA_INSERT | ||
| expected = opener + filler + b"');\n" + b"\n" + ESCAPED_SCHEMA_INSERT | ||
| self.assertEqual(self.run_filter_capped(data, 4096), expected) |
There was a problem hiding this comment.
Add property-based coverage for the streaming parser
The new literal tracker and capped-buffer transitions introduce a parser/state machine, but the added coverage consists entirely of fixed examples. This violates AGENTS.md's explicit requirement to cover meaningful parser/state-machine invariants with property tests rather than examples alone. Add generated statements with varied escaping, line boundaries, and cap positions, asserting that over-cap statements remain byte-identical and subsequent below-cap statements are still repaired; the existing buffered parser can serve as a boundary-detection oracle for correctly escaped statements.
AGENTS.md reference: AGENTS.md:L41-L45
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8a110d6 (lane tmp-code-t, task 14417).
Added property-based coverage per the repo testing doctrine (AGENTS.md L41-45) and the pkgs/deploy precedent: pkgs/cold-store-reaper/tests/test_repair_dump_property.py is a stdlib seeded generator (no hypothesis in this repo's Python tooling; fixed seed 6525, 300 cases) that generates correctly escaped statements with varied escaping, line boundaries, interior boundary-bait lines (lines ending in ');, lines that parse standalone as complete schema INSERTs, comment lines), blank lines after the statement, and cap positions from 64 bytes to just under the statement size. The oracle is a by-construction model: the over-cap statement passes byte-identical and the following below-cap broken statement is repaired to its escaped form. The one documented heuristic outside the model (a candidate ends where a new top-level statement follows) is excluded by construction and named in the docstring.
Oracle check: 43 of the 300 generated cases fail on the pre-fix head 35aa1b7; all 300 pass now. Full cold-store-reaper suite: 162 tests OK (1 skipped).
| if line.rstrip(b"\r\n").endswith(STATEMENT_END) and ( | ||
| tracker.outside_literal or ends_statement(line, next_line) |
There was a problem hiding this comment.
Avoid parsing an interior line as a standalone statement
For a correctly escaped over-cap schema INSERT, this fallback can end pass-through while the tracker is still inside the outer literal. For example, a SQL block comment inside a CREATE TABLE definition can contain INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql) VALUES(1,2,3,4,''''); followed by a blank line: ends_statement(line, next_line) parses that embedded line independently and returns true. A later comment line containing the same INSERT prefix with VALUES(1,2,3,4,''X''); is then treated as a new repair candidate, causing quote rewriting inside the otherwise valid outer statement and breaking the SQLite rebuild. Previously, boundary detection examined the complete outer candidate. Restrict this fallback to lookahead/EOF detection rather than standalone parsing of the current interior line.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8a110d6 (lane tmp-code-t, task 14417).
You were right: OR-ing ends_statement() let its valid-literal path parse the current interior line standalone, ending pass-through while the outer literal was still open. The pass-through end test now uses only the tracker (outside-literal, from the statement's own bytes) OR the lookahead half of ends_statement -- factored out as _next_line_starts_new() and shared by both: next line starts a new top-level statement, or EOF. The current line is never parsed standalone in pass-through mode.
Regression: test_over_cap_interior_insert_line_is_not_a_boundary builds exactly your shape (interior line that parses as a complete schema INSERT, blank line, later interior INSERT-prefixed line, tail below the cap so repair_chunk would run on it). Verified it fails on 35aa1b7 (the later line's quotes were doubled: ''X'' became '''X''') and passes now. Full suite 162 tests OK (1 skipped).
…only; add property coverage (#6525) Codex round on 35aa1b7, two findings: (P2) the pass-through end test OR-ed ends_statement(), which parses the current line standalone -- an interior line that itself parses as a complete schema INSERT ended pass-through while the outer literal was still open, and a later interior INSERT-prefixed line was then repaired as a new candidate, corrupting the valid outer statement. The fallback is now restricted to its lookahead half (_next_line_starts_new, shared with ends_statement): tracker-outside-literal OR next-line-starts-new OR EOF -- never a standalone parse of the current line. Regression: test_over_cap_interior_insert_line_is_not_a_boundary (fails on 35aa, passes now). (P1) property-based coverage per the repo testing doctrine: tests/test_repair_dump_property.py, stdlib seeded generator (seed 6525, 300 cases) varying escaping, line boundaries, interior boundary-bait lines, blank lines and cap positions, with a by-construction model oracle (over-cap valid statement byte-identical + following broken statement repaired). 43 of 300 cases fail on 35aa; all pass now. Full cold-store-reaper suite: 162 tests OK (1 skipped).
Fixes #6525 — repair_dump: bound the candidate buffer
repair_dump.pyis documented as a constant-memory streaming filter, but a candidateINSERT INTO sqlite_schema(statement whose terminating line never arrived was buffered whole — memory grew to the size of the remaining dump and nothing was emitted until EOF.MAX_CANDIDATE_BYTES(8 MiB default;REPAIR_DUMP_MAX_CANDIDATE_BYTESoverride for tests/operators). Real schema statements are orders of magnitude smaller.Tests (in
TestDumpRepairFilter, subprocess against the real script):Full
pkgs/cold-store-reapersuite: 158 tests OK (1 skipped).Agent: queue worker lane code-m, task 14417.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.