Repository navigation
ADFA-7304: SQLite debugger execute returns RETURNING rows and binds named args - #2332
davidschachterADFA wants to merge 61 commits into
Conversation
Phase 2, P2-1 (ADFA-7131 comments 41476, 41477, 41489). - The record header grows from 56 to 72 bytes with rows and changes; every earlier field keeps its offset. SQLITEDBG_INTERFACE_VERSION 3. - PROFILE events carry the rows the statement returned and, for a statement that may write, its own change count (sqlite3_changes64, or 0 when sqlite3_total_changes64 did not move, so a CREATE TABLE does not report the previous write's count). -1 for a read. - New SQLITEDBG_EVENT_ROW: the first N rows of each statement, while a client is connected and sqlitedbg_set_row_capture is on. Off by default; nothing turns it on yet (the server will, ADFA-7297). - Each value is read with the accessor of its own type. Reading every column with sqlite3_column_text turns a BLOB into TEXT for the app. - Up to 16 statements per connection are followed from start to PROFILE. Rows of a statement not seen start are dropped, which drops SQLite's own nested statements (a CREATE TABLE's schema read). - EventDecoder.kt decodes the new header and row data; Event gains rows, changes, rowsCut and row, with defaults. - Fixture regenerated; README documents the layout and the limits. Tests: test.sh passes (ASan+UBSan, TSan, JNI 205). EventDecoderTest, DatabaseToolsTest and McpProtocolTest pass (108), compiled with the Kotlin compiler outside Gradle. Revert proofs: reading every column as text fails test_rows (BLOB read back as TEXT); recording rows with no slot fails test_internal_rows; plain sqlite3_changes64 fails test_changes. Not run here: Gradle, spotlessCheck, the Robolectric tests, and overhead on a phone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
spotlessKotlinCheck failed on 67355bd (the hand-off expected ktlint to reflow): braces around the multi-line `when` branches in EventDecoder.kt and a chained `containsExactly` in EventDecoderTest.kt. Formatting only, from `spotlessApply`; `git diff -w` changes no tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ut of memory record_row passed p to utf8_cut before its `if (!p)` guard. sqlite3_column_text returns NULL when SQLite runs out of memory (for example when it cannot add the NUL terminator), while sqlite3_column_bytes can still return the value's length; for a TEXT value longer than the limit, utf8_cut then read through the NULL pointer, inside the app's own sqlite3_step, and the app crashed. Before ADFA-7296 the extension never read column values, so the path was new. stored is now 0 whenever p is NULL, for TEXT and BLOB. No test: it needs SQLite to fail an allocation at that exact point, which the host tests cannot arrange. test.sh passes (with the next commit): ASan+UBSan 20745 checks, TSan 20726, JNI 205, 0 failures (system JDK). CodeRabbit thread 4691490650. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…eader's batch sqlitedbg_read_events stops at the first record that doesn't fit its buffer, and the server reads 256 KiB at a time (DatabaseTools. EVENT_BATCH_BYTES). sqlitedbg_set_row_capture accepted any max_row_bytes, and a row record was bounded only by half the ring (2 MiB by default), so a large setting could make one record no reader can receive, and every event after it would wait until the ring evicted it. Nothing sets the limit yet (default 4 KiB), so this guards a future setting. SQLITEDBG_MAX_ROW_BYTES (64 KiB) in sqlitedbg.h caps it; a larger value is lowered to it. The tests' ring is 8 KiB, which caps a row first, so a test-only getter (SQLITEDBG_TEST, like sqlitedbg_test_fail_init) shows the limit in force: UINT32_MAX becomes 64 KiB, 1000 stays, 0 is 4 KiB. Revert proof: with the cap removed, test_row_limits fails with "sqlitedbg_test_max_row_bytes() == SQLITEDBG_MAX_ROW_BYTES (4294967295 vs 65536)"; restored, test.sh passes: ASan+UBSan 20745 checks, TSan 20726, JNI 205, 0 failures (system JDK). CodeRabbit thread 4691490645. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ng rows The README said the per-row cost "has not been measured on a phone yet". It now gives the Galaxy J7 numbers from the native benchmark in #2311's description (no client: +1.1 us for a 20-row SELECT, +0.6 us for a one-row SELECT over ade5cc2; about 2.9 us per recorded row), and the 64 KiB cap on a row's data from the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The README still listed the ring buffer's trace events as statement, profile and close, and said SQLITEDBG_INTERFACE_VERSION is 2. This change added row events and raised the version to 3 (sqlitedbg.h). Both lines now say so; the version line keeps why it became 2. Checked against sqlitedbg.h (SQLITEDBG_INTERFACE_VERSION 3, SQLITEDBG_EVENT_ROW). No code change. CodeRabbit review 6053222300, outside-diff comment (README.md:20, 49) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…th check
The malformed-row test patched an integer's stored_bytes to 4 but left
full_bytes at 8, so decodeRow refused it at the cut check (stored <
full with cut 0) and never reached the 8-byte width check for numbers.
The test passed with the width check removed.
The case now sets both stored_bytes and full_bytes to 4 and asserts the
width check's message ("number 0 is 4 bytes"), so only that check can
refuse it. Revert proof: with the width check removed, "a malformed row
is refused" fails; restored, it passes. testDebugUnitTest and
spotlessCheck pass.
CodeRabbit review 6053222300, nitpick (EventDecoderTest.kt:162)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Stage gained five PRs since ade5cc2: #2291 (ADFA-4654), #2292 (ADFA-7134), #2283 (ADFA-6945), #2293 (ADFA-7247, ADFA-7243) and #2298 (ADFA-7201). No conflicts, and no file changed on both sides. This PR's own diff is unchanged: the +/- lines of `git diff ade5cc2 4f971a8` and `git diff origin/stage HEAD` are identical, in the same 9 files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…column types Phase 2, P2-2 (ADFA-7131 comments 41476, 41477). On P2-1 (#2311, at e16ea45). - get_events: a profile event carries rows, changes (null for a read) and rows_cut; a row event carries row_number, column_count, values, storage_classes and cut_values. get_events turns row recording on (new DebugEngine.setRowCapture, JNI setRowCapture): 10 rows per statement, values cut at 256 bytes, a row at 4 KiB. include_rows false turns it off and leaves row events out; it also goes off with the idle client and when the server stops. - query and explain_query_plan: args as an object binds by name (:name, @name, $name, ?NNN; a key with or without its prefix). Names go to JNI as UTF-8 and are matched against sqlite3_bind_parameter_name: every parameter needs a value and every key a parameter. The array form is unchanged. - query returns column_types (sqlite3_column_decltype, null for an expression) and storage_classes, a letter per cell (i r t b n): JSON writes REAL 2.0 as 2, and big integers as strings. - BLOBs are {hex, bytes, truncated}; they were base64. No client reads the old key (AI-Agent-MCP passes results through). - Tool descriptions say what is capped; README updated. Limit: execute (P2-3, #2312) still binds positional args only; the second of the two PRs to merge wires its names. Tests: test.sh passes (ASan+UBSan, TSan, JNI 279 checks: each name form, the five refusals, declared types, the row-recording switch). DatabaseToolsTest, McpProtocolTest and EventDecoderTest pass (118), compiled with the Kotlin compiler outside Gradle, including an encoding of every event in P2-1's fixture. Revert proofs: no unused-name check fails "named: a misspelt name"; no decltype fails "declared types"; no idle switch-off fails rowRecordingStopsWithTheIdleClient; no row filter fails getEventsTurnsRowRecordingOnUnlessToldNotTo. Not run here: Gradle, spotlessCheck, a device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
spotlessKotlinCheck's two changes to DatabaseTools.kt: the named-args key chain on one call per line, and one blank line dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The args description said every key could be written without its prefix, but only :name, @name and $name match a bare name (key_matches): {"1": 5} for ?1 fails with "no value was given for parameter ?1". The text now says a ?NNN key keeps its ?, as the README already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
It described bind_args, which bind_positional and bind_value replaced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
spotlessKotlinCheck failed on DatabaseToolsTest.kt with one max-line-length error, reported at L1. ktlint joins kinds()'s expression body onto its signature line, and the joined line is 142 columns. Its other changes were then not applied either, so the file also needed ktlint's wrapping of the named-args call and of a four-call chain. kinds() now has a block body. Two long assertions are wrapped, and the row-values check reads values.get(c) once, before its when, so each branch stays on one line. Production code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The cloud session's ffb3f18 drops a stale comment above bind_value in sqlitedbg_jni.c (one line). P2-6 (ADFA-7301) already merges it, so the two branches keep the same ancestry. No conflicts; nothing else changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
bind_named stopped at the first parameter with no value, before it
looked for keys that matched no parameter. So args {"idx": 1} against
"WHERE id = :id" failed with "no value was given for parameter :id",
and the misspelt key was never named (seen on the J7, ADFA-7297
comment 41611).
It now binds every parameter that has a value, then reports a key that
matched nothing first, together with the parameter left without a
value: "the statement has no parameter named idx, and no value was
given for parameter :id". A parameter left out with no stray key, and a
stray key with every parameter bound, keep their messages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…eff47b0) The base for ADFA-7304, which needs P2-2 and P2-3/P2-4; neither has landed (David, 2026-11-26). Conflicts, each side kept: - sqlitedbg.c: P2-2's sqlitedbg_set_row_capture beside P2-3's PRAGMA allowlist and writable authorizer. - sqlitedbg_jni.c: P2-3's prepare_bound calls P2-2's bind_named or bind_positional (which checks the count itself, as prepare_bound did); bridge_query passes its names; execute stays positional for now. - DebugEngine.kt: P2-2's setRowCapture beside P2-3's openServerConnection doc. - DatabaseTools.kt: P2-3's withConnection with P2-2's Bind; execute refuses object args (its schema still says array), so an object's values are never bound by position; the Room check passes Bind.NONE. - README: the JNI test list names both PRs' cases. At the merge: test.sh 0 failures (JNI 480); DatabaseToolsTest, McpProtocolTest and EventDecoderTest pass (131). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
The item left for whichever of #2312 and #2319 merged second (41592): execute takes args as an array or an object, through the same prepare_bound, bind_named and argsSchema as query. - JNI execute gains names ([[B); bridge_execute passes them to prepare_bound. ServerConnection.execute gains argNames. - The execute tool's args schema is argsSchema(), and the merge's refusal of an object is gone. README updated. Tests: JNI binds INSERT ... VALUES(:id, @s) by name and refuses a misspelt key with SQLITE_RANGE, writing nothing; executeBindsAnObjectByName. test.sh 0 failures (JNI 488); JVM 132. Revert proof: execute ignoring names fails "each value went to its own parameter", "execute ran with a misspelt name" and "and the row is still there". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
…y's limits
execute ran a statement's RETURNING rows to the end and dropped them.
Now they come back in query's format (P2-2's: column types, storage
classes, hex BLOBs) within the same limits: max_rows (default 100, at
most 1000), the 4 MiB budget with the first row whole, cut cells
listed, has_more. No offset: paging would run the write again.
From the experiments (41621): SQLite makes every change and buffers
every returned row in the first sqlite3_step, so
- a statement stopped at a limit is reset, which commits all of it, and
changes counts every row written; a failed commit at the reset is the
call's error ("could not be committed, and nothing it changed was
kept"; the rollback backstop ends the open transaction);
- a statement that fails at any step, even while its rows come back, is
rolled back whole, so execute returns the error and no rows.
- C: bridge_query's row loop moves into read_rows, which both use.
bridge_execute takes query's limits and returns [columns, rows,
counts, decltypes, {changes, last_insert_rowid}].
- Kotlin: ServerConnection.execute takes QueryLimits; ExecuteResult has
rows. The tool gains max_rows and returns the rows only for a
statement with RETURNING. Description and README updated.
Limit (README): if the JVM fails to allocate a row mid-read, the
unfinished statement is finalized, which commits it while the call
reports the error.
Tests: JNI returningCaps:
- INSERT RETURNING id;
- UPDATE past a 3-row cap (3 rows, has_more, changes 50, all 50
updated);
- the byte budget (first row only);
- a wide row cut;
- DELETE RETURNING cut short (all deleted);
- a failed commit at the reset (SQLITE_BUSY, nothing kept);
- the 1.5 s limit striking while 400,000 rows come back (first step
about 0.5 s; SQLITE_INTERRUPT, nothing kept).
DatabaseToolsTest executeReturnsReturningRowsAsQueryDoes. test.sh 0
failures (JNI 564); JVM 133.
Revert proofs:
- returning rows on error fails "every row of a write past the time
limit came back";
- ignoring the reset's rc fails "a write whose commit failed returned
rows".
Not run here: Gradle, spotlessCheck, a device.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
… change ktlint wraps two long call chains in the new execute tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The case filled its 400,000-row table and ran its timing call through execute, which stops any write after 1.5 s. With Gradle building alongside, the setup UPDATE's first step passed 1.5 s and the JNI suite aborted (review F02). The table is now filled on the app's connection, which has no time limit. If the timing call is itself stopped, the case prints a note and skips the stop-after-rows check instead of aborting. Checked both ways: on a quiet machine the stop-after-rows check runs (JNI 578 checks, no note); with the table made ten times bigger, the first step passes 1.5 s and the case takes the note path and passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The tool text, DebugEngine, the README and a C comment said a statement that fails "returns no rows and keeps nothing". Under FAIL conflict resolution (OR FAIL, ON CONFLICT FAIL, RAISE(FAIL)) SQLite keeps, and in autocommit commits, the rows changed before the failing one (review F01; checked on 3.49.1: ABORT, ROLLBACK and their RAISE forms keep none and leave sqlite3_total_changes64 where it was; FAIL moves it, and sqlite3_changes64 is the number kept). bridge_execute now adds "The N rows it changed before the failure were kept: FAIL conflict resolution keeps them" to the error when the total moved, and the texts say so. The README's accepted limit now covers any allocation failure during or after the read, not only a row's (F03). Tests: a JNI case with INSERT OR FAIL ... RETURNING (code 19, 2 rows kept and counted) and a default ABORT one (nothing kept, nothing claimed); DatabaseToolsTest checks the new tool text. Revert proofs: with the old C, the JNI case fails on the kept-rows message; with the old tool text, DatabaseToolsTest fails on the missing sentence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
FakeDebugEngine.readEvents still counted a 56-byte header, but this PR grew the record header to 72 bytes (EventDecoder.HEADER_BYTES), and it counted a ROW event's SQL, which is empty, instead of its values (#2311 review, 2026-11-26). No test failed, as none sized a batch to the byte. The fake now uses EventDecoder's header and row sizes, made internal for it, and a new test checks that its batches end where the C layer's records in events.bin do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…gger/ADFA-7297 Brings in the #2311 review fix (the fake engine sizes records as the native ones). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
A ROW record with columns = kept = Int.MAX_VALUE passed the kept <= columns check, and ArrayList(kept) then threw OutOfMemoryError before the first value's check could refuse the row, instead of the documented IllegalArgumentException (CodeRabbit, #2311, 2026-11-26). Each kept value takes at least ROW_VALUE_BYTES, so kept is now checked against the row's length before the list is sized. Rows the C layer writes always pass. Without the check, the new test's row throws "OutOfMemoryError: Requested array size exceeds VM limit", and the build's -XX:+ExitOnOutOfMemoryError ends the test JVM (exit 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…gger/ADFA-7297 Brings in the #2311 review fix (EventDecoder refuses a row count its bytes cannot hold). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…e-debugger/ADFA-7304 Brings in #2313 (which includes #2312's head): the busy handler for execute, the lock-aware cap (start_cap_once_locked) and the recheck of the deadline after prepare. Conflicts and how each was resolved, keeping both sides' intent: - subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c - deadline struct: took #2313's new fields (db, cap_ms, slept_ms, busy_hit...). Every initializer now names its fields ({.db = db, .at_ms = ...}), including bridge_query and bridge_execute, which this branch changed and git did not flag. - busy_cb (#2313) kept beside this branch's bind_value / bind_positional / bind_named. - read_rows, prepare_bound(..., names, ...) and the RETURNING row reading kept from this branch; #2313's execute loop that dropped rows was not taken. - bridge_query: this branch's read_rows call, with #2313's cap (dl.cap_ms set, counted from when the lock is held) replacing the old at_ms/capped block. - bridge_execute: #2313's recheck of the deadline after prepare, its cap_ms and sqlite3_busy_handler(busy_cb), its busy_hit message ("waiting for another connection ... Try it again"), its SQLITE_BUSY handling in the plain time-limit branch, and its busy_timeout restore at done; kept this branch's has_more reset and its FAIL-resolution message ("The N rows it changed before the failure were kept"). The order of the error branches is: busy_hit, capped interrupt, plain time limit (interrupt or busy), FAIL rows kept, any other error. - subprojects/sqlite-debugger/src/main/java/.../engine/DebugEngine.kt: the execute KDoc is this branch's (RETURNING rows, FAIL) with #2313's wording on the cap (held the lock, waiting to commit included; a deadline passing during prepare stops it). - subprojects/sqlite-debugger/README.md: "Read-only" and "time limits" bullets from #2313 (this branch did not change them); the "execute writes" bullet is this branch's with its closing sentences on the cap and busy handler replaced by #2313's; the event cursor bullet is this branch's (interface version 3 from #2319). - subprojects/sqlite-debugger/src/test/jni/JniQueryTest.java: the cap test uses #2313's sentinel-table SQL and comments with this branch's execute signature (names, limits). Not flagged by git but changed to compile: #2313's executeAsync called the old 4-argument NativeBridge.execute, so it now goes through run(...) and counts(...). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…e-debugger/ADFA-7304 Brings in #2319's newer commits, including #2311's EventDecoder row-count check. No conflicts: git merged FakeDebugEngine.kt automatically. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…d step A statement cut at a row limit is reset to commit it. When the commit waited on an app reader until the cap, the call got SQLITE_BUSY and no advice, while the same stall in a step reported SQLITE_INTERRUPT with 'Try it again'. The reset path now uses the same classification (throw_if_stopped), and still reports 'nothing it changed was kept' for other failures. The done: path now finalizes before restoring busy_timeout, so the commit an unfinished statement makes in finalize (after an allocation failure) is bounded by busy_cb. The README says so. This path cannot be tested: it needs a JNI or SQLite allocation failure. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… time limit that must strike The commit stopped at the cap is checked for SQLITE_INTERRUPT and the advice (fails without the previous commit: 5 vs 9). RETURNING with OR ROLLBACK, OR IGNORE and OR REPLACE is covered. The time-limit-after-rows case times its first step, halves the table while that takes over 1 s, and fails instead of passing when it cannot reach the path. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The execute description lacked CUT_CELLS_NOTE, which query and explain_query_plan include, though execute returns the same fields. The description test checks it (fails without), and the RETURNING test also checks the column of truncated_cell_indexes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…xecute test 4d02e99 put its "read them with query" check in the query test, where `d` doesn't exist, so the test source didn't compile; it belongs beside the execute description's other checks. The pinned "cannot be paged" becomes "or paged (that would write again)", as F08's rewording reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Brings #2311's fixes for CodeRabbit's #2332 findings (unread huge values, changes -1 for an unfinished statement, slot kept across SQLITE_BUSY, uncounted cut rows). One README conflict: #2311 rewrote three lines of "Rows and changes" and added a line; this branch had changed only the ROW line (get_events turns recording on). Kept both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
@coderabbitai on the two comments in your review body (6121675022):
@hal-eisen-adfa CodeRabbit's review of b9ccfc7 had 13 findings: five fixed in this PR, five fixed in #2311 (which owns that code) and merged here, one follow-up ticket and two accepted.
|
|
Tip For best results, initiate chat on the files or code changes. Analysis chain
I checked the source and documentation at Would you like a follow-up issue for the metadata race? Learnings added
Learnings used
You are interacting with an AI system. |
Brings #2311's fixes for CodeRabbit's findings on #2332 up the stack (CLAUDE.md: a fix lands in the lowest PR, then merges up). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn # Conflicts: # subprojects/sqlite-debugger/README.md
From a fresh review of the write-outcome reporting (#2332 review R01-R06): - A transaction left open on the server connection (a way past the authorizer, then a refused rollback) is rolled back before execute runs its statement. Before, the write ran inside it, the call reported it written, and the backstop after it rolled it back. - The out-of-memory outcome error is always SQLITE_NOMEM. With finalize's code (an interrupt, say), the tool appended "retry it" to an error that says the write may not have been committed. - A statement that failed before its result could be built reports its own error (a constraint, say), not the allocation failure. - A commit that fails at the row-limit reset says nothing was kept only for a lock, a constraint, a full disk or an interrupt; after an I/O error or corruption it says the change may not have been kept. - The KDoc and the tool note say the error tells whether the write was committed or may not have been. Tests: a seam in the JNI test build (SQLITEDBG_TEST, never in the app's build) fails read_rows as a JNI allocation would, on a column named sqlitedbg_test_oom_names, _row or _result. JniQueryTest covers a write committed at a row and after the last step, nothing claimed before the first step, a failed statement's own error, a failed commit at finalize (an app reader holds SHARED past the cap; SQLite rolls the write back), and a write after a transaction left open. Each fails without its fix: reverting the first three fixes fails 3 checks, and dropping the outcome report fails 3 others. The I/O-error wording has no test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
Hal, one more commit for your review, acd87a1: fixes from a fresh review of what
|
The backstop rolls back a transaction left open after each query, not before it. So a query that starts inside one (a way past the authorizer, then a refused ROLLBACK) reads in that transaction's snapshot, which in WAL mode can be stale, for that one call. Documented as accepted: queries run on the read-only connection, so the transaction holds no uncommitted writes. execute rolls one back first (#2332, acd87a1), where a write was at stake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn # Conflicts: # subprojects/sqlite-debugger/README.md
…ze too From the cloud session's review of acd87a1 (optional nits): - When reading RETURNING rows ran out of memory and the commit at finalize then failed, the error always said the write "may not have been committed". For a lock, a constraint, a full disk or an interrupt SQLite rolls the statement back (sqlite3VdbeHalt calls sqlite3RollbackAll), so it now says nothing was kept, as the row-limit reset already did, and a retry is safe. Both paths share commit_failure_rolled_back(). The I/O-error branch keeps the hedge (not testable here). - README: test.sh builds libsqlitedbg.so as it ships plus the SQLITEDBG_TEST seam. The failed-commit JNI check now expects "nothing it changed was kept"; acd87a1's text fails it. test.sh 0 failures (23,037 / 23,036, JNI 690). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
Hal, two more commits:
|
…id field Layout only. The record header grows from 72 to 80 bytes: execution_id, a uint64_t at offset 72. Interface version 3 to 4. add_record and add_event take the id and return the record's seq; every caller passes 0 here, so EventDecoder reads Event.executionId as null for now. EventDecoder.HEADER_BYTES is 80 and the fixture is regenerated with an 11th column. Tests: offsetof and sizeof asserts in the C test, the decoder reads offset 72, and a record with a 72-byte header is refused. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ILE events Rows of statements stepped interleaved on one connection could not be told apart. A STATEMENT's execution_id is its own seq; the slot keeps it, and the ROW and PROFILE events of the run carry it. 0 means none or unknown. Three guards keep a slot left behind at an address from being taken for another statement's: - a PROFILE for an EXPLAIN (traced with no STATEMENT) releases the slot and gets id 0 and rows -1; - a ROW whose sqlite3_sql is NULL (a schema read) is ignored; - a statement an app function runs inside a callback (traced as "-- " plus its own text) releases the slot at its address and gets id 0. Trigger STATEMENTs carry 0. Tests cover interleaved rows, re-runs, triggers, RETURNING, nested statements, EXPLAIN, BUSY resume, a client connecting mid-run, CLOSE, slot eviction and threads. README: the id's meaning, the PROFILE caveats (EXPLAIN, BUSY: more than one PROFILE per id), the eviction gap and the record size. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…MA rerun When SQLite re-prepares a statement after SQLITE_SCHEMA it fires no second STATEMENT, so the rerun's PROFILE got id 0 and its rows were lost. A PROFILE with no rows that is not busy now leaves its slot, marked ended; a later ROW or PROFILE counts for it only if SQLITE_STMTSTATUS_REPREPARE has grown since the STATEMENT, else the slot is released and the event has no id. claim_slot takes an ended slot before the least recently used live one, so finished 0-row statements do not evict live cursors. The REPREPARE check is defence in depth: the EXPLAIN and nested-statement guards catch every event with no STATEMENT first, so no test fails without it. The retry tests (a SELECT after another connection's DDL and after CREATE TABLE on the same connection, a 0-row write, BUSY then SCHEMA) do fail without the ended slot. README: the retry paragraph. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
EventDecoderTest.kt from the execution id tests: spotlessKotlin wants braces and blank lines in a when. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…FA-7297 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
#2311 (b9a3129, merged in the previous commit) gives each event record an execution_id: a STATEMENT event's own seq, and on that run's PROFILE and ROW events the same number. get_events now returns it on every event, null when unknown (a trigger's statements, close, a statement whose start was not seen), so an agent can tell apart the rows of two statements stepped in turn on one connection. The tool description and the README say what it means, and that a run can have more than one profile (a retry after a schema change) or none at its end. Tests: DatabaseToolsTest's fixture test checks execution_id on every decoded event (the fixture's ROW events carry ids); JniQueryTest checks that a recorded row's execution_id is the seq of a STATEMENT record in the buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…and execution_id in get_events) into ADFA-7304 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn # Conflicts: # subprojects/sqlite-debugger/README.md
|
Hal, 69dd43b merges #2319 at 8760dc0: #2311's ADFA-7379 (an execution id on events) and |
A trigger step is traced as "-- " + its text with P the running outer statement. When that text equals the outer statement's own (a trigger on t whose step is the UPDATE that fired it), the nested-statement check took the step for an app statement run in a callback and cleared the outer statement's live slot. Its PROFILE then had execution id 0, rows -1 and changes -1. The connection now remembers the statement whose "-- TRIGGER" trace came last, skips the clear for that statement, and forgets it at the statement's next STATEMENT or PROFILE. A new test fires an UPDATE trigger whose step repeats the UPDATE and checks the PROFILE's id, rows and changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
A PRAGMA (or another non-read-only statement that is not DML) stepped across another statement's INSERT found the connection's total changed and reported sqlite3_changes64, which then held the INSERT's count. The PROFILE now reports sqlite3_changes64 only for a statement whose own SQL starts with INSERT, UPDATE, DELETE, REPLACE or WITH, after whitespace and comments (a small helper reads sqlite3_sql). Otherwise, when the total moved, it reports -1. A total that did not move still means 0. The header and README say so. New tests step PRAGMA journal_mode once, run a 3-row INSERT, and finish the PRAGMA, whose changes must be -1; a WITH ... INSERT keeps its real count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…w-cut docs Eviction: a statement evicted from its slot keeps its id on its STATEMENT and on the ROW events recorded before the eviction. Its later rows are not recorded at all, and only its PROFILE has 0. The header, the README and the test comment said the later ROW events had 0. The eviction test now asserts that statement 0's ROW has exec_id equal to its STATEMENT's seq. README: each ROW trace now makes one extra sqlite3_sql call, and that cost was not re-measured (it said the per-row path was unchanged). The stale claim that the interface version is 3 is gone; sqlitedbg.h has the current value. The limits note that in a UTF-16 database sqlite3_column_bytes converts a whole TEXT value before the 1 MiB guard, and the code comment no longer says it never copies. Behaviour is unchanged. ROWS_CUT and Event.rowsCut also cover a row the producer could not record (a byte budget below a row header, or an allocation failure), not only the per-statement row limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
In a UTF-16 database, recording rows converts each TEXT value to UTF-8 in full before the 1 MiB guard applies, so a large value costs its full size in memory and time. Android's own databases and Room use UTF-8. The decision is to document this and not change the behaviour, so the README now states it as an accepted limit instead of "not fixed yet". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The SQL of a PROFILE is cut at the test's 64-byte limit and keeps a leading comment, so the earlier WITH ... INSERT case never found its event. It now uses a shorter statement that fits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…'s STATEMENT id EventDecoder now requires full_bytes to equal stored_bytes for INTEGER and FLOAT, and zero for NULL. The producer never cuts these, so a record that says otherwise is malformed. A new test feeds INTEGER 8/9, FLOAT 8/9 and NULL 0/1, each flagged cut, and expects IllegalArgumentException. FakeDebugEngine.addEvent(Event) renumbers the event. A STATEMENT whose execution id equals its seq now gets the new seq as its id too, as a native STATEMENT has. Null ids and the parent ids of ROW and PROFILE events are left alone. A new FakeDebugEngineTest case covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…statement Review findings on #2319 (an independent review of the ADFA-7379 code): - F07: get_events' description listed only some of the cases where execution_id is null. It now names them all, as #2311's README does: close, a trigger's statements, a statement an app function runs inside a callback, an EXPLAIN's profile, a statement whose start was not seen, and the later profile of a statement pushed out of its slot. It also says that a step that met a busy lock fires a profile with rows 0 before the run's rows. The README's get_events paragraph says the same. - F06: JniQueryTest only checked that a row's execution_id was the seq of some STATEMENT in the buffer, so an id off by one or naming an older statement still passed. It now requires the id to be the seq of the newest STATEMENT before the row, and that statement's SQL to be the query's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…DFA-7297 # Conflicts: # subprojects/sqlite-debugger/README.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… and #2319's F06/F07) into ADFA-7304 # Conflicts: # subprojects/sqlite-debugger/README.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
Hal, 6b745ce merges #2319 at 6958e2f: #2311's ADFA-7379 review fixes (see #2311) and #2319's fuller |
ADFA-7304
Phase 2 follow-up of the SQLite debugger (ADFA-7131):
executebinds named args asquerydoes, and returns RETURNING rows withinquery's limits. Draft, stacked on #2313 (P2-4, which includes #2312). It also has #2319 (P2-2) merged in, for the named-args code it shares withquery. So until #2319 lands, this PR's diff against #2313 also shows #2319's and #2311's commits. ADFA-7304's own commits are listed below.What it adds (
subprojects/sqlite-debugger):execute(346cd6c): the samebind_named/bind_positionaland the same rules and errors asquery(prefixes, a misspelt key, a duplicate key, an anonymous?).argsis an array or an object, so named and positional can't be mixed.queryreturns them:columns,column_types,rows,storage_classes,has_more,truncated_cellsandtruncated_cell_indexes. That's at mostmax_rows(default asquery's), about 4 MiB of cells, with the same per-cell cuts.has_moremeans RETURNING produced more rows than came back; they can't be paged, because that would write again.done:finalizes before restoringbusy_timeout, so that commit is capped too.execute's description,DebugEngine.execute's KDoc and the README say all this (0d5dbb9 adds the cut-cells notequeryhas).Merges:
sqlitedbg_jni.c,DebugEngine.kt, README.md andJniQueryTest.java; its message lists each resolution.read_rowsand RETURNING come from here.bridge_execute's error branches run in this order: busy, capped interrupt, time limit, FAIL with its kept-row count, then any other error.deadlineinitializers that would have put the deadline in thedbfield, and ADFA-7299: SQLite debugger asks before the first write to a Room database #2313'sexecuteAsynctest calling the old four-argumentexecute.EventDecoderrow-count check, which closes theArrayList(kept)out-of-memory case CodeRabbit flagged.executesentence; the merge adds exactly dd7ee19's words.execution_idon everyget_eventsevent, along with ADFA-7297 SQLite debugger P2-2: rows, change counts, named parameters and column types #2319's two earlier merges of ADFA-7296: SQLite debugger records row and change events #2311 that this branch had taken directly. Two README conflicts: the first took ADFA-7379's text, as this branch's side was ADFA-7296: SQLite debugger records row and change events #2311's earlier wording word for word; the second kept this branch'sexecutebinding and Limits lines and added theexecution_idsentence. Every other file's changed lines equal the incoming change's. ADFA-7298: SQLite debugger execute tool, one write in autocommit #2312 and ADFA-7299: SQLite debugger asks before the first write to a Room database #2313, based on stage, are not merged.execution_iddescription. Two README conflicts, resolved to the incoming lines plus this branch's ownexecutelines; all six incoming lines are present and noexecuteline was lost; every other file matches the incoming change.Reviews:
test-sqlite-debuggerfailed in CI at 5ee892b and 9cb70b8. The table now also doubles (up to 3.2 million rows) while the copy finishes in time.changes-1 for an unfinished statement, the slot kept acrossSQLITE_BUSY, uncounted cut rows, two C-test NULL checks. Follow-up: ADFA-7379 (an execution id in row events). Accepted: column metadata read before the first step (a cross-connection schema change in that window), and no deadline check before a row-capped write's commit (limits are best effort; the write is documented as committed). Each thread has a reply.executeruns. Before, the write ran inside it, the call reported it written, and the backstop rolled it back afterwards.SQLITEDBG_TEST, never in the app) failsread_rowsas a JNI allocation would. The new checks fail without their fixes: reverting the first three fixes fails 3, and dropping the outcome report fails 3 others.test.shadds theSQLITEDBG_TESTseam.Tests:
test.sh0 failures (ASan+UBSan 32,204 checks, TSan 32,207, JNI 691);:subprojects:sqlite-debugger:testDebugUnitTest(146) andspotlessCheckpass.test.sh0 failures (ASan+UBSan 31,659 checks, TSan 31,666, JNI 691);:subprojects:sqlite-debugger:testDebugUnitTest(144) andspotlessCheckpass.test.sh0 failures (ASan+UBSan 23,037 checks, TSan 23,036, JNI 690). No Kotlin change since acd87a1.test.sh0 failures (ASan+UBSan 23,052 checks, TSan 23,045, JNI 690);:subprojects:sqlite-debugger:testDebugUnitTest(140) andspotlessCheckpass. Not rechecked on a device: the changed paths need a transaction left open or a failed allocation, which only the test build can produce.test.sh0 failures (ASan+UBSan 23,044 checks, TSan 23,042, JNI 659);:subprojects:sqlite-debugger:testDebugUnitTest(140) andspotlessCheckpass. A forced first-step interrupt now fails the time-limit test ("cut in its first step"), which the old test accepted.test.shat b9ccfc7: ASan+UBSan 21,006 checks, TSan 21,012, JNI 658, 0 failures. With the table started at 25,000 rows to stand in for a fast machine, the old test fails both checks CI showed, and the new one grows to 200,000 rows and passes. (The earlier claim of 0 failures at 5ee892b held on this machine only; CI failed there.):subprojects:sqlite-debugger:testDebugUnitTest(140),spotlessCheckand:app:assembleV8Debugpass at 0d5dbb9. 5ee892b and b9ccfc7 change onlyJniQueryTest.java, which Gradle doesn't build;spotlessApplychanges nothing at b9ccfc7.Device recheck at bad9f58 (Galaxy J7, 2026-12-01): every check below matches;
execute's description now carries the best-effort and unrecoverable-rows text.Device check (Galaxy J7, Android 9; ADFA-7304 comment, 2026-11-30): a RoomNotes test app with this branch's SQLite debugger at 5ee892b, called over
adb forward. All 14 checks passed:acknowledge_room, then one RETURNING row withcolumns,column_typesandstorage_classes.UPDATE ... RETURNINGwithmax_rows2 gives 2 rows,has_moretrue andchanges3, and all three rows are updated.truncated_cell_indexes[[0,0]].SELECT 1is refused ("run it with query").The run also found that
initialize's instructions still say "Every tool is read-only". That text dates from #2259, and #2312 addedexecutewithout changing it.Merging:
read_rowsreplaces the block ADFA-7295 SQLite debugger: refuse text after the JSON body, report a failed finalize, document the connection-id name clash #2320 adds the finalize check to. Whichever merges second resolves that.Left as is (David, 2026-11-30): nitpicks from the last re-check, none affecting correctness.
execute's description, likequery's, explainstruncated_cell_indexesbut doesn't give the 4,096-byte and 1,024-byte cut sizes.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
Code Reviewer: Code Reviewer couldn't review this pull request
The pull request author does not have access to AI for the associated Atlassian organization.