Skip to content

ADFA-7304: SQLite debugger execute returns RETURNING rows and binds named args - #2332

Draft
davidschachterADFA wants to merge 61 commits into
sqlite-debugger/ADFA-7299from
sqlite-debugger/ADFA-7304
Draft

davidschachterADFA wants to merge 61 commits into
sqlite-debugger/ADFA-7299from
sqlite-debugger/ADFA-7304

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7304

Phase 2 follow-up of the SQLite debugger (ADFA-7131): execute binds named args as query does, and returns RETURNING rows within query'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 with query. 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):

  • Named args for execute (346cd6c): the same bind_named/bind_positional and the same rules and errors as query (prefixes, a misspelt key, a duplicate key, an anonymous ?). args is an array or an object, so named and positional can't be mixed.
  • RETURNING rows (6f5a8a4):
    • Rows come back as query returns them: columns, column_types, rows, storage_classes, has_more, truncated_cells and truncated_cell_indexes. That's at most max_rows (default as query's), about 4 MiB of cells, with the same per-cell cuts.
    • Every change is committed whatever is returned. has_more means RETURNING produced more rows than came back; they can't be paged, because that would write again.
    • A statement that fails returns no rows and SQLite rolls it back. The exception is FAIL conflict resolution, which keeps the rows changed before the failing one, and the error says how many were kept (c2fae14).
    • The 1.5 s write limit covers the whole write, since SQLite makes every change before the first row comes back.
  • A commit stopped at the cap (571cc3f): when a statement cut at a limit can't commit because an app connection holds a lock, it's reported like a stalled step: SQLITE_INTERRUPT, "Try it again", and nothing kept. Before, it was SQLITE_BUSY with no advice. Also, done: finalizes before restoring busy_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 note query has).

Merges:

Reviews:

  • Before it was published (ADFA-7304 comment 41628; fixed in a8bb4e3 and c2fae14).
  • A fresh review on 2026-11-30 after the merges: no IMPORTANT findings. 3 MINOR and 3 NITPICK, all fixed (571cc3f, f7e7b55, 0d5dbb9, 5ee892b) and re-checked.
  • The cloud session's review (2026-11-30, ADFA-7131 comment 41745): 1 IMPORTANT, fixed in b9ccfc7. The RETURNING time-limit test only shrank its table, so on a fast machine every row was copied within the limit and two checks failed; test-sqlite-debugger failed in CI at 5ee892b and 9cb70b8. The table now also doubles (up to 3.2 million rows) while the copy finishes in time.
  • CodeRabbit's review of b9ccfc7 (requested 2026-11-30): 13 findings (4 Major, 9 Minor), checked by a probe against SQLite 3.49.1. Fixed here: 9530161 (when building the result fails after the write ran, the error says whether it was committed; tested since acd87a1), 4d02e99 (KDoc and tool text: best-effort limits; omitted RETURNING rows can't be recovered, a follow-up query helps only if the data still exists), b1c4e54 (the time-limit test requires rows to have been copied, and bisects the table size), 67e3017 (test fix). Fixed in ADFA-7296: SQLite debugger records row and change events #2311, which owns the code, and merged in bad9f58: huge values left unread, changes -1 for an unfinished statement, the slot kept across SQLITE_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.
  • A fresh review of the write-outcome reporting (2026-12-01, by a separate agent, then checked here), fixed in acd87a1:
    • A transaction left open on the server connection (a way past the authorizer, then a refused rollback) is rolled back before execute runs. Before, the write ran inside it, the call reported it written, and the backstop rolled it back afterwards.
    • The out-of-memory outcome error is always SQLITE_NOMEM. Before, it carried finalize's code, so an interrupt drew the tool's "retry it" onto 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, not the allocation failure.
    • A failed commit 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 (not tested).
    • A seam in the JNI test build only (SQLITEDBG_TEST, never in the app) fails read_rows as 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.
  • The cloud session's review of acd87a1: no findings to fix; its three revert proofs each fail one check. Its two optional nits are fixed in 559fb19: after an out-of-memory error, a commit that SQLite rolled back (lock, constraint, full disk, interrupt) now says nothing was kept, as the row-limit reset does; the README says test.sh adds the SQLITEDBG_TEST seam.

Tests:

  • At 6b745ce: test.sh 0 failures (ASan+UBSan 32,204 checks, TSan 32,207, JNI 691); :subprojects:sqlite-debugger:testDebugUnitTest (146) and spotlessCheck pass.
  • At 69dd43b: test.sh 0 failures (ASan+UBSan 31,659 checks, TSan 31,666, JNI 691); :subprojects:sqlite-debugger:testDebugUnitTest (144) and spotlessCheck pass.
  • At 559fb19: test.sh 0 failures (ASan+UBSan 23,037 checks, TSan 23,036, JNI 690). No Kotlin change since acd87a1.
  • At acd87a1: test.sh 0 failures (ASan+UBSan 23,052 checks, TSan 23,045, JNI 690); :subprojects:sqlite-debugger:testDebugUnitTest (140) and spotlessCheck pass. Not rechecked on a device: the changed paths need a transaction left open or a failed allocation, which only the test build can produce.
  • At bad9f58: test.sh 0 failures (ASan+UBSan 23,044 checks, TSan 23,042, JNI 659); :subprojects:sqlite-debugger:testDebugUnitTest (140) and spotlessCheck pass. A forced first-step interrupt now fails the time-limit test ("cut in its first step"), which the old test accepted.
  • test.sh at 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), spotlessCheck and :app:assembleV8Debug pass at 0d5dbb9. 5ee892b and b9ccfc7 change only JniQueryTest.java, which Gradle doesn't build; spotlessApply changes nothing at b9ccfc7.
  • New JNI cases:
    • a commit stalled at the cap (SQLITE_INTERRUPT, "Try it again", 1.4-2.4 s);
    • OR ROLLBACK, OR IGNORE and OR REPLACE with RETURNING;
    • a time limit that strikes while rows come back. The table is halved while the first step is slow and doubled while the copy finishes in time; the case fails rather than passing if no size reaches that path.
  • Revert proofs: without 571cc3f, the stall case fails with code 5 instead of 9; without 0d5dbb9, the description test fails.
  • At 571cc3f alone, the JNI test fails (its old case still expects code 5). It passes from f7e7b55 on.

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:

  • Room's acknowledgement: refused without acknowledge_room, then one RETURNING row with columns, column_types and storage_classes.
  • Named args with and without their prefix; a misspelt key names it; positional args still work.
  • UPDATE ... RETURNING with max_rows 2 gives 2 rows, has_more true and changes 3, and all three rows are updated.
  • A 5,000-character value comes back cut to 4,096, with truncated_cell_indexes [[0,0]].
  • With RETURNING: OR FAIL keeps its 1 row and says so; OR ROLLBACK keeps nothing; OR IGNORE returns the inserted row; OR REPLACE returns the new row.
  • SELECT 1 is 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 added execute without changing it.

Merging:

Left as is (David, 2026-11-30): nitpicks from the last re-check, none affecting correctness.

  • The commit-stall case's 2.4 s upper bound can still flake on a very slow CI runner; if it happens, widen the bound or retry once. The time-limit case now fails only when no table size fits: a first step over 1 s at a size whose copy still finishes in time.
  • execute's description, like query's, explains truncated_cell_indexes but 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.

claude and others added 30 commits November 25, 2026 03:22
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
davidschachterADFA and others added 2 commits November 30, 2026 18:02
…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
@davidschachterADFA

davidschachterADFA commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

@coderabbitai on the two comments in your review body (6121675022):

  • sqlitedbg_jni.c 575-577, column metadata before the first step: confirmed with a probe (another connection's ALTER TABLE between prepare and the first step leaves a stale column count). Not fixed in this PR: it needs a cross-connection schema change in that short window, the stored data is unaffected and a retry is right, and the fix (step first, then read metadata and handle the first row) is a larger rework of read_rows shared with query. Accepted as a limit.
  • sqlitedbg_jni.c 794-796, the deadline and a row-capped RETURNING write's commit: by design. Limits are best effort, and a write cut at a limit commits in full; the README, the KDoc and the tool description say so (4d02e99). Enforcing the deadline there would roll back a write the caller is told is committed.

@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.

  • In this PR: 9530161 (execute says whether the write committed when building the result fails), 4d02e99 (docs and tool text: best-effort limits, unrecoverable RETURNING rows), b1c4e54 (the RETURNING time-limit test now requires rows to have been copied, and bisects the table size), 67e3017 (test fix).
  • From ADFA-7296: SQLite debugger records row and change events #2311 (5d8acf6), merged in bad9f58: no huge-value reads, changes -1 for an unfinished statement, the slot kept across SQLITE_BUSY, uncounted cut rows, NULL checks in two C tests.
  • Follow-up: ADFA-7379 (an execution id in row events). Accepted: the metadata race and the deadline-at-commit design, as above.
  • Tests at bad9f58: test.sh 0 failures (ASan+UBSan 23,044 checks, TSan 23,042, JNI 659); :subprojects:sqlite-debugger:testDebugUnitTest 140 and spotlessCheck pass.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
printf '%s\n' '=== Review body ==='
gh api repos/appdevforall/CodeOnTheGo/pulls/2332/reviews/6121675022 --jq '.body' 2>&1 || true
printf '%s\n' '=== Source outline ==='
ast-grep outline subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c --items all --match 'read_rows|bridge_execute|bridge_query' 2>&1 || true
printf '%s\n' '=== Row collection and execute source ==='
cat -n subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c | sed -n '480,880p'
printf '%s\n' '=== Deadline and limit documentation ==='
rg -n -i -C 4 'best.effort|returning|commit|deadline' subprojects/sqlite-debugger/README.md subprojects/sqlite-debugger/src/main/java/org/appdevforall/sqlitedebugger/engine/DebugEngine.kt subprojects/sqlite-debugger/src/main/java/org/appdevforall/sqlitedebugger/mcp/DatabaseTools.kt | head -n 260
printf '%s\n' '=== test.sh files ==='
fd -t f '^test\.sh$' subprojects/sqlite-debugger -x sh -c 'echo "=== $1 ==="; cat -n "$1"' _ {}
printf '%s\n' '=== Current revision ==='
git rev-parse HEAD

Length of output: 112260


@davidschachterADFA Thanks for the clarification.

  • Metadata race: read_rows still reads metadata before the first step. The README documents the stale-column limitation. I acknowledge your decision to accept it for this PR.
  • Commit deadline: The documented best-effort limit answers my question. A row-capped RETURNING write commits in full if the commit succeeds, even if the call passes its deadline. I am not requesting a change to that behavior.

I checked the source and documentation at bad9f5883. I did not rerun the reported tests.

Would you like a follow-up issue for the metadata race?


Learnings added

Learnt from: davidschachterADFA
URL: https://github.com/appdevforall/CodeOnTheGo/pull/2332

Timestamp: 2026-12-01T02:11:15.231Z
Learning: Within repository "appdevforall/CodeOnTheGo", only for files matching one of ["subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c"]: In subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c, read_rows reads column metadata before the first SQLite step. A schema change on another connection between prepare and that step can leave the returned column set stale. The maintainer accepted this documented limitation for PR #2332 because the window is short, stored data is unaffected, and stepping before reading metadata requires a larger rework of read_rows shared with query. Do not treat the race as fixed when reviewing this path.
Learnt from: davidschachterADFA
URL: https://github.com/appdevforall/CodeOnTheGo/pull/2332

Timestamp: 2026-12-01T02:11:15.231Z
Learning: Within repository "appdevforall/CodeOnTheGo", only for files matching one of ["subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c"]: In subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c, bridge_execute uses a best-effort deadline for a RETURNING write cut at a row or size limit. A successful commit keeps the full write; the maintainer does not require a hard deadline check at commit start because rolling back at that point would conflict with the documented commit contract. Do not request a stricter commit-start deadline solely for this accepted behavior; this does not waive other deadline checks or commit error handling.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


Learnings used

Learnt from: davidschachterADFA
Repo: appdevforall/CodeOnTheGo PR: 2259
File: subprojects/sqlite-debugger/README.md:34-34
Timestamp: 2026-11-24T23:13:30.129Z
Learning: Within repository "appdevforall/CodeOnTheGo", only for files matching one of ["subprojects/sqlite-debugger/src/main/cpp/sqlitedbg_jni.c","subprojects/sqlite-debugger/README.md"]: In the SQLite debugger, while query deadlines are enforced through the SQLite progress handler, do not treat the 1.5-second non-WAL deadline or the 50-second call deadline as a hard bound on read-lock duration or response time. The handler checks every 1,000 SQLite VM instructions, not during a busy wait or inside a long instruction. The non-WAL deadline is intended to protect app writes, but it cannot guarantee that a write will not time out.
Learnt from: davidschachterADFA
Repo: appdevforall/CodeOnTheGo

Timestamp: 2026-12-01T02:09:35.324Z
Learning: Within repository "appdevforall/CodeOnTheGo", only for files matching one of ["subprojects/sqlite-debugger/src/main/cpp/sqlitedbg.c"]: In subprojects/sqlite-debugger/src/main/cpp/sqlitedbg.c, do not treat unchanged SQLite change counters at PROFILE as proof that a partially stepped INSERT ... RETURNING changed no rows. SQLite 3.49.1 can emit PROFILE before reset halts the statement and updates the counters, even when reset keeps the inserts. The trace_cb reports changes as -1 (unknown) when the statement is still busy at PROFILE.

You are interacting with an AI system.

davidschachterADFA and others added 2 commits November 30, 2026 18:26
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
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

Hal, one more commit for your review, acd87a1: fixes from a fresh review of what execute reports when its call fails after the write ran.

  • A transaction left open on the server connection is rolled back before execute runs. Before, the write ran inside it, was reported as written, and was then rolled back by the backstop.
  • The out-of-memory outcome error is always SQLITE_NOMEM, so the tool no longer adds "retry it" to an error that says the write may not have been committed.
  • A statement that failed before its result was built reports its own error.
  • After an I/O error or corruption at the row-limit commit, the error says the change may not have been kept, not that nothing was kept.
  • The tests use a seam in the JNI test build only (SQLITEDBG_TEST). Each new check fails without its fix.

test.sh 0 failures (JNI 690), unit tests (140) and spotlessCheck pass. Details are in the description under Reviews and Tests.

davidschachterADFA and others added 4 commits November 30, 2026 23:49
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

# 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
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

Hal, two more commits:

  • 75af55f merges ADFA-7296: SQLite debugger records row and change events #2311's README note (dd7ee19). Both sentences are kept in the one conflicted line.
  • 559fb19: after an out-of-memory error, a commit that SQLite rolled back (lock, constraint, full disk, interrupt) now says nothing was kept, as the row-limit reset already does, so a retry is safe. The README says test.sh adds the SQLITEDBG_TEST seam. test.sh 0 failures (JNI 690).

davidschachterADFA and others added 7 commits December 1, 2026 00:48
…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
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

Hal, 69dd43b merges #2319 at 8760dc0: #2311's ADFA-7379 (an execution id on events) and execution_id in get_events. Two README conflicts, resolved to ADFA-7379's text plus this branch's own execute lines; every other file matches the incoming change. test.sh 0 failures (JNI 691), unit tests 144, spotlessCheck.

davidschachterADFA and others added 9 commits December 1, 2026 17:29
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
@davidschachterADFA

Copy link
Copy Markdown
Collaborator Author

Hal, 6b745ce merges #2319 at 6958e2f: #2311's ADFA-7379 review fixes (see #2311) and #2319's fuller execution_id description. Two README conflicts, resolved to the incoming lines plus this branch's own execute lines; every other file matches the incoming change. test.sh 0 failures (32,204 / 32,207 / JNI 691), unit tests 146, spotlessCheck.

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.

2 participants