Skip to content

ADFA-7299: SQLite debugger asks before the first write to a Room database - #2313

Open
davidschachterADFA wants to merge 7 commits into
sqlite-debugger/ADFA-7298from
sqlite-debugger/ADFA-7299
Open

davidschachterADFA wants to merge 7 commits into
sqlite-debugger/ADFA-7298from
sqlite-debugger/ADFA-7299

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-7299

Phase 2, P2-4 of the SQLite debugger (ADFA-7131 comment 41476, decision D6): the first execute on a Room database waits for an acknowledgement. Stacked on #2312 (P2-3, ADFA-7298); merge it after #2312.

What it does (subprojects/sqlite-debugger, Kotlin only)

  • Room records changes with TEMP triggers on its own connection, which a write on the server's connection does not fire, so its observers (Flow, LiveData, Paging, InvalidationTracker) miss the change and a screen can show stale data. The SQLite debugger does not make Room refresh: it must not change how the app behaves.
  • execute looks for room_master_table on the read-only connection. On a Room database it runs nothing and returns an error naming the risk, with details {room: true, acknowledge_with: "acknowledge_room"}, until the call is repeated with acknowledge_room: true.
  • The acknowledgement is kept per database path for the life of DatabaseTools (one per app process), so later writes to that database run without asking and the check is not run again. A database without room_master_table never asks.
  • acknowledge_room must be a boolean; it is checked before the engine is called.
  • The README and execute's description and input schema are updated.

Limits: a database without Room's table is checked on every execute (one indexed read of sqlite_master); an acknowledgement outlives a database the app deletes and recreates under the same path.

Commits: fb55fbc (the cloud session's c07fbf3, cherry-picked onto #2312's branch; conflicts with #2312's last_insert_rowid in execute's result and the README's execute paragraph, resolved to keep both), 1f695c4 (its Room test helper built ExecuteResult(1), which no longer compiled after last_insert_rowid; a test line over ktlint's 140 columns wrapped), 43d9da5 (merge of #2312 at 8c2f6ac; this PR's own diff unchanged). For the 2026-11-26 review (ADFA-7131 comment 41632): f12f2e7 (merge of #2312 at 2258ffc, its lock-wait fixes; one README conflict, both sides kept) and 07e7ccd (the "refuses again" check now runs on the same DatabaseTools, review comment 4713225968).

Tests

  • Local, at 07e7ccd: test.sh with the system JDK: ASan+UBSan 16030 checks, TSan 16020, JNI 427, 0 failures; :subprojects:sqlite-debugger:testDebugUnitTest (125), :subprojects:sqlite-debugger:assembleDebug (the native library for both ABIs) and spotlessCheck pass. Revert proof: with the acknowledgement recorded before the flag check, aRoomDatabaseRefusesTheFirstWriteWithAWarningAndRunsNothing fails at the second call.
  • Local, at eff47b0, which merges ADFA-7298: SQLite debugger execute tool, one write in autocommit #2312's b98c9a1 (ADFA-7298: SQLite debugger execute tool, one write in autocommit #2312 with stage at 6612799), with no conflicts, and this PR's own diff is unchanged: :subprojects:sqlite-debugger:testDebugUnitTest (125), :plugin-api:testDebugUnitTest (251) with apiCheck, spotlessCheck and assembleV8Debug pass. test.sh with the system JDK: ASan+UBSan 16040 checks, TSan 16030, JNI 382, 0 failures. At 09939db (with ADFA-7298: SQLite debugger execute tool, one write in autocommit #2312's 01413e0): test.sh JNI 382, 0 failures, and the same Gradle checks pass.
  • Local, at 43d9da5: :subprojects:sqlite-debugger:testDebugUnitTest (125), :plugin-api:testDebugUnitTest (251) with apiCheck, spotlessCheck and assembleV8Debug pass. test.sh with the system JDK: ASan+UBSan 15919 checks, TSan 15909, JNI 319, 0 failures (no native change in this PR).
  • From the cloud session: revert proofs: never refusing fails aRoomDatabaseRefusesTheFirstWriteWithAWarningAndRunsNothing and anAcknowledgementCoversOnlyItsOwnDatabaseAndOnlyThisServerProcess; not remembering the acknowledgement fails anAcknowledgedRoomWriteRunsAndLaterWritesRunWithoutAsking. One P2-3 test now counts the read-only connection execute opens.

Device checks (2026-11-25):

  • Galaxy J7, by direct MCP calls (ADFA-7299 comments 41562 and 41568): the first write to a Room database is refused with the warning; the acknowledged write runs, and so do the writes after it.
  • Note 20, through the Agent with P2-5 (ADFA-7300 comment 41584): the write ran after the user approved execute, but the Room warning wasn't shown, because the model put acknowledge_room: true in its first call. David: acceptable, since a user who knows to supply it has the understanding the warning asks for, so this PR stays as it is.

No screens added or changed.

🤖 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 3 commits November 24, 2026 23:37
…om database

Phase 2, P2-4 (ADFA-7131 comment 41476, decision D6). On P2-3.

- Room records changes with TEMP triggers on its own connection, which
  a write on the server's connection does not fire, so its observers
  miss the change and a screen can show stale data. The debugger does
  not make Room refresh: it must not change how the app behaves.
- execute looks for room_master_table on the read-only connection. On a
  Room database it runs nothing and returns an error naming the risk,
  with details {room: true, acknowledge_with: "acknowledge_room"}, until
  the call is repeated with acknowledge_room: true.
- The acknowledgement is kept per database path for the life of
  DatabaseTools (one per app process), so later writes to that
  database run without asking and the check is not run again. A
  database without room_master_table never asks.
- acknowledge_room must be a boolean; it is checked before the engine.
- README and execute's description and input schema updated.

Limits: a database without Room's table is checked on every execute
(one indexed read of sqlite_master); an acknowledgement outlives a
database the app deletes and recreates under the same path.

Tests: DatabaseToolsTest, McpProtocolTest and EventDecoderTest pass
(119), compiled with the Kotlin compiler outside Gradle. One P2-3 test
now counts the read-only connection execute opens. Revert proofs:
never refusing fails aRoomDatabaseRefusesTheFirstWrite... and
anAcknowledgementCoversOnlyItsOwnDatabase...; not remembering the
acknowledgement fails anAcknowledgedRoomWriteRunsAndLaterWritesRun...
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
(cherry picked from commit c07fbf3)
…sult

c07fbf3 was written on P2-3 before execute returned last_insert_rowid
(b73b9f7), so its Room test helper built ExecuteResult(1) and no longer
compiled; it now passes lastInsertRowid = null. Its one-line fake answer
in the acknowledgement test exceeded ktlint's 140 columns, which
spotlessApply cannot fix; it is wrapped. Tests only, no behaviour change.

:subprojects:sqlite-debugger:testDebugUnitTest 125 tests pass,
assembleDebug passes, spotlessApply leaves nothing to change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…gger/ADFA-7299

Brings P2-3's 8c2f6ac (execute reports rowid 0; INT64_MIN stands for
"no row inserted") into this stacked branch.

One conflict, in the README's execute paragraph: P2-3 changed its
last_insert_rowid sentence, and this PR removed "(the Room warning is
ADFA-7299)" from it, as its own bullet now covers the Room warning. The
resolution keeps P2-3's paragraph without that parenthesis, followed by
this PR's Room bullet. Outside the README this PR's own diff is unchanged
(+/- lines of `git diff b73b9f7 1f695c4` and `git diff
sqlite-debugger/ADFA-7298 HEAD` identical); in the README its own changes
are the same two (the parenthesis removed, the Room bullet added).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

…gger/ADFA-7299

Brings P2-3's fix for CodeRabbit's flag-PRAGMA finding into this stacked
branch: every PRAGMA that takes a value is refused except schema reads and
user_version on execute's connection (d7c5350), and execute's writable
connection enforces foreign keys (01413e0).

Two conflicts, both resolved to keep both sides: in DatabaseTools.kt,
P2-3's new READ_PRAGMAS_NOTE beside this PR's ROOM_DESCRIPTION and
ROOM_WARNING, and execute's description with P2-3's new text plus this
PR's "$ROOM_DESCRIPTION"; in the README, P2-3's rewritten read-only and
execute paragraphs (the latter without "(the Room warning is
ADFA-7299)", as this PR's Room bullet covers it), then the Room bullet.
Outside those two files this PR's own diff is unchanged (+/- lines of
`git diff 8c2f6ac 43d9da5` and `git diff sqlite-debugger/ADFA-7298
HEAD` identical); in them its own changes are the same as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 25, 2026
Brings #2313 at 09939db (with #2312 at 01413e0: the PRAGMA allowlist and
foreign keys on execute's connection) into the temporary branch for the
device checks. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…gger/ADFA-7299

P2-3's branch merged origin/stage at 6612799, which adds #2291
(ADFA-4654), #2292 (ADFA-7134), #2283 (ADFA-6945), #2293 (ADFA-7247,
ADFA-7243) and #2298 (ADFA-7201). This brings that merge into the
stacked branch.

No conflicts. This PR's own diff is unchanged: the +/- lines of
`git diff 01413e0 09939db` and `git diff sqlite-debugger/ADFA-7298
HEAD` are identical, in the same 3 files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA pushed a commit that referenced this pull request Nov 26, 2026
…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

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review of #2313 at eff47b0ba6. Stack: #2312 (P2-3) <- #2313 (this, top); claims checked at this head, the stack tip.

MINOR

  • subprojects/sqlite-debugger/src/test/java/org/appdevforall/sqlitedebugger/mcp/DatabaseToolsTest.kt:1282 - refuses-again assertion uses a fresh DatabaseTools, so it cannot detect an ack recorded on refusal

Verdict: COMMENT. This PR is authored by the account posting the review, and GitHub refuses APPROVE and REQUEST_CHANGES on your own PR. Severity rules: CodeOnTheGo REVIEW.md and CLAUDE.md (a ticket moves to QA with no outstanding critical, high or medium findings); addons has no written rule, so the default applied.


Generated by Claude Code

davidschachterADFA and others added 2 commits November 26, 2026 15:04
…gger/ADFA-7299

Brings in the #2312 review fixes (execute lock waits, the rollback check).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
`tools` builds a new DatabaseTools on each read, so the "asked again
without the flag, it refuses again" call ran on an instance that
remembered nothing, and passed even if a refusal recorded the
acknowledgement (#2313 review, comment 4713225968). Both calls now use one
instance; recording the acknowledgement before the flag check fails it.

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-eisen-adfa New commits since you were asked to review:

The description lists the tests.

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