Repository navigation
ADFA-7295 SQLite debugger: refuse text after the JSON body, report a failed finalize, document the connection-id name clash - #2320
davidschachterADFA wants to merge 3 commits into
Conversation
…failed finalize, document the connection-id name clash Three follow-ups from CodeRabbit's review of #2260 (F18, F06, F24). - McpProtocol.post: JSONTokener.nextValue() reads one value and stops, so {"jsonrpc":"2.0","id":1,"method":"ping"} garbage ran the ping. Only JSON whitespace may follow the value now; anything else is HTTP 400 with PARSE_ERROR, and nothing runs. The rest is read with next(), because Android's nextClean() also skips comments and the JVM's org.json does not. - bridge_query dropped the result of sqlite3_finalize. A page that stops before SQLITE_DONE ends the statement there, and on a writable connection an autocommit write (an INSERT with RETURNING) commits there: a failed commit rolled the write back while the call returned its first rows. That is now the call's error, unless the query had already failed. No tool opens a writable connection yet. - README: the name clash of sqlitedbg_connection_id() as a limit, and the finalize error beside the rollback backstop. Tests: McpProtocolTest.textAfterTheJsonIsAParseErrorAndRunsNothing, and a JniQueryTest case where another connection's read lock makes the commit at finalize fail. Both fail with the fix reverted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
There was a problem hiding this comment.
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.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
On #2320 (7b83e89), which left them out as not asked for; David asked for them. - F21: McpHttp's request-head deadline (serve, readHead) uses System.nanoTime(), as finishReply does, so a wall clock set back no longer extends it. - F09: sqlitedbg.map is a LINK_DEPENDS of libsqlitedbg, so an edit to the version script alone relinks. - F11: TimerIdleScheduler cancels its timer once the task has run, so the daemon thread no longer stays parked until the next schedule. Tests: DatabaseToolsTest, McpProtocolTest and EventDecoderTest pass (109), compiled with the Kotlin compiler outside Gradle; the existing head-deadline test (a trickling client, McpProtocolTest) passes on nanoTime. New: theIdleTimerThreadEndsOnceItsCheckHasRun; without the cancel it fails ("still parked"). F09, by a host CMake/Ninja build: touching sqlitedbg.map relinks, and without LINK_DEPENDS "no work to do". F21 has no test: there is no clock seam to step back. C sources unchanged, so test.sh is not rerun. Not run here: Gradle, spotlessCheck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
…nal change spotlessKotlinCheck's one change after 156d315: ktlint wraps the idleThreads() call chain in theIdleTimerThreadEndsOnceItsCheckHasRun. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
|
@hal-eisen-adfa, this PR gained two commits since the review request:
The description lists them with their tests. The earlier commit, 7b83e89, is unchanged. (Written by Claude Code for David.) |
davidschachterADFA
left a comment
There was a problem hiding this comment.
Review of #2320 at ebadb2dcb7. Not stacked (base stage). Includes 156d315 (F21, F09, F11), checked to be an ancestor of this head.
NITPICK - 1 inline, not listed
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
ADFA-7295
Follow-ups to the SQLite debugger (ADFA-7131) from CodeRabbit's review of #2260: F18, F06 and F24 in ADFA-7295, and its three optional items F21, F09 and F11, which David asked for. They concern #2259's code, which is in stage, so this PR goes straight into stage.
What it does (
subprojects/sqlite-debugger)McpProtocol.postparsed withJSONTokener(body).nextValue(), which reads one value and stops, so{"jsonrpc":"2.0","id":1,"method":"ping"} garbageran the ping. Only JSON whitespace may follow the value now; anything else gets HTTP 400 withPARSE_ERROR(-32700), and nothing runs. The rest is read withnext(), because Android'snextClean()also skips comments and the JVM's org.json does not.sqlite3_finalize:bridge_querydropped its result. A page that stops beforeSQLITE_DONEends the statement atsqlite3_finalize, and on a writable connection an autocommit write, such as an INSERT with RETURNING, commits there. A commit that failed rolled the write back while the call returned its first rows. That is now the call's error, unless the query had already failed (then the first error is kept, as the rollback backstop does). No tool opens a writable connection on stage, so production is not affected yet.sqlitedbg_connection_id(), freed by that function's destructor. If the app registers a function of the same name with no arguments on that connection, or deletes ours, SQLite frees the state while the trace callback still uses it. The README's limits say so; a fix is not asked for. The README's read-only paragraph also names the finalize error beside the rollback backstop.McpHttp.serveandreadHeaduseSystem.nanoTime(), asfinishReplyalready does, so a backward step of the wall clock no longer extends the deadline.sqlitedbg.mapis aLINK_DEPENDSoflibsqlitedbginCMakeLists.txt, so an edit to the version script alone relinks.TimerIdleSchedulercancels its timer once its task has run, so the timer thread no longer stays parked until the next check cancels it. The class is nowinternal, for its test.Commits: 7b83e89 (F18, F06, F24); 156d315 (F21, F09, F11, written by the cloud session); ebadb2d (
spotlessApplyon 156d315's new test only).Siblings checked:
McpProtocol.postis the module's only JSON body parse. The othersqlite3_finalizecalls areis_wal_mode(a read-only PRAGMA; a failure already counts as not WAL) andprepare_one(statements that never ran, so finalize can't fail). On #2312,executesteps every statement toSQLITE_DONE, so its finalize can't add an error either. Left on the wall clock on purpose: the 50 s per-POST tool deadline (McpProtocol.post,clock = System::currentTimeMillis). It crosses into C as epoch milliseconds, andsqlitedbg_jni.ccompares it withCLOCK_REALTIMEin the progress handler, so a backward step of the clock during a POST lengthens that POST's hold on the tools by the step. Moving it to a monotonic clock changes that contract on both sides at once, in every stacked PR that passes a deadline, so it is out of scope here (2026-11-26 review, comment 4713230914).Tests
McpProtocolTest.textAfterTheJsonIsAParseErrorAndRunsNothing(six bodies with text after the JSON, none runs the tool; trailing whitespace still works), and aJniQueryTestcase where another connection's read transaction makes the commit at finalize fail withSQLITE_BUSYand the insert is not kept.DatabaseToolsTest.theIdleTimerThreadEndsOnceItsCheckHasRun. With the cancel removed it fails at its assertion that the timer thread has ended (rerun locally). F09 was checked by the cloud session with a host CMake and Ninja build: touchingsqlitedbg.maprelinks, and withoutLINK_DEPENDSNinja has no work to do. F21 has no test, as there is no clock seam to step back; the existing trickling-client head-deadline test passes onnanoTime.:subprojects:sqlite-debugger:testDebugUnitTest(114 tests),spotlessCheckand:subprojects:sqlite-debugger:assembleDebugpass. The C sources are unchanged since 7b83e89.test.shpasses (ASan+UBSan 15736 checks, TSan 15726, JNI 212, 0 failures);:subprojects:sqlite-debugger:testDebugUnitTest(113 tests) andspotlessCheckpass.Merging: a test merge with #2312 (and #2313, which carries it) conflicts in
bridge_query'sdone:block,JniQueryTest.javaand the README; one with #2319 (and the P2-6 branch on it) conflicts inDatabaseToolsTest.kt, where both add tests at the end. Whichever merges second resolves them.git merge-treefinds no conflict with #2311.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.