Repository navigation
Let a host cancel all running JavaScript - #33
Conversation
sqlitejs_cancel_all() stops the JavaScript running in every connection: each call fails with an "interrupted" error, even code that catches every exception. JavaScript that begins afterwards runs normally. Android cannot otherwise stop a runaway function: it cancels a query with a progress handler, which SQLite never calls while a function runs, and Room 2.7 and later pass no cancellation signal at all. A global epoch, read when the outermost call into JavaScript begins and compared by the existing interrupt handler, makes the cancel reach every runtime without a list of connections. The interrupt handler is now installed even when sqlite3_is_interrupted() is unavailable (SQLite before 3.41), so cancelling still works there. When the cancel stops a call, the handler also interrupts that call's connection with sqlite3_interrupt(), so its statement stops too. A collation cannot report an error: without this, a sort went on calling it, each call beginning after the cancel, and never ended. Add to the Cancel all test a runaway collation that one cancel stops; it hung without this. The test's worker cancels only once the JavaScript under test has called started(), an SQL function, since a cancel that came first would leave the JavaScript running. If that has not happened within 10 seconds, the worker fails the test with a message instead of cancelling. Like the Interrupt test, a watchdog ends the program if the JavaScript cannot be stopped. Only a call into JavaScript is cancelled, not the JavaScript a connection runs while it is set up: a cancel then made the connection fail to load the extension (SQLITE_NOMEM), and an app's query on a new pool connection failed. The Cancel all test now opens 200 connections while another thread cancels without pause; without this, the first failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Since 1.4.2 every result set still open when the outermost call into JavaScript returns is ended there, which runs the final of each window or aggregate function its statement was computing. Each final enters JavaScript as a new outermost call, so js_enter() took the cancel epoch of that moment and a cancel during the call no longer stopped it. On SQLite 3.41 and later the interrupt the cancel left on the connection does; before 3.41 nothing did, and a final that never ends hung the statement for good. The finals that ending a call's result sets runs now keep that call's epoch, so a cancel during the call, or during the ending, stops each of them at QuickJS's next interrupt check: one that never ends is stopped and the statement fails with an interrupt, though a short final can still run to its end. Reading on from those result sets throws "interrupted", as after sqlite3_interrupt() on 3.41 and later, rather than the message for a result set that outlived its call, whether the cancel came before the call returned or while its result sets were ended. js_end_rowsets() marks the latter after its loop, by the pass that ended them, since a final it runs can free result sets of the list. Before 3.41, an sqlite3_interrupt() that no cancel came with still reads as the result set outliving its call: nothing shows it. Test: Cancel all now covers both cases on any SQLite. A call that returns normally keeps two result sets of window functions whose finals never end, and the first final starts the cancel: both finals stop and both result sets read on as "interrupted". And a cancel that lands as a call returns, from SQL inside it, stops the long final that ending its result set runs, so the call fails and the final records nothing. Without this change the first fails with the "closed" message, and the second returns OK with the final run to its end. Upstream's suite passes 17 of 17, also under ASan, LeakSanitizer and UBSan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
The DLL exports only what the generated .def file lists, so the test
program could not link sqlitejs_cancel_all() on Windows ("undefined
reference" in the windows-x86_64 job). The .def file now lists it with
the other public functions; it is the only export list in the project.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
- js_leave no longer tests the cancel epoch: the block after the loop in js_end_rowsets already marks a cancelled call's result sets interrupted. - Say that only JavaScript the extension runs while it initialises a connection (globaljs_init, depth 0) is exempt from a cancel; stored functions loaded by js_init_table run as a call and can be cancelled. - Initialise rowset end_pass to 0 where a rowset is created. - Document sqlitejs_cancel_all in sqlitejs.h. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Patch 0002 (rebuilt from upstream PR sqliteai/sqlite-js#33) now: - drops the redundant cancelled term from js_leave: the block after the loop in js_end_rowsets marks a cancelled call's result sets interrupted; - says only JavaScript the extension runs while it initialises a connection is exempt from a cancel, not js_init_table's stored functions; - initialises a rowset's end_pass where it is created; - documents sqlitejs_cancel_all in sqlitejs.h. upstream/ is regenerated with vendor.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
|
Merged, and released in 1.4.3. Thank you — Your four commits (c52018c…f0f6216) went in unmodified through #34: the merge commit on #34 adds two commits on top. One is a gap I found while testing the cancel against a connection pool, which is the case this feature exists for: the exemption covered the JavaScript run while the extension loads, but the functions Loading a stored function is now setup too: The other commit documents in I ran your branch against |
Upstream merged sqliteai/sqlite-js#33, our patches 0001 (cancel) and 0002 (a cancelled call's finals and result sets) unmodified, and released them in 1.4.3 with one fix of the maintainer's: a cancel no longer stops a stored function's code while js_init_table(1) loads it, as it already spared the JavaScript that loads the extension. Before, a cancel in flight left the connection without that function. Only that call is exempt: JavaScript the code runs through SQL is still cancelled. - upstream/ is plain 1.4.3; patches/ is gone. vendor.sh and test.sh apply any patches/ there may be later (nullglob). - The glue still loads a stored function up to three times, for the case 1.4.3 still cancels. glue_test.c: new test 20 checks that a cancel during a function's own load code does not stop it (fails on 1.4.2 with the two patches); the w and h tests now cancel JavaScript that the load code runs through SQL (they fail with one try). - README, SqliteJs.cancelAll() javadoc: a cancel interrupts the connection, so any other statement in progress on it fails too, and it spares loading stored functions. The README now says the 1.4.2 build passed on the phone and the 1.4.3 build has not run on one yet. test.sh: upstream's suite 17 of 17; glue test 50 of 50 normally and as on SQLite 3.40, and the same under ASan, LeakSanitizer and UBSan. vendor.sh --check passes. NDK 29 builds for both ABIs: no warnings, the same four exports, version string 1.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
|
Thank you for merging this, for releasing it in 1.4.3, and for the fix in #34. Exempting the Our Android build now vendors 1.4.3 with no local patches (in review), and its tests pass against the release, including a new one that checks a cancel no longer stops a stored function's own load code. This reply originated with AI: Claude, Anthropic's AI model, wrote it for App Dev For All. Contact: davidschachter@appdevforall.org |
* ADFA-7082: Vendor sqlite-js 1.3.7 with our patches sqlite-js 1.3.7 (Apache-2.0, with QuickJS/quickjs-ng amalgamated in libs/quickjs.c, MIT), only the files the AAR build uses, with patches/ applied: 0001-0008 are the Termux package's (terminal-packages packages/sqlite-js), 0009 makes each call measure its own thread's stack, and 0010 adds sqlitejs_cancel_all(). 0001-0009 are sent upstream as sqliteai/sqlite-js #11-#19. vendor.sh rebuilds upstream/ and the license notices from the release (checked against its SHA-256) and patches/, or with --check tells whether they match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Build the sqlite-js AAR for apps in subprojects:sqlite-js The AAR the JavaScript-in-SQLite project template depends on: libsqlitejs.so for arm64-v8a, armeabi-v7a and x86_64 (minSdk 26), and SqliteJs: cancelAll(), libraryPath(), ENTRY_POINT (loads the functions stored in js_functions on every connection) and ENTRY_POINT_FOR_DEFINING. sqlitejs_android.c, ours, holds the JNI and that entry point; the version script exports only the entry points and JNI_OnLoad. Nothing in CoGo depends on the module. AndroidModuleConf leaves it without the v7/v8 flavors, like :plugin-api, since one AAR serves every ABI, and without core-library desugaring, like :logsender, so apps need not enable it. Tested in a trial app (requery 3.49.0, Room 2.8.4) on a Galaxy Note20 Ultra as a 64-bit and a 32-bit process: scalar and aggregate from DAOs, deep recursion on pool threads, 32 parallel queries under WAL, and a runaway query stopped by cancelAll() within 5 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Release the sqlite-js AAR to sqlite-js-latest A manual workflow, like release-plugin-api.yml: checks the vendored sqlite-js, builds the AAR from main, and replaces the moving sqlite-js-latest release, from which dev-assets fetches it into the template that uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Build the sqlite-js AAR for arm64-v8a and armeabi-v7a only Apps built with Code on the Go run on ARM phones, so the AAR no longer carries x86_64. ADR 0005 says so. CLAUDE.md's ABI section now names the two modules without v7/v8 flavors, as ARCHITECTURE.md and ADR 0005 do (review of PR #2244, F07). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Run no stored code by default; test sqlite-js on pull requests From the reviews of PR #2244 (independent F02, F03, F05, F06; CodeRabbit): - ENTRY_POINT (sqlite3_sqlitejs_init, also the name SQLite derives from libsqlitejs.so) now loads sqlite-js alone. The old entry point loaded the functions stored in js_functions, which runs their code, so any database file the app opened ran its stored JavaScript at once. Loading them is now ENTRY_POINT_FOR_TRUSTED_DATABASE (sqlite3_sqlitejs_trusted_init), for databases the app made. ENTRY_POINT_FOR_DEFINING is gone: ENTRY_POINT does that job. - The trusted entry point loads each stored function on its own, so one that fails is logged and skipped instead of dropping those after it. - cancelAll()'s Javadoc and the README say it stops JavaScript in every query, so call it only for a known runaway and repeat it until the query ends. - test.sh runs upstream's test suite with patches/, and glue_test.c, the first test of sqlitejs_android.c. test-sqlite-js.yml runs vendor.sh --check and test.sh on pull requests for this module. glue_test.c passes 14 of 14; against the old glue 5 fail (stored functions loaded by ENTRY_POINT, functions after a broken one dropped). The AAR builds and exports the two entry points, sqlite3_js_init and JNI_OnLoad. Not run on a device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Update sqlite-js-latest in place, out of latest-release selection release-sqlite-js.yml deleted the release and its tag before making the new one, so a failed upload left dev-assets nothing to fetch. It now uploads the new assets over the old ones, putting the old ones back if that fails, then moves the tag and the notes. The release is created and kept with --latest=false, so it never becomes the repository's latest release (CodeRabbit, PR #2244). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Sort the QuickJS copyright lines the same on every machine vendor.sh built LICENSE.quickjs with sort -u in the machine's locale, so the new test-sqlite-js workflow's vendor.sh --check failed on the runner: en_US.UTF-8 and C order "2017" and "2017-2018" differently. It now sorts with LC_ALL=C, and upstream/LICENSE.quickjs and the META-INF notice are regenerated; only the order of their copyright lines changes. --check passes under C, C.UTF-8 and en_US.UTF-8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Log stored functions that cannot be listed; guard the tag move From CodeRabbit's review of the previous commits: - The trusted entry point returned silently when it could not list the stored functions (busy, out of memory, an odd table), opening the connection with some or none of them. Each failure is now logged; the connection still opens. It first looks js_functions up in sqlite_master, so a database without stored functions makes SQLite log no "no such table" error on each connection, as it did. - release-sqlite-js.yml moves the tag and edits the notes in the same guarded sequence as the upload. If any step fails, the previous assets and tag are put back. glue_test.c passes 16 of 16; the two new tests fail on the previous glue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the reviewed sqlite-js patches Patches 0002, 0003, 0004 and 0010 are regenerated after three reviews: the independent reviews of terminal-packages #6 and of this PR, and CodeRabbit's review of this PR. - 0002: garbage is collected before the memory limit fills. Running out of memory through small allocations reports "out of memory". - 0003: the README says TEMP views and triggers can call the js_* functions. - 0004: db.exec throws for a buffer it cannot read instead of binding NULL. A typed array's own offset and length are used, not properties a script defines. - 0010: a cancel also interrupts the cancelled call's statement, so a runaway JavaScript collation stops. Before, nothing could stop one. The other patches change only in their headers and line numbers. upstream/ is regenerated with vendor.sh, and vendor.sh --check passes. SqliteJs.cancelAll() and the README say a cancel interrupts the statement too. Tested: - test.sh: upstream's suite passes 16 of 16, and the glue test 16 of 16. - In the work repo, the same suite passes under ASan and UBSan with leak checking, and each new test fails without its fix. - The AAR builds for arm64-v8a and armeabi-v7a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Put back both the assets and the tag if a release update fails From CodeRabbit's review: under bash -e, a failed restore of the previous assets stopped the rollback before it put the tag back, so the tag could name the new build while the release held the old one. Each restore is now attempted, reported if it fails, and the step still fails. Checked with gh stubbed out: when the update fails and the asset restore fails, the tag restore still runs and the step exits 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Find js_functions in any case; sync the cancel test; doc caveats From CodeRabbit's review of the vendored patches: - The trusted entry point looks up js_functions with COLLATE NOCASE, as SQLite resolves a table name, so a table named JS_FUNCTIONS loads. A new glue test, now 18 of 18, fails without it. - Patch 0010's Cancel all test cancels once the JavaScript under test has called started(), an SQL function, instead of after a fixed 200 ms. A slow start can no longer end the test at its alarm. It still hangs without the fix it tests. - SqliteJs.cancelAll() and the README now say two more things. An interrupted INSERT, UPDATE or DELETE in an explicit transaction rolls the whole transaction back. And a cancel reaches SQL that JavaScript runs through db.exec only when that SQL returns to JavaScript. Tested: - test.sh: upstream's suite passes 16 of 16, also under ASan and UBSan in the work repo, and the glue test 18 of 18. - vendor.sh --check passes. - The AAR builds with the new lookup for arm64-v8a and armeabi-v7a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a re-run repair a release left without its assets A run that stops during `gh release upload --clobber` can leave an asset missing. The next run then failed at the backup download ("no assets match the file pattern") before it uploaded anything, so re-running could not repair the release. The step now backs up only the assets that exist and puts the previous ones back only when it has both. Tested with a stub gh over a fake release: both assets missing now ends with the new pair and the tag moved (before: exit 1 at the download); the other five cases are unchanged. Checked against gh 2.46: download fails only when no pattern matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor sqlite-js main with our changes merged, one patch left Upstream merged our patches 0001 to 0009 (sqliteai/sqlite-js #11 to #19) on 2026-11-12, with fixes of its own. One fixes a bug in our 0002: a memory limit lowered under memory that is garbage left the connection out of memory until the limit was raised again (ef06558). upstream/ is now sqlite-js main at c8ae85a, the same source as the Termux package 1.3.7-p20261112, with one patch: 0001, sqlitejs_cancel_all(), our old 0010 rebased. Its test now fails with a message when the JavaScript under test has not started within 10 seconds, instead of cancelling anyway, and uses upstream's watchdog thread instead of alarm(). The patch is offered upstream in sqliteai/sqlite-js issue 20. vendor.sh, test.sh and test-sqlite-js.yml take the commit (COMMIT, URL) instead of the release tag. vendor.sh --check passes; test.sh passes: upstream's suite 16 of 16 with Cancel all, glue_test 18 of 18. The upstream suite with the patch also passes under ASan + UBSan; without the patch's sqlite3_interrupt() its collation case runs until the watchdog, and with started() never called the worker fails with its message. The native library builds with NDK 29 for arm64-v8a and armeabi-v7a, with no warnings in sqlitejs.c or sqlitejs_android.c, and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the sqlite-js 1.4.1 release Upstream released 1.4.0 and 1.4.1 on 2026-11-12, after c8ae85a. Both contain it, and 1.4.1 differs from it in src/ and libs/ only in SQLITE_JS_VERSION, so js_version() now reports 1.4.1. vendor.sh, test.sh and test-sqlite-js.yml take the release's archive again (VERSION, SHA256, URL). Patch 0001 is unchanged but for its context. The scripts now take the archive's one top directory whatever its name (tar --strip-components=1). They named it after COMMIT, so the README's "point URL at its tag again" would have failed: a tag's archive unpacks to sqlite-js-<tag> (independent review). The README says how to vendor a release, and a commit between releases. vendor.sh --check passes on the 1.4.1 archive (SHA-256 d45d394f...3078). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a connection open, and its stored functions load, during a cancel A cancelAll() that landed while another thread opened a connection made that connection fail to load sqlite-js (SQLITE_NOMEM), so a Room query on a new pool connection failed (independent review). Setting up the runtime runs JavaScript of its own, which the interrupt handler stopped. Patch 0001 now cancels only JavaScript inside a call (js_enter), and its Cancel all test opens 200 connections while another thread cancels without pause: the first one failed before. A cancel that lands while the trusted entry point loads a stored function stops that function's code the same way, and the function was then missing from the connection for good. load_stored_function now tries such a load again, up to three tries in all; its stored code runs again each time. glue_test.c stores a function whose code cancels the first time it loads: it loads on the second try, and with one try it is missing. The README and SqliteJs's Javadoc say both. test.sh passes: upstream's suite 16 of 16, glue_test 22 of 22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Patch two stack-bound crashes and two garbage cases 0002, after CodeRabbit's review: code that called itself without end crashed the process instead of failing with "Maximum call stack size exceeded" in two cases. - On a thread with less than 64 KB of stack left, js_enter kept the connection's 1 MB size rather than the room it measured. It now keeps any measurement, and 1 rather than 0, which turns the check off. - On the main thread, RLIMIT_STACK was counted from where the first measurement was taken. Loaded 2 MB deep, the extension allowed 10.2 MB of an 8 MB stack. It is now counted from the stack's top, as the kernel counts it. 0003, after the independent review of terminal-packages #6: garbage could leave an allocation that fits in the memory limit failing on every try. After 40 MB of cyclic garbage, new ArrayBuffer(30 MB) failed under the 64 MB default. And after a limit was lowered to 32 MB above the garbage, new ArrayBuffer(16 MB) failed. The extension now collects after any "out of memory" error and whenever a limit is set. Each patch adds tests to upstream's suite that fail without it. The suite passes 16 of 16 with all three patches, also under ASan and UBSan, and test.sh's glue_test 22 of 22. The NDK 29 build for arm64-v8a and armeabi-v7a has no warnings outside QuickJS and exports the same four symbols. Both fixes are offered upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a re-run replace a release left as a draft gh release create makes a draft and publishes it once its assets are uploaded. A first run that stopped during that upload left a draft: the next run found it, skipped the create, and failed fetching its tag, which a draft does not have yet. Every re-run then failed (independent review). The step now deletes a draft release, which dev-assets cannot fetch from, and creates the release again. Tested with a stub gh over a fake release, eight cases. The draft case failed with a 404 before, and now ends with the new assets and tag. The other seven are unchanged: no release, normal, upload fails, tag update fails, both assets missing, one missing, and upload fails with both missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * style: spotless reformat, no functional change Spotless wraps the cancelAll() Javadoc paragraph, which the previous commits lengthened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: End the result sets an interrupted call leaves open CodeRabbit: SQLite keeps an interrupt in effect while any statement of the connection runs, and a db.exec result set that JavaScript keeps open is a running statement. After cancelAll() stopped JavaScript that kept one in a global, every later statement on that connection failed with "interrupted", until the connection closed. A stored function whose code kept one could not load on any of its three tries. sqlite3_interrupt() does the same, without our cancel patch. Patch 0004 lists each connection's result sets. When the outermost call into JavaScript returns on an interrupted connection, it finalizes those still open. Reading on from one that JavaScript kept throws "interrupted". Reproduced on the host, with a cancel and with sqlite3_interrupt(): every later statement failed before, and all run after. Upstream's Interrupt test interrupts code that keeps a result set, in a global and as garbage, and fails without the patch. glue_test.c stores a function whose code keeps one and cancels the first time it loads. It loads on its second try, and the connection runs SQL afterwards; without the patch, those three checks fail. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for arm64-v8a and armeabi-v7a has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Make ending result sets safe when it runs JavaScript, and on old SQLite CodeRabbit, on 0004: - 0005: finalizing a result set that is computing a JavaScript window function runs the function's final, whose js_leave() ended the result sets again on the interrupted connection, finalizing the same statement twice. Under ASan that is a use after free in sqlite3VdbeMemFinalize, reproduced on the host. Each statement is now taken from its result set before it is finalized, the list is walked again from its head after each one, and a nested call does nothing. Upstream's Interrupt test now keeps a result set computing a window function; it fails under ASan without 0005. - 0006: on SQLite before 3.41, which has no sqlite3_is_interrupted(), 0004 never ran, though a cancel still interrupts the connection. The interrupt handler now records the interrupt it sends. Built to report SQLite 3.40, a cancel of JavaScript that keeps a result set left every later statement failing before 0006, and not after. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Stop what ending result sets runs; count the interrupts db.exec sees CodeRabbit, two more cases on SQLite before 3.41, both in patch 0007: - Ending result sets after a cancel can run a window or aggregate function's final, which begins after the cancel, so nothing stopped it: a final that never ended hung the cancelled query. The interrupt handler now stops any JavaScript while result sets are being ended. - A direct sqlite3_interrupt() that reached a db.exec statement's SQL, with another result set kept open, went unseen. A result set whose step returns SQLITE_INTERRUPT now records it. Checked with the patched source built to report SQLite 3.40: the endless final hung before and ends after, and a direct interrupt during db.exec's SQL, caught or not, left later statements failing before and not after. Still unseen before 3.41, and said in the README: an interrupt that never reaches the SQL that JavaScript runs. Android's cancelling never calls sqlite3_interrupt(), and cancelAll() is covered. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer the independent review of patches 0004 to 0007 - 0009: a result set's SQLITE_INTERRUPT now counts as an interrupt only before SQLite 3.41. A progress handler that stops a statement, as Android's cancelling does, gives the same code and interrupts nothing else, yet it ended the result sets earlier calls kept, on any SQLite. - 0008: the Interrupt test's "garbage" result set was freed by reference counting, so the case passed without 0004. It is now a reference cycle, and fails on 1.4.1 without 0004. Also pushed to sqliteai/sqlite-js#24. - Tests for 0006, 0007 and 0009, which had none: glue_test.c cancels JavaScript that keeps a result set, then a kept window function whose final never ends, then has a progress handler stop a statement. test.sh runs it twice, the second time with sqlitejs.c built to report SQLite 3.40. Without 0009 the progress-handler check fails; without 0007 the 3.40 run hangs until the test's 30 s alarm; without 0006 seven checks fail in the 3.40 run. - README: a cancel ends every result set open on the connection, not only the stopped call's. And on any SQLite, an sqlite3_interrupt() that lands while no JavaScript runs leaves the connection failing while JavaScript keeps a result set, so finish result sets before a call returns. Reproduced on 3.49: every later statement fails, and sqlite3_close returns SQLITE_BUSY. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 34 of 34 in both runs. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Test a direct interrupt during db.exec with a result set kept CodeRabbit: the case that 0007's record of a step's SQLITE_INTERRUPT is for had no automated test. glue_test.c now keeps a result set, has another thread call sqlite3_interrupt() while db.exec runs a query that never ends otherwise, and checks that the connection runs SQL and that the kept result set was ended. In the run as SQLite 3.40, those checks fail without the record. The checks that a kept result set was ended now tell an ended one (caught in JavaScript: "ended: interrupted") from a connection that is still interrupted, whose error is the same word. test.sh passes: upstream's suite 16 of 16, and glue_test 37 of 37 in both runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the sqlite-js 1.4.2 release Upstream released 1.4.2 with our stack, garbage-collection and result-set patches merged (sqliteai/sqlite-js #22, with two maintainer commits, #23 and #24) and with a fix for the use after free we reported (#25). That fix also changes behaviour: a db.exec result set no longer outlives the call into JavaScript that created it, and reading one afterwards throws "The result set was closed when the call into JavaScript that created it returned". So patches 0002 to 0009 go: - 0002 to 0005 and 0008 are upstream, by patch-id identical except for 0002, which has the maintainer's two commits on top. - 0006, 0007 (its second half) and 0009 only told interrupts apart for result sets kept across calls, which 1.4.2 no longer allows. 0001 (sqlitejs_cancel_all, issue 20) is rebased: the same changes, with new context in the struct. A new 0002 keeps what 0006 and the first half of 0007 did for a cancel on SQLite before 3.41: ending a cancelled call's result sets runs the finals of the window and aggregate functions they were computing, each a call that begins after the cancel, which before 3.41 nothing else stops; and those result sets read on as "interrupted". It is narrowed to a cancelled call, since in 1.4.2 result sets are also ended on every normal return. The next commit updates the tests for 1.4.2. vendor.sh --check passes on the 1.4.2 archive (SHA-256 1aa4c566...cf24). The libs/ and license files are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Test sqlite-js 1.4.2's result-set rule and patch 0002 glue_test.c, for 1.4.2: - The progress-handler case kept a result set across calls, which 1.4.2 no longer allows. It now checks, within one call, that a statement a progress handler stopped (as Android's cancelling does) leaves the call's other result set readable, on any SQLite, and that the connection runs SQL afterwards. - A direct sqlite3_interrupt() before SQLite 3.41 shows nowhere, so its kept result set reads as one that outlived its call; on 3.41 and later, as interrupted. - The cleanup that read a kept result set after its call is gone: it now throws. test.sh and the README name patch 0002 for the run as on SQLite 3.40, and the README lists the two patches, states the 1.4.2 rule, and says the 1.4.2 build has not been run on a phone yet. test.sh: upstream's suite 17 of 17 (its 16 and 0001's Cancel all), and glue_test 37 of 37 both normally and as on SQLite 3.40. Without patch 0002, the normal run still passes 37 of 37, and the 3.40 run fails as expected: the kept result set after a cancel reads "The result set was closed ..." rather than "interrupted", and the window function whose final never ends hangs until the 30 s alarm stops the test. Both ABIs build with NDK 29, and libsqlitejs.so exports only JNI_OnLoad and the three entry points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Keep a call's cancel for the finals its result sets run From the independent review of 3a5cb53 and 464e6e7 (no critical, high or medium findings; F01 to F05 low or nits). Patch 0002 told a cancelled call apart only once, in js_leave(), and each final that ending its result sets ran entered JavaScript as a new call with a new cancel epoch. So, before SQLite 3.41: - a cancel that landed while the result sets were ended stopped only the final then running, and the next final that never ended hung the statement (F01); - a cancel that landed just before the call returned let the call succeed with its finals skipped, on any SQLite (F02). Patch 0002 now keeps the call's epoch while its result sets are ended (js_enter), so a cancel during the call or the ending stops every final, and a late cancel fails the statement with an interrupt. The ending_cancelled flag and its interrupt-handler check are gone; the patch is 8 lines. upstream/ is regenerated with vendor.sh. glue_test.c, 44 tests (was 37): - 31: a cancelled call that keeps two result sets whose window finals never end (F03's case); - 33-34: the cancel lands during the first final of a call that returned normally (F01); - 36-37: a cancel that lands as the call returns fails it (F02); - 43: after a progress handler's stop, the kept result set reads as outliving its call, not as interrupted (F04; it passes without the fix too, as a guard against counting such a stop as an interrupt). test.sh: upstream's suite 17 of 17; the glue test 44 of 44 normally and as on SQLite 3.40. With the previous 0002, test 37 fails in the normal run and the 3.40 run hangs at test 34; with 0001 alone, test 37 fails, and the 3.40 run fails test 29 and hangs at test 31. README: what 0002 does now, and what the glue test covers (F05). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Say what a late cancel does to a call's finals From the independent review of 5b9b062 (no code defects; tests catch what they're named for and are not flaky in 120 runs on 2 cores and 16 on 1; two low findings and a nit): - F01: "those result sets read on as interrupted" holds only when the cancel came before the call returned. js_leave() decides that once, before ending them, so a cancel that lands while they are ended stops their finals but leaves the "closed" message. - F02: a cancel stops each final at QuickJS's next interrupt check. A final that never ends is stopped and the statement fails, but a short final can still run to its end, so "rather than skipping its finals" overstated it. The patch 0002 header and README say so; 5b9b062's message overstated both in the same way. Patch 0002's code is unchanged. - F03: test 36's final records that it ran, and a new test 38 checks that the late cancel stopped it before it did; test 37 is renamed to say its final is a long one. test.sh: upstream's suite 17 of 17; the glue test 45 of 45 normally and as on SQLite 3.40. With 0001 alone, tests 37 and 38 fail (the final ran to its end) and the 3.40 run fails 29 and hangs at 31; with the previous 0002, test 37 fails and the 3.40 run hangs at 34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Read result sets as interrupted when the cancel lands while they are ended From CodeRabbit's review of 5b5cd20 (4570522172), the same gap the independent review noted as F01: js_leave() decides once, before ending a call's result sets, whether they read on as "interrupted". A cancel that landed while their finals ran stopped the finals but left the "closed when the call ... returned" message. Patch 0002 now has js_end_rowsets() number its passes and mark each result set with the pass that ended it. After the loop, where nothing runs JavaScript and so no final can have freed a listed result set, it marks that pass's result sets interrupted if the cancel epoch has moved. The README and the patch header say the message is "interrupted" whether the cancel came before the call returned or during the ending. glue_test.c: new test 36 reads both result sets after the cancel that lands during the ending, and expects "interrupted". test.sh: upstream's suite 17 of 17; the glue test 46 of 46 normally and as on SQLite 3.40, and the same under AddressSanitizer and UBSan. With the previous 0002, test 36 fails in both runs with the "closed" message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Address review of the sqlite-js cancel patches Patch 0002 (rebuilt from upstream PR sqliteai/sqlite-js#33) now: - drops the redundant cancelled term from js_leave: the block after the loop in js_end_rowsets marks a cancelled call's result sets interrupted; - says only JavaScript the extension runs while it initialises a connection is exempt from a cancel, not js_init_table's stored functions; - initialises a rowset's end_pass where it is created; - documents sqlitejs_cancel_all in sqlitejs.h. upstream/ is regenerated with vendor.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the sqlite-js 1.4.3 release, with no patches Upstream merged sqliteai/sqlite-js#33, our patches 0001 (cancel) and 0002 (a cancelled call's finals and result sets) unmodified, and released them in 1.4.3 with one fix of the maintainer's: a cancel no longer stops a stored function's code while js_init_table(1) loads it, as it already spared the JavaScript that loads the extension. Before, a cancel in flight left the connection without that function. Only that call is exempt: JavaScript the code runs through SQL is still cancelled. - upstream/ is plain 1.4.3; patches/ is gone. vendor.sh and test.sh apply any patches/ there may be later (nullglob). - The glue still loads a stored function up to three times, for the case 1.4.3 still cancels. glue_test.c: new test 20 checks that a cancel during a function's own load code does not stop it (fails on 1.4.2 with the two patches); the w and h tests now cancel JavaScript that the load code runs through SQL (they fail with one try). - README, SqliteJs.cancelAll() javadoc: a cancel interrupts the connection, so any other statement in progress on it fails too, and it spares loading stored functions. The README now says the 1.4.2 build passed on the phone and the 1.4.3 build has not run on one yet. test.sh: upstream's suite 17 of 17; glue test 50 of 50 normally and as on SQLite 3.40, and the same under ASan, LeakSanitizer and UBSan. vendor.sh --check passes. NDK 29 builds for both ABIs: no warnings, the same four exports, version string 1.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * style: spotless rewrap of the cancelAll() javadoc, no functional change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer the independent review of the 1.4.3 move No correctness defects; two nits: - F01: two glue-test comments still credited "patch 0002" for what sqlite-js 1.4.3 now does. - F02: the v test assumed cancel_calls was still 0; it now resets it, as the w and h tests do. Glue test 50 of 50 normally and as on SQLite 3.40. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Record the phone run of the 1.4.3 build On the Note20, with an AAR built from 0c2e603: the trial app passes 7 of 7 as a 64-bit and as a 32-bit process, on a new and an existing database, and the template (dev-assets #79) stops its runaway query 11 to 12 ms after Cancel in its 64-bit and 32-bit debug builds and its release build. The README said the 1.4.3 build had not run on a phone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer CodeRabbit's full review of the sqlite-js module - release-sqlite-js.yml: when the release is missing but its tag is left behind, move the tag to the commit being built before creating the release, since gh release create reuses an existing tag and ignores --target. - glue_test.c: a worker thread that cannot start stops the run (exit 2), as a database that cannot open does, instead of returning SQLITE_ERROR, which the cancel checks accepted as a pass. - test.sh: upstream's test main leaves its "Memory" (leak) check out of its exit code, so any FAILED line in its output fails the run too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Take only a 404 for a missing sqlite-js release or tag The release step took any failed lookup for a missing release, so a passing API error could move the live release's tag before gh release create failed, and a failed tag lookup skipped the move the last commit added. exists() now answers 1 only for HTTP 404 and stops the job on any other error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…bug builds (#2259) * ADFA-7082: Vendor sqlite-js 1.3.7 with our patches sqlite-js 1.3.7 (Apache-2.0, with QuickJS/quickjs-ng amalgamated in libs/quickjs.c, MIT), only the files the AAR build uses, with patches/ applied: 0001-0008 are the Termux package's (terminal-packages packages/sqlite-js), 0009 makes each call measure its own thread's stack, and 0010 adds sqlitejs_cancel_all(). 0001-0009 are sent upstream as sqliteai/sqlite-js #11-#19. vendor.sh rebuilds upstream/ and the license notices from the release (checked against its SHA-256) and patches/, or with --check tells whether they match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Build the sqlite-js AAR for apps in subprojects:sqlite-js The AAR the JavaScript-in-SQLite project template depends on: libsqlitejs.so for arm64-v8a, armeabi-v7a and x86_64 (minSdk 26), and SqliteJs: cancelAll(), libraryPath(), ENTRY_POINT (loads the functions stored in js_functions on every connection) and ENTRY_POINT_FOR_DEFINING. sqlitejs_android.c, ours, holds the JNI and that entry point; the version script exports only the entry points and JNI_OnLoad. Nothing in CoGo depends on the module. AndroidModuleConf leaves it without the v7/v8 flavors, like :plugin-api, since one AAR serves every ABI, and without core-library desugaring, like :logsender, so apps need not enable it. Tested in a trial app (requery 3.49.0, Room 2.8.4) on a Galaxy Note20 Ultra as a 64-bit and a 32-bit process: scalar and aggregate from DAOs, deep recursion on pool threads, 32 parallel queries under WAL, and a runaway query stopped by cancelAll() within 5 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Release the sqlite-js AAR to sqlite-js-latest A manual workflow, like release-plugin-api.yml: checks the vendored sqlite-js, builds the AAR from main, and replaces the moving sqlite-js-latest release, from which dev-assets fetches it into the template that uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Build the sqlite-js AAR for arm64-v8a and armeabi-v7a only Apps built with Code on the Go run on ARM phones, so the AAR no longer carries x86_64. ADR 0005 says so. CLAUDE.md's ABI section now names the two modules without v7/v8 flavors, as ARCHITECTURE.md and ADR 0005 do (review of PR #2244, F07). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Run no stored code by default; test sqlite-js on pull requests From the reviews of PR #2244 (independent F02, F03, F05, F06; CodeRabbit): - ENTRY_POINT (sqlite3_sqlitejs_init, also the name SQLite derives from libsqlitejs.so) now loads sqlite-js alone. The old entry point loaded the functions stored in js_functions, which runs their code, so any database file the app opened ran its stored JavaScript at once. Loading them is now ENTRY_POINT_FOR_TRUSTED_DATABASE (sqlite3_sqlitejs_trusted_init), for databases the app made. ENTRY_POINT_FOR_DEFINING is gone: ENTRY_POINT does that job. - The trusted entry point loads each stored function on its own, so one that fails is logged and skipped instead of dropping those after it. - cancelAll()'s Javadoc and the README say it stops JavaScript in every query, so call it only for a known runaway and repeat it until the query ends. - test.sh runs upstream's test suite with patches/, and glue_test.c, the first test of sqlitejs_android.c. test-sqlite-js.yml runs vendor.sh --check and test.sh on pull requests for this module. glue_test.c passes 14 of 14; against the old glue 5 fail (stored functions loaded by ENTRY_POINT, functions after a broken one dropped). The AAR builds and exports the two entry points, sqlite3_js_init and JNI_OnLoad. Not run on a device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Update sqlite-js-latest in place, out of latest-release selection release-sqlite-js.yml deleted the release and its tag before making the new one, so a failed upload left dev-assets nothing to fetch. It now uploads the new assets over the old ones, putting the old ones back if that fails, then moves the tag and the notes. The release is created and kept with --latest=false, so it never becomes the repository's latest release (CodeRabbit, PR #2244). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Sort the QuickJS copyright lines the same on every machine vendor.sh built LICENSE.quickjs with sort -u in the machine's locale, so the new test-sqlite-js workflow's vendor.sh --check failed on the runner: en_US.UTF-8 and C order "2017" and "2017-2018" differently. It now sorts with LC_ALL=C, and upstream/LICENSE.quickjs and the META-INF notice are regenerated; only the order of their copyright lines changes. --check passes under C, C.UTF-8 and en_US.UTF-8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Log stored functions that cannot be listed; guard the tag move From CodeRabbit's review of the previous commits: - The trusted entry point returned silently when it could not list the stored functions (busy, out of memory, an odd table), opening the connection with some or none of them. Each failure is now logged; the connection still opens. It first looks js_functions up in sqlite_master, so a database without stored functions makes SQLite log no "no such table" error on each connection, as it did. - release-sqlite-js.yml moves the tag and edits the notes in the same guarded sequence as the upload. If any step fails, the previous assets and tag are put back. glue_test.c passes 16 of 16; the two new tests fail on the previous glue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the reviewed sqlite-js patches Patches 0002, 0003, 0004 and 0010 are regenerated after three reviews: the independent reviews of terminal-packages #6 and of this PR, and CodeRabbit's review of this PR. - 0002: garbage is collected before the memory limit fills. Running out of memory through small allocations reports "out of memory". - 0003: the README says TEMP views and triggers can call the js_* functions. - 0004: db.exec throws for a buffer it cannot read instead of binding NULL. A typed array's own offset and length are used, not properties a script defines. - 0010: a cancel also interrupts the cancelled call's statement, so a runaway JavaScript collation stops. Before, nothing could stop one. The other patches change only in their headers and line numbers. upstream/ is regenerated with vendor.sh, and vendor.sh --check passes. SqliteJs.cancelAll() and the README say a cancel interrupts the statement too. Tested: - test.sh: upstream's suite passes 16 of 16, and the glue test 16 of 16. - In the work repo, the same suite passes under ASan and UBSan with leak checking, and each new test fails without its fix. - The AAR builds for arm64-v8a and armeabi-v7a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Put back both the assets and the tag if a release update fails From CodeRabbit's review: under bash -e, a failed restore of the previous assets stopped the rollback before it put the tag back, so the tag could name the new build while the release held the old one. Each restore is now attempted, reported if it fails, and the step still fails. Checked with gh stubbed out: when the update fails and the asset restore fails, the tag restore still runs and the step exits 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Find js_functions in any case; sync the cancel test; doc caveats From CodeRabbit's review of the vendored patches: - The trusted entry point looks up js_functions with COLLATE NOCASE, as SQLite resolves a table name, so a table named JS_FUNCTIONS loads. A new glue test, now 18 of 18, fails without it. - Patch 0010's Cancel all test cancels once the JavaScript under test has called started(), an SQL function, instead of after a fixed 200 ms. A slow start can no longer end the test at its alarm. It still hangs without the fix it tests. - SqliteJs.cancelAll() and the README now say two more things. An interrupted INSERT, UPDATE or DELETE in an explicit transaction rolls the whole transaction back. And a cancel reaches SQL that JavaScript runs through db.exec only when that SQL returns to JavaScript. Tested: - test.sh: upstream's suite passes 16 of 16, also under ASan and UBSan in the work repo, and the glue test 18 of 18. - vendor.sh --check passes. - The AAR builds with the new lookup for arm64-v8a and armeabi-v7a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a re-run repair a release left without its assets A run that stops during `gh release upload --clobber` can leave an asset missing. The next run then failed at the backup download ("no assets match the file pattern") before it uploaded anything, so re-running could not repair the release. The step now backs up only the assets that exist and puts the previous ones back only when it has both. Tested with a stub gh over a fake release: both assets missing now ends with the new pair and the tag moved (before: exit 1 at the download); the other five cases are unchanged. Checked against gh 2.46: download fails only when no pattern matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor sqlite-js main with our changes merged, one patch left Upstream merged our patches 0001 to 0009 (sqliteai/sqlite-js #11 to #19) on 2026-11-12, with fixes of its own. One fixes a bug in our 0002: a memory limit lowered under memory that is garbage left the connection out of memory until the limit was raised again (ef06558). upstream/ is now sqlite-js main at c8ae85a, the same source as the Termux package 1.3.7-p20261112, with one patch: 0001, sqlitejs_cancel_all(), our old 0010 rebased. Its test now fails with a message when the JavaScript under test has not started within 10 seconds, instead of cancelling anyway, and uses upstream's watchdog thread instead of alarm(). The patch is offered upstream in sqliteai/sqlite-js issue 20. vendor.sh, test.sh and test-sqlite-js.yml take the commit (COMMIT, URL) instead of the release tag. vendor.sh --check passes; test.sh passes: upstream's suite 16 of 16 with Cancel all, glue_test 18 of 18. The upstream suite with the patch also passes under ASan + UBSan; without the patch's sqlite3_interrupt() its collation case runs until the watchdog, and with started() never called the worker fails with its message. The native library builds with NDK 29 for arm64-v8a and armeabi-v7a, with no warnings in sqlitejs.c or sqlitejs_android.c, and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the sqlite-js 1.4.1 release Upstream released 1.4.0 and 1.4.1 on 2026-11-12, after c8ae85a. Both contain it, and 1.4.1 differs from it in src/ and libs/ only in SQLITE_JS_VERSION, so js_version() now reports 1.4.1. vendor.sh, test.sh and test-sqlite-js.yml take the release's archive again (VERSION, SHA256, URL). Patch 0001 is unchanged but for its context. The scripts now take the archive's one top directory whatever its name (tar --strip-components=1). They named it after COMMIT, so the README's "point URL at its tag again" would have failed: a tag's archive unpacks to sqlite-js-<tag> (independent review). The README says how to vendor a release, and a commit between releases. vendor.sh --check passes on the 1.4.1 archive (SHA-256 d45d394f...3078). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a connection open, and its stored functions load, during a cancel A cancelAll() that landed while another thread opened a connection made that connection fail to load sqlite-js (SQLITE_NOMEM), so a Room query on a new pool connection failed (independent review). Setting up the runtime runs JavaScript of its own, which the interrupt handler stopped. Patch 0001 now cancels only JavaScript inside a call (js_enter), and its Cancel all test opens 200 connections while another thread cancels without pause: the first one failed before. A cancel that lands while the trusted entry point loads a stored function stops that function's code the same way, and the function was then missing from the connection for good. load_stored_function now tries such a load again, up to three tries in all; its stored code runs again each time. glue_test.c stores a function whose code cancels the first time it loads: it loads on the second try, and with one try it is missing. The README and SqliteJs's Javadoc say both. test.sh passes: upstream's suite 16 of 16, glue_test 22 of 22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Patch two stack-bound crashes and two garbage cases 0002, after CodeRabbit's review: code that called itself without end crashed the process instead of failing with "Maximum call stack size exceeded" in two cases. - On a thread with less than 64 KB of stack left, js_enter kept the connection's 1 MB size rather than the room it measured. It now keeps any measurement, and 1 rather than 0, which turns the check off. - On the main thread, RLIMIT_STACK was counted from where the first measurement was taken. Loaded 2 MB deep, the extension allowed 10.2 MB of an 8 MB stack. It is now counted from the stack's top, as the kernel counts it. 0003, after the independent review of terminal-packages #6: garbage could leave an allocation that fits in the memory limit failing on every try. After 40 MB of cyclic garbage, new ArrayBuffer(30 MB) failed under the 64 MB default. And after a limit was lowered to 32 MB above the garbage, new ArrayBuffer(16 MB) failed. The extension now collects after any "out of memory" error and whenever a limit is set. Each patch adds tests to upstream's suite that fail without it. The suite passes 16 of 16 with all three patches, also under ASan and UBSan, and test.sh's glue_test 22 of 22. The NDK 29 build for arm64-v8a and armeabi-v7a has no warnings outside QuickJS and exports the same four symbols. Both fixes are offered upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a re-run replace a release left as a draft gh release create makes a draft and publishes it once its assets are uploaded. A first run that stopped during that upload left a draft: the next run found it, skipped the create, and failed fetching its tag, which a draft does not have yet. Every re-run then failed (independent review). The step now deletes a draft release, which dev-assets cannot fetch from, and creates the release again. Tested with a stub gh over a fake release, eight cases. The draft case failed with a 404 before, and now ends with the new assets and tag. The other seven are unchanged: no release, normal, upload fails, tag update fails, both assets missing, one missing, and upload fails with both missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * style: spotless reformat, no functional change Spotless wraps the cancelAll() Javadoc paragraph, which the previous commits lengthened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: End the result sets an interrupted call leaves open CodeRabbit: SQLite keeps an interrupt in effect while any statement of the connection runs, and a db.exec result set that JavaScript keeps open is a running statement. After cancelAll() stopped JavaScript that kept one in a global, every later statement on that connection failed with "interrupted", until the connection closed. A stored function whose code kept one could not load on any of its three tries. sqlite3_interrupt() does the same, without our cancel patch. Patch 0004 lists each connection's result sets. When the outermost call into JavaScript returns on an interrupted connection, it finalizes those still open. Reading on from one that JavaScript kept throws "interrupted". Reproduced on the host, with a cancel and with sqlite3_interrupt(): every later statement failed before, and all run after. Upstream's Interrupt test interrupts code that keeps a result set, in a global and as garbage, and fails without the patch. glue_test.c stores a function whose code keeps one and cancels the first time it loads. It loads on its second try, and the connection runs SQL afterwards; without the patch, those three checks fail. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for arm64-v8a and armeabi-v7a has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Make ending result sets safe when it runs JavaScript, and on old SQLite CodeRabbit, on 0004: - 0005: finalizing a result set that is computing a JavaScript window function runs the function's final, whose js_leave() ended the result sets again on the interrupted connection, finalizing the same statement twice. Under ASan that is a use after free in sqlite3VdbeMemFinalize, reproduced on the host. Each statement is now taken from its result set before it is finalized, the list is walked again from its head after each one, and a nested call does nothing. Upstream's Interrupt test now keeps a result set computing a window function; it fails under ASan without 0005. - 0006: on SQLite before 3.41, which has no sqlite3_is_interrupted(), 0004 never ran, though a cancel still interrupts the connection. The interrupt handler now records the interrupt it sends. Built to report SQLite 3.40, a cancel of JavaScript that keeps a result set left every later statement failing before 0006, and not after. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Stop what ending result sets runs; count the interrupts db.exec sees CodeRabbit, two more cases on SQLite before 3.41, both in patch 0007: - Ending result sets after a cancel can run a window or aggregate function's final, which begins after the cancel, so nothing stopped it: a final that never ended hung the cancelled query. The interrupt handler now stops any JavaScript while result sets are being ended. - A direct sqlite3_interrupt() that reached a db.exec statement's SQL, with another result set kept open, went unseen. A result set whose step returns SQLITE_INTERRUPT now records it. Checked with the patched source built to report SQLite 3.40: the endless final hung before and ends after, and a direct interrupt during db.exec's SQL, caught or not, left later statements failing before and not after. Still unseen before 3.41, and said in the README: an interrupt that never reaches the SQL that JavaScript runs. Android's cancelling never calls sqlite3_interrupt(), and cancelAll() is covered. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer the independent review of patches 0004 to 0007 - 0009: a result set's SQLITE_INTERRUPT now counts as an interrupt only before SQLite 3.41. A progress handler that stops a statement, as Android's cancelling does, gives the same code and interrupts nothing else, yet it ended the result sets earlier calls kept, on any SQLite. - 0008: the Interrupt test's "garbage" result set was freed by reference counting, so the case passed without 0004. It is now a reference cycle, and fails on 1.4.1 without 0004. Also pushed to sqliteai/sqlite-js#24. - Tests for 0006, 0007 and 0009, which had none: glue_test.c cancels JavaScript that keeps a result set, then a kept window function whose final never ends, then has a progress handler stop a statement. test.sh runs it twice, the second time with sqlitejs.c built to report SQLite 3.40. Without 0009 the progress-handler check fails; without 0007 the 3.40 run hangs until the test's 30 s alarm; without 0006 seven checks fail in the 3.40 run. - README: a cancel ends every result set open on the connection, not only the stopped call's. And on any SQLite, an sqlite3_interrupt() that lands while no JavaScript runs leaves the connection failing while JavaScript keeps a result set, so finish result sets before a call returns. Reproduced on 3.49: every later statement fails, and sqlite3_close returns SQLITE_BUSY. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 34 of 34 in both runs. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Test a direct interrupt during db.exec with a result set kept CodeRabbit: the case that 0007's record of a step's SQLITE_INTERRUPT is for had no automated test. glue_test.c now keeps a result set, has another thread call sqlite3_interrupt() while db.exec runs a query that never ends otherwise, and checks that the connection runs SQL and that the kept result set was ended. In the run as SQLite 3.40, those checks fail without the record. The checks that a kept result set was ended now tell an ended one (caught in JavaScript: "ended: interrupted") from a connection that is still interrupted, whose error is the same word. test.sh passes: upstream's suite 16 of 16, and glue_test 37 of 37 in both runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7135: Define the interface between the SQLite debugger extension and its server sqlitedbg.h is what the extension implements and its JNI layer calls; DebugEngine.kt is what the server (ADFA-7136) builds against, with a fake for JVM tests. Not yet built by Gradle: the module has no build file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: Copy the MCP server from ShareYourApps, renamed McpHttp.kt and McpProtocol.kt from Local Store Server Combined with only the package, server name, title, instructions and 401 texts changed. McpProtocolTest.kt still names that project's tools and does not compile; ADFA-7136 rewrites it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Add the sqlite-debugger module skeleton Module build file modelled on sqlite-js (no ABI flavors, both ABIs, no STL, 16 KiB pages), plus Kotlin at API 2.0 for apps built with CoGo. Registered in settings, modulesWithoutAbiFlavors and disableCoreLibDesugaringForModules. The CMake file arrives with the extension in the next commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: MCP server with the eight read-only database tools Binds 127.0.0.1 on port 0 with a new token per process start, and serves list_databases, list_connections, get_schema, query, explain_query_plan, get_stats, integrity_check and get_events against DebugEngine. JVM tests run against FakeDebugEngine (51 pass). DebuggerStartup.kt and the manifest are Android-only and not yet compiled. Formatting follows in its own commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Implement the SQLite debugger extension and its host tests sqlitedbg.c implements sqlitedbg.h as a loadable-extension client. Per-connection state is freed only from the xDestroy of sqlitedbg_connection_id; the trace CLOSE event only marks it closing. Events live in a ring of records in their exported layout. Server connections are recognised by a thread-local flag set around sqlitedbg_open_server's own open. test.sh builds SQLite 3.49.1 from the amalgamation (pinned) and runs sqlitedbg_test.c under ASan+UBSan and under TSan. The same run writes or checks the fixture the EventDecoder JVM test reads. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Add the JNI layer and NativeDebugEngine sqlitedbg_jni.c registers NativeBridge's natives from JNI_OnLoad (the version script exports nothing else) and reaches SQLite only through the extension's api table. ServerConnection.query steps the statement in C, binds args by type, applies QueryLimits, and stops at the deadline through a progress handler on the server connection. EventDecoder mirrors the exported record layout and is tested against the fixture the host C test writes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * style: spotless reformat of the SQLite debugger module, no functional change Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Fix three review findings in the extension - read_events moves the cursor past dropped events when it copies nothing, so a drop is reported once. - An internal failure in sqlitedbg_extension_init is logged and the connection left untracked; the app's own sqlite3_open no longer fails because of it. - A trigger is told apart from app SQL by X differing from sqlite3_sql(P), not by a "--" prefix, so statements that start with a comment are expanded. test.sh builds the extension with SQLITEDBG_TEST for the failure hook. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: Document the SQLite debugger module Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: List sqlite-debugger among the modules without ABI flavors AndroidModuleConf.kt already excludes it; ARCHITECTURE.md and CLAUDE.md named only plugin-api and sqlite-js. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Never let the debugger crash or miss the host app's early connections - DebuggerStartup catches Throwable after the debuggable check, so a missing requery library (UnsatisfiedLinkError) disables the debugger instead of killing the app. The check itself still throws. - install() runs synchronously in onCreate; only the server start is on the thread, so connections opened in Application.onCreate are tracked. - McpHttp: connection and accept threads catch Throwable; an Error while handling a request is answered with a 500. - McpHttp: a failed accept sleeps 100 ms, doubling to 2 s while failures continue, and resets on success (no spin on EMFILE). Tests: an Error thrown by a tool gives HTTP 500 and the server keeps serving; a ServerSocket whose accept fails is retried with growing gaps, then serves. DebuggerStartup imports android.* and has no JVM test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Keep read-only server connections from holding locks The read-only authorizer allowed BEGIN, SAVEPOINT and PRAGMA locking_mode, so a client could hold a lock on the app's database: BEGIN; SELECT left the app's INSERT failing with SQLITE_BUSY until ROLLBACK. - sqlitedbg.c: deny SQLITE_TRANSACTION, SQLITE_SAVEPOINT, PRAGMA locking_mode and PRAGMA busy_timeout (any form) on read-only server connections. - sqlitedbg_jni.c: bridge_query rolls back if the connection is not in autocommit when it returns (covers writable connections). - Host C test: each denied statement returns SQLITE_AUTH and the app can still write after a read on that connection. Without the authorizer change the test fails on all 8 statements (BEGIN and SAVEPOINT: "database is locked" for the app's INSERT). The backstop is tested with the JNI test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Bound query results and report truncation per cell - M4: QueryLimits.maxTotalBytes (DatabaseTools passes 4 MiB). bridge_query counts the TEXT/BLOB bytes kept and 8 per number, and stops with hasMore before the row that would pass the budget; the first row always goes in so a page makes progress. The tool result text is serialised compact: it was sent twice, pretty and as structuredContent. - L11: the engine reports cut cells (QueryResult.truncatedCellIndexes, row * columns + column) instead of DatabaseTools guessing from size >= limit, so a BLOB of exactly maxBlobBytes is no longer flagged. - L12: get_schema and get_stats read sqlite_master (sqlite_schema needs 3.33). - L13: sqlite3_column_text/blob returning NULL (out of memory) is checked. JVM tests: blob at the limit vs one byte over, the budget pages a result of 3 MiB rows, sqlite_master in the SQL sent, compact result text. Each fails with its fix reverted. The native side (budget, cut cells) is tested by the JNI test in a later commit; L13 has no test (needs an allocation failure). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Drop stale server connections and stop expanding SQL when idle - M7: DatabaseTools cached a server connection per path forever, so after the app deleted and recreated its database the server read the old file. Each cached connection remembers the ids of the app connections to its path when it opened. Before each tool call it is closed and dropped when no live app connection has the path, or none of those ids is left. - L14: the first get_events turned on bound-value expansion until the server stopped, so every app statement was expanded twice forever. It now goes off 60 s after the last get_events call, checked on every tool call and by a daemon timer; the tool description says so. - L10 (one lock for all tool calls) is documented in the class KDoc. Tests: recreated database reopens (opened 2, closed 1), a connection survives while a seen app connection remains, a vanished path closes the cached one, and expansion stops after 60 s. Each fails with its fix reverted (expected 2 but was 1; expected 1 but was 0; "60 s after the last get_events"). Limit accepted: a database replaced in place while the same app connections stay open is not detected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Test the JNI query path test.sh now also builds the JNI layer as it ships (libsqlitedbg.so without SQLITE_CORE, with the version script) against a requery-like libsqlite3x.so (amalgamation, THREADSAFE=2, all symbols exported) and runs src/test/jni/JniQueryTest.java on the host JVM through NativeBridge. It is skipped with a message when no JDK is on PATH. It uses Java stubs of NativeBridge and DebugEngineException (same names and native signatures) rather than compiling the Kotlin, so only a JDK is needed; test.sh fails if the native names in NativeBridge.kt and the stub differ. A change of a Kotlin parameter type alone is not caught. Covers: value types, paging and hasMore, the total-bytes budget (including "first row always goes in" and the budget stopping on a row boundary), per-cell truncation at, over and under the limit with row * columns + column indexes and a budget-dropped row's cells, bound types, the deadline giving SQLITE_INTERRUPT, refused writes giving SQLITE_AUTH, BEGIN/SAVEPOINT/PRAGMA refusals leaving the app able to write, and the rollback backstop. Checked to fail with each native fix reverted: budget (50 rows vs 4), cut cell indexes ([] vs [1, 3]), rollback backstop (app INSERT 5 vs 0, SQLITE_BUSY), authorizer (BEGIN: 0 vs 23), dropped row's cut cells ([0, 1] vs [0]). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Document the JNI test and the requery trace limit README: the JNI test and how it stands in for the Kotlin, and that requery's own sqlite3_trace (log.tag.SQLiteStatements or SQLiteTime VERBOSE) replaces ours on a connection, so its events stop. No code change for that. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7082: Vendor the sqlite-js 1.4.2 release Upstream released 1.4.2 with our stack, garbage-collection and result-set patches merged (sqliteai/sqlite-js #22, with two maintainer commits, #23 and #24) and with a fix for the use after free we reported (#25). That fix also changes behaviour: a db.exec result set no longer outlives the call into JavaScript that created it, and reading one afterwards throws "The result set was closed when the call into JavaScript that created it returned". So patches 0002 to 0009 go: - 0002 to 0005 and 0008 are upstream, by patch-id identical except for 0002, which has the maintainer's two commits on top. - 0006, 0007 (its second half) and 0009 only told interrupts apart for result sets kept across calls, which 1.4.2 no longer allows. 0001 (sqlitejs_cancel_all, issue 20) is rebased: the same changes, with new context in the struct. A new 0002 keeps what 0006 and the first half of 0007 did for a cancel on SQLite before 3.41: ending a cancelled call's result sets runs the finals of the window and aggregate functions they were computing, each a call that begins after the cancel, which before 3.41 nothing else stops; and those result sets read on as "interrupted". It is narrowed to a cancelled call, since in 1.4.2 result sets are also ended on every normal return. The next commit updates the tests for 1.4.2. vendor.sh --check passes on the 1.4.2 archive (SHA-256 1aa4c566...cf24). The libs/ and license files are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Test sqlite-js 1.4.2's result-set rule and patch 0002 glue_test.c, for 1.4.2: - The progress-handler case kept a result set across calls, which 1.4.2 no longer allows. It now checks, within one call, that a statement a progress handler stopped (as Android's cancelling does) leaves the call's other result set readable, on any SQLite, and that the connection runs SQL afterwards. - A direct sqlite3_interrupt() before SQLite 3.41 shows nowhere, so its kept result set reads as one that outlived its call; on 3.41 and later, as interrupted. - The cleanup that read a kept result set after its call is gone: it now throws. test.sh and the README name patch 0002 for the run as on SQLite 3.40, and the README lists the two patches, states the 1.4.2 rule, and says the 1.4.2 build has not been run on a phone yet. test.sh: upstream's suite 17 of 17 (its 16 and 0001's Cancel all), and glue_test 37 of 37 both normally and as on SQLite 3.40. Without patch 0002, the normal run still passes 37 of 37, and the 3.40 run fails as expected: the kept result set after a cancel reads "The result set was closed ..." rather than "interrupted", and the window function whose final never ends hangs until the 30 s alarm stops the test. Both ABIs build with NDK 29, and libsqlitejs.so exports only JNI_OnLoad and the three entry points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Keep a call's cancel for the finals its result sets run From the independent review of 3a5cb5356 and 464e6e7ef (no critical, high or medium findings; F01 to F05 low or nits). Patch 0002 told a cancelled call apart only once, in js_leave(), and each final that ending its result sets ran entered JavaScript as a new call with a new cancel epoch. So, before SQLite 3.41: - a cancel that landed while the result sets were ended stopped only the final then running, and the next final that never ended hung the statement (F01); - a cancel that landed just before the call returned let the call succeed with its finals skipped, on any SQLite (F02). Patch 0002 now keeps the call's epoch while its result sets are ended (js_enter), so a cancel during the call or the ending stops every final, and a late cancel fails the statement with an interrupt. The ending_cancelled flag and its interrupt-handler check are gone; the patch is 8 lines. upstream/ is regenerated with vendor.sh. glue_test.c, 44 tests (was 37): - 31: a cancelled call that keeps two result sets whose window finals never end (F03's case); - 33-34: the cancel lands during the first final of a call that returned normally (F01); - 36-37: a cancel that lands as the call returns fails it (F02); - 43: after a progress handler's stop, the kept result set reads as outliving its call, not as interrupted (F04; it passes without the fix too, as a guard against counting such a stop as an interrupt). test.sh: upstream's suite 17 of 17; the glue test 44 of 44 normally and as on SQLite 3.40. With the previous 0002, test 37 fails in the normal run and the 3.40 run hangs at test 34; with 0001 alone, test 37 fails, and the 3.40 run fails test 29 and hangs at test 31. README: what 0002 does now, and what the glue test covers (F05). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Say what a late cancel does to a call's finals From the independent review of 5b9b062eb (no code defects; tests catch what they're named for and are not flaky in 120 runs on 2 cores and 16 on 1; two low findings and a nit): - F01: "those result sets read on as interrupted" holds only when the cancel came before the call returned. js_leave() decides that once, before ending them, so a cancel that lands while they are ended stops their finals but leaves the "closed" message. - F02: a cancel stops each final at QuickJS's next interrupt check. A final that never ends is stopped and the statement fails, but a short final can still run to its end, so "rather than skipping its finals" overstated it. The patch 0002 header and README say so; 5b9b062eb's message overstated both in the same way. Patch 0002's code is unchanged. - F03: test 36's final records that it ran, and a new test 38 checks that the late cancel stopped it before it did; test 37 is renamed to say its final is a long one. test.sh: upstream's suite 17 of 17; the glue test 45 of 45 normally and as on SQLite 3.40. With 0001 alone, tests 37 and 38 fail (the final ran to its end) and the 3.40 run fails 29 and hangs at 31; with the previous 0002, test 37 fails and the 3.40 run hangs at 34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7135 Set the Kotlin JVM target on the compile tasks The root build sets jvmTarget 17 on every KotlinCompile task, which overrides the module's kotlin { compilerOptions } and made compileDebugKotlin fail against compileOptions' Java 1.8 ("Inconsistent JVM-target compatibility"). Setting it on the tasks keeps 1.8, as sqlite-js uses. First compile of the Android-only files (NativeDebugEngine.kt, DebuggerStartup.kt, sqlitedbg_jni.c, the manifest): with this change :subprojects:sqlite-debugger:assembleDebug builds both ABIs, the C compiles without warnings under -Wall -Wextra, libsqlitedbg.so exports only JNI_OnLoad, and testDebugUnitTest passes 56 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-7082: Read result sets as interrupted when the cancel lands while they are ended From CodeRabbit's review of 5b5cd201c (4570522172), the same gap the independent review noted as F01: js_leave() decides once, before ending a call's result sets, whether they read on as "interrupted". A cancel that landed while their finals ran stopped the finals but left the "closed when the call ... returned" message. Patch 0002 now has js_end_rowsets() number its passes and mark each result set with the pass that ended it. After the loop, where nothing runs JavaScript and so no final can have freed a listed result set, it marks that pass's result sets interrupted if the cancel epoch has moved. The README and the patch header say the message is "interrupted" whether the cancel came before the call returned or during the ending. glue_test.c: new test 36 reads both result sets after the cancel that lands during the ending, and expects "interrupted". test.sh: upstream's suite 17 of 17; the glue test 46 of 46 normally and as on SQLite 3.40, and the same under AddressSanitizer and UBSan. With the previous 0002, test 36 fails in both runs with the "closed" message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Address review of the sqlite-js cancel patches Patch 0002 (rebuilt from upstream PR sqliteai/sqlite-js#33) now: - drops the redundant cancelled term from js_leave: the block after the loop in js_end_rowsets marks a cancelled call's result sets interrupted; - says only JavaScript the extension runs while it initialises a connection is exempt from a cancel, not js_init_table's stored functions; - initialises a rowset's end_pass where it is created; - documents sqlitejs_cancel_all in sqlitejs.h. upstream/ is regenerated with vendor.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7136 Bound the request head and refuse before reading the body; say the server is read-only A local app could hold all 8 connection slots without authenticating: the 30 s timeout applied per read and the token was checked after the whole request. The head now has an overall deadline (5 s), and Host, Origin, path and token are checked before the body. The initialize instructions no longer mention a read-write mode that does not exist. Tests: sockets that send nothing or trickle bytes are closed within the deadline and the real client is then served; an unauthenticated request with an unsent body gets 401; the instructions do not mention read-write. All three fail with the fix reverted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Refuse the process-wide heap limit and temp directory PRAGMAs on server connections SQLite applies hard_heap_limit, soft_heap_limit and temp_store_directory to the whole process, so a client's PRAGMA hard_heap_limit=1 could make the app's own connections fail with SQLITE_NOMEM. Test: each form (set and read) returns SQLITE_AUTH on a server connection; without the change all five return SQLITE_OK. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Give server connections a 3 s busy timeout With the app's database in rollback-journal mode, a server read failed at once with SQLITE_BUSY while the app held a write lock, exactly when the agent wants to look. The timeout is set in C and PRAGMA busy_timeout stays refused, so the client cannot change it. Test: an app connection holds BEGIN EXCLUSIVE; a server read waits about 500 ms and succeeds once it is released, and reports SQLITE_BUSY after about 3 s if it is not. Without the timeout the first read failed after 0 ms with SQLITE_BUSY. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Fail a query whose argument count differs from its parameter count Too few arguments left the missing parameters unbound, which SQLite reads as NULL, so the query ran and returned a plausible empty result. It now throws SQLITE_RANGE with a message naming both counts. Test (JniQueryTest, the real JNI query path on a host JVM, run by test.sh): zero args for one parameter and one for two give SQLITE_RANGE; the first expectation was NULL before, and both fail with the check disabled. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 List an open database once when the databases folder is reached through a link list_databases matched the files of the app's databases folder against connection paths as strings, so on a phone (/data/user/0/<pkg> against /data/data/<pkg>) every open database was listed again as available: false. Both sides are now canonicalised before matching; paths are reported as the connections gave them. Test: a folder listed through a symlink, and the reverse, list the open database once. Without the canonicalisation it was listed twice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Run the sqlite-debugger host tests in CI test.sh (the extension's C tests under ASan/UBSan and TSan, and the JNI query test) ran in no workflow. The new workflow follows test-sqlite-js.yml and also triggers on the vendored SQLite headers test.sh compares against. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7082: Vendor the sqlite-js 1.4.3 release, with no patches Upstream merged sqliteai/sqlite-js#33, our patches 0001 (cancel) and 0002 (a cancelled call's finals and result sets) unmodified, and released them in 1.4.3 with one fix of the maintainer's: a cancel no longer stops a stored function's code while js_init_table(1) loads it, as it already spared the JavaScript that loads the extension. Before, a cancel in flight left the connection without that function. Only that call is exempt: JavaScript the code runs through SQL is still cancelled. - upstream/ is plain 1.4.3; patches/ is gone. vendor.sh and test.sh apply any patches/ there may be later (nullglob). - The glue still loads a stored function up to three times, for the case 1.4.3 still cancels. glue_test.c: new test 20 checks that a cancel during a function's own load code does not stop it (fails on 1.4.2 with the two patches); the w and h tests now cancel JavaScript that the load code runs through SQL (they fail with one try). - README, SqliteJs.cancelAll() javadoc: a cancel interrupts the connection, so any other statement in progress on it fails too, and it spares loading stored functions. The README now says the 1.4.2 build passed on the phone and the 1.4.3 build has not run on one yet. test.sh: upstream's suite 17 of 17; glue test 50 of 50 normally and as on SQLite 3.40, and the same under ASan, LeakSanitizer and UBSan. vendor.sh --check passes. NDK 29 builds for both ABIs: no warnings, the same four exports, version string 1.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * style: spotless rewrap of the cancelAll() javadoc, no functional change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer the independent review of the 1.4.3 move No correctness defects; two nits: - F01: two glue-test comments still credited "patch 0002" for what sqlite-js 1.4.3 now does. - F02: the v test assumed cancel_calls was still 0; it now resets it, as the w and h tests do. Glue test 50 of 50 normally and as on SQLite 3.40. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Record the phone run of the 1.4.3 build On the Note20, with an AAR built from 0c2e603ee: the trial app passes 7 of 7 as a 64-bit and as a 32-bit process, on a new and an existing database, and the template (dev-assets #79) stops its runaway query 11 to 12 ms after Cancel in its 64-bit and 32-bit debug builds and its release build. The README said the 1.4.3 build had not run on a phone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7135: Correct two README lines the CI and device work made false "No workflow runs either yet" has been false since the test-sqlite-debugger workflow: it runs test.sh, the C and JNI tests. The JVM tests are still in no workflow, which the line now says. "Nothing has run in an app on a device" has been false since the device runs recorded on ADFA-7135. What is left is a device run of the current code, because those results predate the review fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Refuse SQL that holds more than one statement bridge_query prepared with no tail pointer, so SQLite compiled only the first statement: query with "SELECT 1; SELECT 2" ran the first, dropped the second and reported success, and explain_query_plan (which prefixes the client's SQL) did the same. A lone comment returned an empty result, and anything after a NUL character was dropped too, since SQLite reads no further. prepare_one now prepares the tail as well. Whitespace, comments and semicolons prepare to no statement and are accepted; anything else, including a tail that fails to prepare (the server's authorizer refuses a trailing write at prepare time), fails the call with SQLITE_ERROR, "the SQL holds more than one statement; run one statement per call". SQL with no statement, or with a NUL, fails with its own message. Every tool reaches SQLite through bridge_query, so this covers query and explain_query_plan; the other tools send fixed SQL, and get_stats builds its COUNT(*) from quoted table names, not client input. Preparing the tail is not running it: the only effects are those a PRAGMA can have at prepare time, under the same authorizer a client already meets by sending that statement alone. Test (JniQueryTest, the real JNI path on a host JVM, run by test.sh): two statements, a statement after a comment, a trailing DELETE, a trailing syntax error and EXPLAIN QUERY PLAN with a second statement give the more-than-one message; a lone comment, a lone semicolon and a NUL give theirs; trailing semicolons, whitespace, comments, an open comment and a leading comment still run. With the fix reverted the 8 refusal checks fail, each "null vs 1 the SQL holds ...": the call ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say when a query ran out of time waiting for another tool call A query's 50 s deadline is set before runChecked waits for the tools' lock, so a call queued behind a slow one could fail with "the time limit passed before the query started" or "the query ran past its time limit", and the agent would read that as its own query being too slow. The deadline still starts before the wait (decided in review, so it bounds the wait for an answer once set); only the error changes. runChecked times its wait for the lock, and when the time ran out (SQLITE_INTERRUPT) after that wait took at least half of what the call had left, the message adds "(this call waited N s of its 50 s for another tool call to finish; tool calls run one at a time, so retry it)". Not counted: get_stats sets its deadline before its path check, which also takes the lock, so a wait there is not attributed. A tool call's first wait, in the idle check, comes before any deadline is set. Test (DatabaseToolsTest, fake clock): a second call takes the lock just after the query set its deadline, as a third concurrent call can, and holds it while the fake clock moves. A wait of 50.001 s and of 30 s each get the note; a 10 s wait followed by the query's own timeout does not. Without the fix the first two fail: expected "...started (this call waited 50.001 s of its 50 s ...)" but was "...started", and "the query ran past its time limit" with no note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Start a tool call's time limit when the call begins The 50 s limit was meant to make the server give up before the client (60 s), so a timed-out call never leaves a query holding the lock after the client has stopped waiting. It did not: every call first waited for the lock in the idle check, and run() set its deadline only after that and the path check, so a call queued behind a slow one could run a full 50 s after the wait. Each tool call now gets a Call when it begins: its deadline (DEADLINE_MS, unchanged) and the time it has spent waiting for the lock. Every lock taken inside the call (idle check, path check, each query, get_stats included) goes through Call.locked, which adds the wait. The note from ff0bd0c6b now uses that total: when the time runs out after waits of at least half the limit, the error says the call waited N s for another tool call and should be retried. Test (DatabaseToolsTest, fake clock): a call starts while another holds the lock and waits for it in the idle check. After a 50.001 s wait a query fails with "the time limit passed before the query started (this call waited 50.001 s ...)"; after 30 s a query that then times out gets the note; get_stats after a 50 s wait fails the same way; a 10 s wait gets no note. Against ff0bd0c6b three fail: the 50.001 s query and get_stats succeed (AssertionError: {"isError":false,...}), and the 30 s case reads "the query ran past its time limit" with no note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Let the query backstop's ROLLBACK past the server's authorizer After every query bridge_query ran ROLLBACK when the connection was not in autocommit, as a backstop for a transaction left open. On a read-only server connection, the kind every tool uses, the authorizer denies SQLITE_TRANSACTION, and SQLite authorizes ROLLBACK as that action: the ROLLBACK failed with "not authorized", its result was ignored, and the transaction and its lock on the app's database stayed. Nothing a client sends opens one today (BEGIN and SAVEPOINT are refused), so the backstop only mattered for a hole in the authorizer, and there it did nothing. sqlitedbg_end_transaction (sqlitedbg.h) now does the rollback. It sets a thread-local flag around its own sqlite3_exec("ROLLBACK"), and the authorizer lets SQLITE_TRANSACTION through only when that flag is set and the statement is ROLLBACK. A client's BEGIN, COMMIT, END and ROLLBACK are still refused, also while a transaction is open, and SAVEPOINT (with ROLLBACK TO) is untouched. bridge_query checks the result: a rollback that fails becomes the call's error, "a transaction was left open and rolling it back failed: <errmsg>", with ROLLBACK's code. If the query had already failed, that error is kept instead. The connection stays cached either way, so each later query tries the rollback again. Tests: - C (sqlitedbg_test.c, test_server_ends_transaction): a read-only server connection is put into a transaction holding a read lock by clearing the authorizer, running BEGIN and a SELECT, and putting the real authorizer back (a SQLITEDBG_TEST hook exposes it). The app's write gets SQLITE_BUSY. The client's ROLLBACK, COMMIT and BEGIN still get SQLITE_AUTH. sqlitedbg_end_transaction returns SQLITE_OK, the connection is back in autocommit, and the app can write. Afterwards the client's BEGIN and ROLLBACK are still refused. test_server_holds_no_locks also checks that COMMIT, END and ROLLBACK are refused. With the authorizer change reverted it fails with "sqlitedbg_end_transaction(srv) == SQLITE_OK (23 vs 0)", then autocommit stays 0 and the app's write is "database is locked". - JNI (JniQueryTest): a writable server connection holding BEGIN IMMEDIATE, with an authorizer that refuses ROLLBACK, fails the next query with "23 a transaction was left open and rolling it back failed: not authorized" while the app stays locked out. Once that authorizer is cleared, the next query rolls the transaction back and the app can write. With the old unchecked ROLLBACK restored it fails with "the failed rollback is reported: null vs 23 ...": the query returned as if nothing were wrong. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say when get_schema cut a CREATE statement get_schema reads sqlite_master with a 64 KiB text limit but reported only truncated: result.hasMore, which means more rows exist. A view or trigger whose SQL is longer than 64 KiB came back as a prefix with truncated false, and an agent would read it as the full definition. Each entry now has truncated, true when a value in its row was cut. The result also has truncated_cells, the count of cut values, named as query names it. The top-level truncated is true when anything was cut or rows past the first 1000 were left out. The tool description gives the 64 KiB limit and the three fields. The limit is now a constant, MAX_SCHEMA_SQL_BYTES. The README's Limits paragraph says it too. Other tools checked: query already reports truncated_cells and has_more. explain_query_plan and integrity_check use the 4 KiB text limit and report neither, and were left alone: a plan line or an integrity message near 4 KiB, or more than 1000 of them, is not a realistic case, and integrity_check's ok compares against "ok", which a cut value cannot equal. get_stats reads only numbers and table names. Tests (DatabaseToolsTest with FakeDebugEngine): getSchemaSaysWhichCreateStatementWasCut gives get_schema a result whose view SQL is listed as cut. The top-level truncated is true, truncated_cells is 1, the view entry has truncated true, and the table entry has truncated false. getSchemaIsTruncatedPastMaxRowsEntries checks that 1001 entries still give truncated true with truncated_cells 0. getSchemaGroupsByType checks false and 0 when nothing is cut. With the reporting reverted the first fails with "a cut CREATE statement makes the result truncated", and the other two fail on the missing truncated_cells. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say that functions the app adds to its own connections are missing Every tool runs on a server connection the SQLite debugger opens itself, never on an app connection, and SQLite registers functions per connection. So what the app adds to its own connections (requery's SQLiteCustomFunction and SQLiteCustomExtension, sqlite-js and its stored JavaScript functions) does not exist there: SELECT median(price) fails with "no such function: median" through query, and through explain_query_plan or a view, although the app's own queries run it. The query and explain_query_plan descriptions now say so, so the agent reads the rows or computes in plain SQL instead, and the README states the limit and why. No behaviour change. A test pins the phrase in both descriptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Name both limits that can leave get_schema entries out get_schema's description gave "past the first 1000 entries" as the only reason for the top-level truncated, but the 4 MiB result budget ends the result too, after about 64 CREATE statements of 64 KiB. The agent then saw truncated true with no entry cut, and get_schema has no offset. The description now names both limits and sends the agent to page through sqlite_master with query, reading a statement longer than query's 4096-byte TEXT limit in parts with substr. The README says the same. No behaviour change. The description test pins both causes and the way out; a new test shows the budget ends a get_schema result of 64 KiB statements with truncated true and truncated_cells 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say that a full integrity_check fails on the app's index functions A full integrity_check evaluates the functions an index uses and fails with "unknown function" when the app added one to its own connections; quick_check does not. integrity_check's description and the README say so and name quick_check as the alternative. The description test pins the phrase. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Give get_schema's paging advice an ORDER BY and the right unit The advice to page through sqlite_master gave no ORDER BY, so pages could overlap or skip rows; it now says ORDER BY name. substr counts characters while the TEXT limit counts bytes, which the description and README now say. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say which app functions make quick_check and integrity_check fail A CHECK constraint or a NOT NULL virtual generated column that calls an app function makes quick_check fail too; an index on an expression or a partial index whose WHERE calls one fails only the full integrity_check (verified with SQLite 3.46). Views, triggers and other generated columns fail neither. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Advise ORDER BY type, name to page through sqlite_master get_schema sorts by type, name, and a trigger can share a table's name, so ORDER BY name alone skips or repeats entries when paging with an offset. (type, name) is unique in sqlite_master. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Register consumer-rules.pro so an app's R8 keeps NativeBridge The file existed but no consumerProguardFiles line named it, so proguard.txt was missing from the AAR and an app's minified build could rename or strip the JNI-registered NativeBridge functions and the DebugEngineException constructor the native code calls. The rules cover every class sqlitedbg_jni.c looks up by name. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Refuse a server connection to a path the app no longer has open checkedPath and runChecked read separate connection snapshots, so a cache miss could open a server connection after the app closed its last connection to that path. Re-check against the snapshot taken under the lock and answer with the same unknown database error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Bound a JSON-RPC batch by message count and reply size A batch kept every reply, each up to about 8 MiB, with no limit, all in the host app's heap. Refuse a batch of more than 32 messages whole (400, invalid request), and once a batch's replies reach …
… app (#2260) * ADFA-7082: Vendor sqlite-js 1.3.7 with our patches sqlite-js 1.3.7 (Apache-2.0, with QuickJS/quickjs-ng amalgamated in libs/quickjs.c, MIT), only the files the AAR build uses, with patches/ applied: 0001-0008 are the Termux package's (terminal-packages packages/sqlite-js), 0009 makes each call measure its own thread's stack, and 0010 adds sqlitejs_cancel_all(). 0001-0009 are sent upstream as sqliteai/sqlite-js #11-#19. vendor.sh rebuilds upstream/ and the license notices from the release (checked against its SHA-256) and patches/, or with --check tells whether they match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Build the sqlite-js AAR for apps in subprojects:sqlite-js The AAR the JavaScript-in-SQLite project template depends on: libsqlitejs.so for arm64-v8a, armeabi-v7a and x86_64 (minSdk 26), and SqliteJs: cancelAll(), libraryPath(), ENTRY_POINT (loads the functions stored in js_functions on every connection) and ENTRY_POINT_FOR_DEFINING. sqlitejs_android.c, ours, holds the JNI and that entry point; the version script exports only the entry points and JNI_OnLoad. Nothing in CoGo depends on the module. AndroidModuleConf leaves it without the v7/v8 flavors, like :plugin-api, since one AAR serves every ABI, and without core-library desugaring, like :logsender, so apps need not enable it. Tested in a trial app (requery 3.49.0, Room 2.8.4) on a Galaxy Note20 Ultra as a 64-bit and a 32-bit process: scalar and aggregate from DAOs, deep recursion on pool threads, 32 parallel queries under WAL, and a runaway query stopped by cancelAll() within 5 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Release the sqlite-js AAR to sqlite-js-latest A manual workflow, like release-plugin-api.yml: checks the vendored sqlite-js, builds the AAR from main, and replaces the moving sqlite-js-latest release, from which dev-assets fetches it into the template that uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Build the sqlite-js AAR for arm64-v8a and armeabi-v7a only Apps built with Code on the Go run on ARM phones, so the AAR no longer carries x86_64. ADR 0005 says so. CLAUDE.md's ABI section now names the two modules without v7/v8 flavors, as ARCHITECTURE.md and ADR 0005 do (review of PR #2244, F07). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Run no stored code by default; test sqlite-js on pull requests From the reviews of PR #2244 (independent F02, F03, F05, F06; CodeRabbit): - ENTRY_POINT (sqlite3_sqlitejs_init, also the name SQLite derives from libsqlitejs.so) now loads sqlite-js alone. The old entry point loaded the functions stored in js_functions, which runs their code, so any database file the app opened ran its stored JavaScript at once. Loading them is now ENTRY_POINT_FOR_TRUSTED_DATABASE (sqlite3_sqlitejs_trusted_init), for databases the app made. ENTRY_POINT_FOR_DEFINING is gone: ENTRY_POINT does that job. - The trusted entry point loads each stored function on its own, so one that fails is logged and skipped instead of dropping those after it. - cancelAll()'s Javadoc and the README say it stops JavaScript in every query, so call it only for a known runaway and repeat it until the query ends. - test.sh runs upstream's test suite with patches/, and glue_test.c, the first test of sqlitejs_android.c. test-sqlite-js.yml runs vendor.sh --check and test.sh on pull requests for this module. glue_test.c passes 14 of 14; against the old glue 5 fail (stored functions loaded by ENTRY_POINT, functions after a broken one dropped). The AAR builds and exports the two entry points, sqlite3_js_init and JNI_OnLoad. Not run on a device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Update sqlite-js-latest in place, out of latest-release selection release-sqlite-js.yml deleted the release and its tag before making the new one, so a failed upload left dev-assets nothing to fetch. It now uploads the new assets over the old ones, putting the old ones back if that fails, then moves the tag and the notes. The release is created and kept with --latest=false, so it never becomes the repository's latest release (CodeRabbit, PR #2244). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Sort the QuickJS copyright lines the same on every machine vendor.sh built LICENSE.quickjs with sort -u in the machine's locale, so the new test-sqlite-js workflow's vendor.sh --check failed on the runner: en_US.UTF-8 and C order "2017" and "2017-2018" differently. It now sorts with LC_ALL=C, and upstream/LICENSE.quickjs and the META-INF notice are regenerated; only the order of their copyright lines changes. --check passes under C, C.UTF-8 and en_US.UTF-8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Log stored functions that cannot be listed; guard the tag move From CodeRabbit's review of the previous commits: - The trusted entry point returned silently when it could not list the stored functions (busy, out of memory, an odd table), opening the connection with some or none of them. Each failure is now logged; the connection still opens. It first looks js_functions up in sqlite_master, so a database without stored functions makes SQLite log no "no such table" error on each connection, as it did. - release-sqlite-js.yml moves the tag and edits the notes in the same guarded sequence as the upload. If any step fails, the previous assets and tag are put back. glue_test.c passes 16 of 16; the two new tests fail on the previous glue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the reviewed sqlite-js patches Patches 0002, 0003, 0004 and 0010 are regenerated after three reviews: the independent reviews of terminal-packages #6 and of this PR, and CodeRabbit's review of this PR. - 0002: garbage is collected before the memory limit fills. Running out of memory through small allocations reports "out of memory". - 0003: the README says TEMP views and triggers can call the js_* functions. - 0004: db.exec throws for a buffer it cannot read instead of binding NULL. A typed array's own offset and length are used, not properties a script defines. - 0010: a cancel also interrupts the cancelled call's statement, so a runaway JavaScript collation stops. Before, nothing could stop one. The other patches change only in their headers and line numbers. upstream/ is regenerated with vendor.sh, and vendor.sh --check passes. SqliteJs.cancelAll() and the README say a cancel interrupts the statement too. Tested: - test.sh: upstream's suite passes 16 of 16, and the glue test 16 of 16. - In the work repo, the same suite passes under ASan and UBSan with leak checking, and each new test fails without its fix. - The AAR builds for arm64-v8a and armeabi-v7a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Put back both the assets and the tag if a release update fails From CodeRabbit's review: under bash -e, a failed restore of the previous assets stopped the rollback before it put the tag back, so the tag could name the new build while the release held the old one. Each restore is now attempted, reported if it fails, and the step still fails. Checked with gh stubbed out: when the update fails and the asset restore fails, the tag restore still runs and the step exits 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Find js_functions in any case; sync the cancel test; doc caveats From CodeRabbit's review of the vendored patches: - The trusted entry point looks up js_functions with COLLATE NOCASE, as SQLite resolves a table name, so a table named JS_FUNCTIONS loads. A new glue test, now 18 of 18, fails without it. - Patch 0010's Cancel all test cancels once the JavaScript under test has called started(), an SQL function, instead of after a fixed 200 ms. A slow start can no longer end the test at its alarm. It still hangs without the fix it tests. - SqliteJs.cancelAll() and the README now say two more things. An interrupted INSERT, UPDATE or DELETE in an explicit transaction rolls the whole transaction back. And a cancel reaches SQL that JavaScript runs through db.exec only when that SQL returns to JavaScript. Tested: - test.sh: upstream's suite passes 16 of 16, also under ASan and UBSan in the work repo, and the glue test 18 of 18. - vendor.sh --check passes. - The AAR builds with the new lookup for arm64-v8a and armeabi-v7a. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a re-run repair a release left without its assets A run that stops during `gh release upload --clobber` can leave an asset missing. The next run then failed at the backup download ("no assets match the file pattern") before it uploaded anything, so re-running could not repair the release. The step now backs up only the assets that exist and puts the previous ones back only when it has both. Tested with a stub gh over a fake release: both assets missing now ends with the new pair and the tag moved (before: exit 1 at the download); the other five cases are unchanged. Checked against gh 2.46: download fails only when no pattern matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor sqlite-js main with our changes merged, one patch left Upstream merged our patches 0001 to 0009 (sqliteai/sqlite-js #11 to #19) on 2026-11-12, with fixes of its own. One fixes a bug in our 0002: a memory limit lowered under memory that is garbage left the connection out of memory until the limit was raised again (ef06558). upstream/ is now sqlite-js main at c8ae85a, the same source as the Termux package 1.3.7-p20261112, with one patch: 0001, sqlitejs_cancel_all(), our old 0010 rebased. Its test now fails with a message when the JavaScript under test has not started within 10 seconds, instead of cancelling anyway, and uses upstream's watchdog thread instead of alarm(). The patch is offered upstream in sqliteai/sqlite-js issue 20. vendor.sh, test.sh and test-sqlite-js.yml take the commit (COMMIT, URL) instead of the release tag. vendor.sh --check passes; test.sh passes: upstream's suite 16 of 16 with Cancel all, glue_test 18 of 18. The upstream suite with the patch also passes under ASan + UBSan; without the patch's sqlite3_interrupt() its collation case runs until the watchdog, and with started() never called the worker fails with its message. The native library builds with NDK 29 for arm64-v8a and armeabi-v7a, with no warnings in sqlitejs.c or sqlitejs_android.c, and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Vendor the sqlite-js 1.4.1 release Upstream released 1.4.0 and 1.4.1 on 2026-11-12, after c8ae85a. Both contain it, and 1.4.1 differs from it in src/ and libs/ only in SQLITE_JS_VERSION, so js_version() now reports 1.4.1. vendor.sh, test.sh and test-sqlite-js.yml take the release's archive again (VERSION, SHA256, URL). Patch 0001 is unchanged but for its context. The scripts now take the archive's one top directory whatever its name (tar --strip-components=1). They named it after COMMIT, so the README's "point URL at its tag again" would have failed: a tag's archive unpacks to sqlite-js-<tag> (independent review). The README says how to vendor a release, and a commit between releases. vendor.sh --check passes on the 1.4.1 archive (SHA-256 d45d394f...3078). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a connection open, and its stored functions load, during a cancel A cancelAll() that landed while another thread opened a connection made that connection fail to load sqlite-js (SQLITE_NOMEM), so a Room query on a new pool connection failed (independent review). Setting up the runtime runs JavaScript of its own, which the interrupt handler stopped. Patch 0001 now cancels only JavaScript inside a call (js_enter), and its Cancel all test opens 200 connections while another thread cancels without pause: the first one failed before. A cancel that lands while the trusted entry point loads a stored function stops that function's code the same way, and the function was then missing from the connection for good. load_stored_function now tries such a load again, up to three tries in all; its stored code runs again each time. glue_test.c stores a function whose code cancels the first time it loads: it loads on the second try, and with one try it is missing. The README and SqliteJs's Javadoc say both. test.sh passes: upstream's suite 16 of 16, glue_test 22 of 22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Patch two stack-bound crashes and two garbage cases 0002, after CodeRabbit's review: code that called itself without end crashed the process instead of failing with "Maximum call stack size exceeded" in two cases. - On a thread with less than 64 KB of stack left, js_enter kept the connection's 1 MB size rather than the room it measured. It now keeps any measurement, and 1 rather than 0, which turns the check off. - On the main thread, RLIMIT_STACK was counted from where the first measurement was taken. Loaded 2 MB deep, the extension allowed 10.2 MB of an 8 MB stack. It is now counted from the stack's top, as the kernel counts it. 0003, after the independent review of terminal-packages #6: garbage could leave an allocation that fits in the memory limit failing on every try. After 40 MB of cyclic garbage, new ArrayBuffer(30 MB) failed under the 64 MB default. And after a limit was lowered to 32 MB above the garbage, new ArrayBuffer(16 MB) failed. The extension now collects after any "out of memory" error and whenever a limit is set. Each patch adds tests to upstream's suite that fail without it. The suite passes 16 of 16 with all three patches, also under ASan and UBSan, and test.sh's glue_test 22 of 22. The NDK 29 build for arm64-v8a and armeabi-v7a has no warnings outside QuickJS and exports the same four symbols. Both fixes are offered upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Let a re-run replace a release left as a draft gh release create makes a draft and publishes it once its assets are uploaded. A first run that stopped during that upload left a draft: the next run found it, skipped the create, and failed fetching its tag, which a draft does not have yet. Every re-run then failed (independent review). The step now deletes a draft release, which dev-assets cannot fetch from, and creates the release again. Tested with a stub gh over a fake release, eight cases. The draft case failed with a 404 before, and now ends with the new assets and tag. The other seven are unchanged: no release, normal, upload fails, tag update fails, both assets missing, one missing, and upload fails with both missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * style: spotless reformat, no functional change Spotless wraps the cancelAll() Javadoc paragraph, which the previous commits lengthened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: End the result sets an interrupted call leaves open CodeRabbit: SQLite keeps an interrupt in effect while any statement of the connection runs, and a db.exec result set that JavaScript keeps open is a running statement. After cancelAll() stopped JavaScript that kept one in a global, every later statement on that connection failed with "interrupted", until the connection closed. A stored function whose code kept one could not load on any of its three tries. sqlite3_interrupt() does the same, without our cancel patch. Patch 0004 lists each connection's result sets. When the outermost call into JavaScript returns on an interrupted connection, it finalizes those still open. Reading on from one that JavaScript kept throws "interrupted". Reproduced on the host, with a cancel and with sqlite3_interrupt(): every later statement failed before, and all run after. Upstream's Interrupt test interrupts code that keeps a result set, in a global and as garbage, and fails without the patch. glue_test.c stores a function whose code keeps one and cancels the first time it loads. It loads on its second try, and the connection runs SQL afterwards; without the patch, those three checks fail. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for arm64-v8a and armeabi-v7a has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Make ending result sets safe when it runs JavaScript, and on old SQLite CodeRabbit, on 0004: - 0005: finalizing a result set that is computing a JavaScript window function runs the function's final, whose js_leave() ended the result sets again on the interrupted connection, finalizing the same statement twice. Under ASan that is a use after free in sqlite3VdbeMemFinalize, reproduced on the host. Each statement is now taken from its result set before it is finalized, the list is walked again from its head after each one, and a nested call does nothing. Upstream's Interrupt test now keeps a result set computing a window function; it fails under ASan without 0005. - 0006: on SQLite before 3.41, which has no sqlite3_is_interrupted(), 0004 never ran, though a cancel still interrupts the connection. The interrupt handler now records the interrupt it sends. Built to report SQLite 3.40, a cancel of JavaScript that keeps a result set left every later statement failing before 0006, and not after. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Stop what ending result sets runs; count the interrupts db.exec sees CodeRabbit, two more cases on SQLite before 3.41, both in patch 0007: - Ending result sets after a cancel can run a window or aggregate function's final, which begins after the cancel, so nothing stopped it: a final that never ended hung the cancelled query. The interrupt handler now stops any JavaScript while result sets are being ended. - A direct sqlite3_interrupt() that reached a db.exec statement's SQL, with another result set kept open, went unseen. A result set whose step returns SQLITE_INTERRUPT now records it. Checked with the patched source built to report SQLite 3.40: the endless final hung before and ends after, and a direct interrupt during db.exec's SQL, caught or not, left later statements failing before and not after. Still unseen before 3.41, and said in the README: an interrupt that never reaches the SQL that JavaScript runs. Android's cancelling never calls sqlite3_interrupt(), and cancelAll() is covered. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer the independent review of patches 0004 to 0007 - 0009: a result set's SQLITE_INTERRUPT now counts as an interrupt only before SQLite 3.41. A progress handler that stops a statement, as Android's cancelling does, gives the same code and interrupts nothing else, yet it ended the result sets earlier calls kept, on any SQLite. - 0008: the Interrupt test's "garbage" result set was freed by reference counting, so the case passed without 0004. It is now a reference cycle, and fails on 1.4.1 without 0004. Also pushed to sqliteai/sqlite-js#24. - Tests for 0006, 0007 and 0009, which had none: glue_test.c cancels JavaScript that keeps a result set, then a kept window function whose final never ends, then has a progress handler stop a statement. test.sh runs it twice, the second time with sqlitejs.c built to report SQLite 3.40. Without 0009 the progress-handler check fails; without 0007 the 3.40 run hangs until the test's 30 s alarm; without 0006 seven checks fail in the 3.40 run. - README: a cancel ends every result set open on the connection, not only the stopped call's. And on any SQLite, an sqlite3_interrupt() that lands while no JavaScript runs leaves the connection failing while JavaScript keeps a result set, so finish result sets before a call returns. Reproduced on 3.49: every later statement fails, and sqlite3_close returns SQLITE_BUSY. test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan, and glue_test 34 of 34 in both runs. The NDK 29 build for both ABIs has no warnings outside QuickJS and exports the same four symbols. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Test a direct interrupt during db.exec with a result set kept CodeRabbit: the case that 0007's record of a step's SQLITE_INTERRUPT is for had no automated test. glue_test.c now keeps a result set, has another thread call sqlite3_interrupt() while db.exec runs a query that never ends otherwise, and checks that the connection runs SQL and that the kept result set was ended. In the run as SQLite 3.40, those checks fail without the record. The checks that a kept result set was ended now tell an ended one (caught in JavaScript: "ended: interrupted") from a connection that is still interrupted, whose error is the same word. test.sh passes: upstream's suite 16 of 16, and glue_test 37 of 37 in both runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7135: Define the interface between the SQLite debugger extension and its server sqlitedbg.h is what the extension implements and its JNI layer calls; DebugEngine.kt is what the server (ADFA-7136) builds against, with a fake for JVM tests. Not yet built by Gradle: the module has no build file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: Copy the MCP server from ShareYourApps, renamed McpHttp.kt and McpProtocol.kt from Local Store Server Combined with only the package, server name, title, instructions and 401 texts changed. McpProtocolTest.kt still names that project's tools and does not compile; ADFA-7136 rewrites it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Add the sqlite-debugger module skeleton Module build file modelled on sqlite-js (no ABI flavors, both ABIs, no STL, 16 KiB pages), plus Kotlin at API 2.0 for apps built with CoGo. Registered in settings, modulesWithoutAbiFlavors and disableCoreLibDesugaringForModules. The CMake file arrives with the extension in the next commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: MCP server with the eight read-only database tools Binds 127.0.0.1 on port 0 with a new token per process start, and serves list_databases, list_connections, get_schema, query, explain_query_plan, get_stats, integrity_check and get_events against DebugEngine. JVM tests run against FakeDebugEngine (51 pass). DebuggerStartup.kt and the manifest are Android-only and not yet compiled. Formatting follows in its own commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Implement the SQLite debugger extension and its host tests sqlitedbg.c implements sqlitedbg.h as a loadable-extension client. Per-connection state is freed only from the xDestroy of sqlitedbg_connection_id; the trace CLOSE event only marks it closing. Events live in a ring of records in their exported layout. Server connections are recognised by a thread-local flag set around sqlitedbg_open_server's own open. test.sh builds SQLite 3.49.1 from the amalgamation (pinned) and runs sqlitedbg_test.c under ASan+UBSan and under TSan. The same run writes or checks the fixture the EventDecoder JVM test reads. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Add the JNI layer and NativeDebugEngine sqlitedbg_jni.c registers NativeBridge's natives from JNI_OnLoad (the version script exports nothing else) and reaches SQLite only through the extension's api table. ServerConnection.query steps the statement in C, binds args by type, applies QueryLimits, and stops at the deadline through a progress handler on the server connection. EventDecoder mirrors the exported record layout and is tested against the fixture the host C test writes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * style: spotless reformat of the SQLite debugger module, no functional change Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Fix three review findings in the extension - read_events moves the cursor past dropped events when it copies nothing, so a drop is reported once. - An internal failure in sqlitedbg_extension_init is logged and the connection left untracked; the app's own sqlite3_open no longer fails because of it. - A trigger is told apart from app SQL by X differing from sqlite3_sql(P), not by a "--" prefix, so statements that start with a comment are expanded. test.sh builds the extension with SQLITEDBG_TEST for the failure hook. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: Document the SQLite debugger module Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136: List sqlite-debugger among the modules without ABI flavors AndroidModuleConf.kt already excludes it; ARCHITECTURE.md and CLAUDE.md named only plugin-api and sqlite-js. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Never let the debugger crash or miss the host app's early connections - DebuggerStartup catches Throwable after the debuggable check, so a missing requery library (UnsatisfiedLinkError) disables the debugger instead of killing the app. The check itself still throws. - install() runs synchronously in onCreate; only the server start is on the thread, so connections opened in Application.onCreate are tracked. - McpHttp: connection and accept threads catch Throwable; an Error while handling a request is answered with a 500. - McpHttp: a failed accept sleeps 100 ms, doubling to 2 s while failures continue, and resets on success (no spin on EMFILE). Tests: an Error thrown by a tool gives HTTP 500 and the server keeps serving; a ServerSocket whose accept fails is retried with growing gaps, then serves. DebuggerStartup imports android.* and has no JVM test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7135 Keep read-only server connections from holding locks The read-only authorizer allowed BEGIN, SAVEPOINT and PRAGMA locking_mode, so a client could hold a lock on the app's database: BEGIN; SELECT left the app's INSERT failing with SQLITE_BUSY until ROLLBACK. - sqlitedbg.c: deny SQLITE_TRANSACTION, SQLITE_SAVEPOINT, PRAGMA locking_mode and PRAGMA busy_timeout (any form) on read-only server connections. - sqlitedbg_jni.c: bridge_query rolls back if the connection is not in autocommit when it returns (covers writable connections). - Host C test: each denied statement returns SQLITE_AUTH and the app can still write after a read on that connection. Without the authorizer change the test fails on all 8 statements (BEGIN and SAVEPOINT: "database is locked" for the app's INSERT). The backstop is tested with the JNI test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Bound query results and report truncation per cell - M4: QueryLimits.maxTotalBytes (DatabaseTools passes 4 MiB). bridge_query counts the TEXT/BLOB bytes kept and 8 per number, and stops with hasMore before the row that would pass the budget; the first row always goes in so a page makes progress. The tool result text is serialised compact: it was sent twice, pretty and as structuredContent. - L11: the engine reports cut cells (QueryResult.truncatedCellIndexes, row * columns + column) instead of DatabaseTools guessing from size >= limit, so a BLOB of exactly maxBlobBytes is no longer flagged. - L12: get_schema and get_stats read sqlite_master (sqlite_schema needs 3.33). - L13: sqlite3_column_text/blob returning NULL (out of memory) is checked. JVM tests: blob at the limit vs one byte over, the budget pages a result of 3 MiB rows, sqlite_master in the SQL sent, compact result text. Each fails with its fix reverted. The native side (budget, cut cells) is tested by the JNI test in a later commit; L13 has no test (needs an allocation failure). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Drop stale server connections and stop expanding SQL when idle - M7: DatabaseTools cached a server connection per path forever, so after the app deleted and recreated its database the server read the old file. Each cached connection remembers the ids of the app connections to its path when it opened. Before each tool call it is closed and dropped when no live app connection has the path, or none of those ids is left. - L14: the first get_events turned on bound-value expansion until the server stopped, so every app statement was expanded twice forever. It now goes off 60 s after the last get_events call, checked on every tool call and by a daemon timer; the tool description says so. - L10 (one lock for all tool calls) is documented in the class KDoc. Tests: recreated database reopens (opened 2, closed 1), a connection survives while a seen app connection remains, a vanished path closes the cached one, and expansion stops after 60 s. Each fails with its fix reverted (expected 2 but was 1; expected 1 but was 0; "60 s after the last get_events"). Limit accepted: a database replaced in place while the same app connections stay open is not detected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Test the JNI query path test.sh now also builds the JNI layer as it ships (libsqlitedbg.so without SQLITE_CORE, with the version script) against a requery-like libsqlite3x.so (amalgamation, THREADSAFE=2, all symbols exported) and runs src/test/jni/JniQueryTest.java on the host JVM through NativeBridge. It is skipped with a message when no JDK is on PATH. It uses Java stubs of NativeBridge and DebugEngineException (same names and native signatures) rather than compiling the Kotlin, so only a JDK is needed; test.sh fails if the native names in NativeBridge.kt and the stub differ. A change of a Kotlin parameter type alone is not caught. Covers: value types, paging and hasMore, the total-bytes budget (including "first row always goes in" and the budget stopping on a row boundary), per-cell truncation at, over and under the limit with row * columns + column indexes and a budget-dropped row's cells, bound types, the deadline giving SQLITE_INTERRUPT, refused writes giving SQLITE_AUTH, BEGIN/SAVEPOINT/PRAGMA refusals leaving the app able to write, and the rollback backstop. Checked to fail with each native fix reverted: budget (50 rows vs 4), cut cell indexes ([] vs [1, 3]), rollback backstop (app INSERT 5 vs 0, SQLITE_BUSY), authorizer (BEGIN: 0 vs 23), dropped row's cut cells ([0, 1] vs [0]). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7136 Document the JNI test and the requery trace limit README: the JNI test and how it stands in for the Kotlin, and that requery's own sqlite3_trace (log.tag.SQLiteStatements or SQLiteTime VERBOSE) replaces ours on a connection, so its events stop. No code change for that. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba * ADFA-7082: Vendor the sqlite-js 1.4.2 release Upstream released 1.4.2 with our stack, garbage-collection and result-set patches merged (sqliteai/sqlite-js #22, with two maintainer commits, #23 and #24) and with a fix for the use after free we reported (#25). That fix also changes behaviour: a db.exec result set no longer outlives the call into JavaScript that created it, and reading one afterwards throws "The result set was closed when the call into JavaScript that created it returned". So patches 0002 to 0009 go: - 0002 to 0005 and 0008 are upstream, by patch-id identical except for 0002, which has the maintainer's two commits on top. - 0006, 0007 (its second half) and 0009 only told interrupts apart for result sets kept across calls, which 1.4.2 no longer allows. 0001 (sqlitejs_cancel_all, issue 20) is rebased: the same changes, with new context in the struct. A new 0002 keeps what 0006 and the first half of 0007 did for a cancel on SQLite before 3.41: ending a cancelled call's result sets runs the finals of the window and aggregate functions they were computing, each a call that begins after the cancel, which before 3.41 nothing else stops; and those result sets read on as "interrupted". It is narrowed to a cancelled call, since in 1.4.2 result sets are also ended on every normal return. The next commit updates the tests for 1.4.2. vendor.sh --check passes on the 1.4.2 archive (SHA-256 1aa4c566...cf24). The libs/ and license files are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Test sqlite-js 1.4.2's result-set rule and patch 0002 glue_test.c, for 1.4.2: - The progress-handler case kept a result set across calls, which 1.4.2 no longer allows. It now checks, within one call, that a statement a progress handler stopped (as Android's cancelling does) leaves the call's other result set readable, on any SQLite, and that the connection runs SQL afterwards. - A direct sqlite3_interrupt() before SQLite 3.41 shows nowhere, so its kept result set reads as one that outlived its call; on 3.41 and later, as interrupted. - The cleanup that read a kept result set after its call is gone: it now throws. test.sh and the README name patch 0002 for the run as on SQLite 3.40, and the README lists the two patches, states the 1.4.2 rule, and says the 1.4.2 build has not been run on a phone yet. test.sh: upstream's suite 17 of 17 (its 16 and 0001's Cancel all), and glue_test 37 of 37 both normally and as on SQLite 3.40. Without patch 0002, the normal run still passes 37 of 37, and the 3.40 run fails as expected: the kept result set after a cancel reads "The result set was closed ..." rather than "interrupted", and the window function whose final never ends hangs until the 30 s alarm stops the test. Both ABIs build with NDK 29, and libsqlitejs.so exports only JNI_OnLoad and the three entry points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Keep a call's cancel for the finals its result sets run From the independent review of 3a5cb5356 and 464e6e7ef (no critical, high or medium findings; F01 to F05 low or nits). Patch 0002 told a cancelled call apart only once, in js_leave(), and each final that ending its result sets ran entered JavaScript as a new call with a new cancel epoch. So, before SQLite 3.41: - a cancel that landed while the result sets were ended stopped only the final then running, and the next final that never ended hung the statement (F01); - a cancel that landed just before the call returned let the call succeed with its finals skipped, on any SQLite (F02). Patch 0002 now keeps the call's epoch while its result sets are ended (js_enter), so a cancel during the call or the ending stops every final, and a late cancel fails the statement with an interrupt. The ending_cancelled flag and its interrupt-handler check are gone; the patch is 8 lines. upstream/ is regenerated with vendor.sh. glue_test.c, 44 tests (was 37): - 31: a cancelled call that keeps two result sets whose window finals never end (F03's case); - 33-34: the cancel lands during the first final of a call that returned normally (F01); - 36-37: a cancel that lands as the call returns fails it (F02); - 43: after a progress handler's stop, the kept result set reads as outliving its call, not as interrupted (F04; it passes without the fix too, as a guard against counting such a stop as an interrupt). test.sh: upstream's suite 17 of 17; the glue test 44 of 44 normally and as on SQLite 3.40. With the previous 0002, test 37 fails in the normal run and the 3.40 run hangs at test 34; with 0001 alone, test 37 fails, and the 3.40 run fails test 29 and hangs at test 31. README: what 0002 does now, and what the glue test covers (F05). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Say what a late cancel does to a call's finals From the independent review of 5b9b062eb (no code defects; tests catch what they're named for and are not flaky in 120 runs on 2 cores and 16 on 1; two low findings and a nit): - F01: "those result sets read on as interrupted" holds only when the cancel came before the call returned. js_leave() decides that once, before ending them, so a cancel that lands while they are ended stops their finals but leaves the "closed" message. - F02: a cancel stops each final at QuickJS's next interrupt check. A final that never ends is stopped and the statement fails, but a short final can still run to its end, so "rather than skipping its finals" overstated it. The patch 0002 header and README say so; 5b9b062eb's message overstated both in the same way. Patch 0002's code is unchanged. - F03: test 36's final records that it ran, and a new test 38 checks that the late cancel stopped it before it did; test 37 is renamed to say its final is a long one. test.sh: upstream's suite 17 of 17; the glue test 45 of 45 normally and as on SQLite 3.40. With 0001 alone, tests 37 and 38 fail (the final ran to its end) and the 3.40 run fails 29 and hangs at 31; with the previous 0002, test 37 fails and the 3.40 run hangs at 34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7135 Set the Kotlin JVM target on the compile tasks The root build sets jvmTarget 17 on every KotlinCompile task, which overrides the module's kotlin { compilerOptions } and made compileDebugKotlin fail against compileOptions' Java 1.8 ("Inconsistent JVM-target compatibility"). Setting it on the tasks keeps 1.8, as sqlite-js uses. First compile of the Android-only files (NativeDebugEngine.kt, DebuggerStartup.kt, sqlitedbg_jni.c, the manifest): with this change :subprojects:sqlite-debugger:assembleDebug builds both ABIs, the C compiles without warnings under -Wall -Wextra, libsqlitedbg.so exports only JNI_OnLoad, and testDebugUnitTest passes 56 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ADFA-7082: Read result sets as interrupted when the cancel lands while they are ended From CodeRabbit's review of 5b5cd201c (4570522172), the same gap the independent review noted as F01: js_leave() decides once, before ending a call's result sets, whether they read on as "interrupted". A cancel that landed while their finals ran stopped the finals but left the "closed when the call ... returned" message. Patch 0002 now has js_end_rowsets() number its passes and mark each result set with the pass that ended it. After the loop, where nothing runs JavaScript and so no final can have freed a listed result set, it marks that pass's result sets interrupted if the cancel epoch has moved. The README and the patch header say the message is "interrupted" whether the cancel came before the call returned or during the ending. glue_test.c: new test 36 reads both result sets after the cancel that lands during the ending, and expects "interrupted". test.sh: upstream's suite 17 of 17; the glue test 46 of 46 normally and as on SQLite 3.40, and the same under AddressSanitizer and UBSan. With the previous 0002, test 36 fails in both runs with the "closed" message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Address review of the sqlite-js cancel patches Patch 0002 (rebuilt from upstream PR sqliteai/sqlite-js#33) now: - drops the redundant cancelled term from js_leave: the block after the loop in js_end_rowsets marks a cancelled call's result sets interrupted; - says only JavaScript the extension runs while it initialises a connection is exempt from a cancel, not js_init_table's stored functions; - initialises a rowset's end_pass where it is created; - documents sqlitejs_cancel_all in sqlitejs.h. upstream/ is regenerated with vendor.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7136 Bound the request head and refuse before reading the body; say the server is read-only A local app could hold all 8 connection slots without authenticating: the 30 s timeout applied per read and the token was checked after the whole request. The head now has an overall deadline (5 s), and Host, Origin, path and token are checked before the body. The initialize instructions no longer mention a read-write mode that does not exist. Tests: sockets that send nothing or trickle bytes are closed within the deadline and the real client is then served; an unauthenticated request with an unsent body gets 401; the instructions do not mention read-write. All three fail with the fix reverted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Refuse the process-wide heap limit and temp directory PRAGMAs on server connections SQLite applies hard_heap_limit, soft_heap_limit and temp_store_directory to the whole process, so a client's PRAGMA hard_heap_limit=1 could make the app's own connections fail with SQLITE_NOMEM. Test: each form (set and read) returns SQLITE_AUTH on a server connection; without the change all five return SQLITE_OK. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Give server connections a 3 s busy timeout With the app's database in rollback-journal mode, a server read failed at once with SQLITE_BUSY while the app held a write lock, exactly when the agent wants to look. The timeout is set in C and PRAGMA busy_timeout stays refused, so the client cannot change it. Test: an app connection holds BEGIN EXCLUSIVE; a server read waits about 500 ms and succeeds once it is released, and reports SQLITE_BUSY after about 3 s if it is not. Without the timeout the first read failed after 0 ms with SQLITE_BUSY. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Fail a query whose argument count differs from its parameter count Too few arguments left the missing parameters unbound, which SQLite reads as NULL, so the query ran and returned a plausible empty result. It now throws SQLITE_RANGE with a message naming both counts. Test (JniQueryTest, the real JNI query path on a host JVM, run by test.sh): zero args for one parameter and one for two give SQLITE_RANGE; the first expectation was NULL before, and both fail with the check disabled. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 List an open database once when the databases folder is reached through a link list_databases matched the files of the app's databases folder against connection paths as strings, so on a phone (/data/user/0/<pkg> against /data/data/<pkg>) every open database was listed again as available: false. Both sides are now canonicalised before matching; paths are reported as the connections gave them. Test: a folder listed through a symlink, and the reverse, list the open database once. Without the canonicalisation it was listed twice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Run the sqlite-debugger host tests in CI test.sh (the extension's C tests under ASan/UBSan and TSan, and the JNI query test) ran in no workflow. The new workflow follows test-sqlite-js.yml and also triggers on the vendored SQLite headers test.sh compares against. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7137 Add debugger_endpoint_table and migration 5 to 6 The SQLite debugger in an app built by Code on the Go reports a token and a port; Code on the Go needs to keep them per app and per project. debugger_endpoint_table (RecentProjectRoomDatabase version 6) is keyed by application_id and holds project_location, token, port and updated_at. project_location is a foreign key to recent_project_table.location with ON DELETE CASCADE, so removing a project removes its endpoints, and ON UPDATE CASCADE, so renaming a project (which rewrites location) does not fail once an endpoint row exists. Room enables PRAGMA foreign_keys itself once the schema declares a foreign key, so no extra code is needed. The pairing upsert is INSERT OR IGNORE plus UPDATE in one transaction: minSdk 28 ships SQLite 3.22, which predates UPSERT (3.24). Tests: migration 5 to 6 on a v5 file opened through Room (projects kept, schema validated, cascade works on the migrated file); delete and rename cascades. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * style: spotless reformat, no functional change LaunchAppAction.kt was indented with spaces; the next commit edits it, which pulls the whole file under the Spotless ratchet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7137 Pair apps with projects and receive their debugger endpoint Code on the Go must know which project an app belongs to before it accepts that app's debugger token and port, otherwise any app could register an endpoint. - A project-started install records (application ID, project) once the install succeeds. An existing pairing moves to the new project and its stale token and port are cleared. LaunchAppAction only adds a pairing when the app has none, and waits for it before launching. The Activity is not captured in the pairing lambda. - DebuggerEndpointReceiver (exported, action com.itsaky.androidide.SQLITE_DEBUGGER_ENDPOINT) stores the endpoint off the main thread. The token must be 1-128 URL-safe base64 characters and the port 1-65535. A broadcast from an unpaired app stores nothing. A database failure is logged, never thrown. - Sender identity: the app attaches an immutable PendingIntent, and the receiver trusts only its creatorPackage, which the framework sets and another app cannot forge, on every API level. A forged broadcast could otherwise point the AI Agent at another app's debugger server. Tests: DAO and repository (pairing rules, failures reported as false, move and clear on re-pairing); the receiver delivered through the framework under Robolectric (stored, unpaired app ignored, no PendingIntent ignored, malformed extras ignored); validation of token and port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7137 Send the debugger endpoint to Code on the Go once the server listens The library broadcasts its token and port on every process start, after the server listens, so a relaunched app (new port) updates its row. - The broadcast carries an immutable PendingIntent, so Code on the Go can identify the sender from its creatorPackage on every API level. - FLAG_INCLUDE_STOPPED_PACKAGES and FLAG_RECEIVER_FOREGROUND deliver it to Code on the Go when that is not running (cold start). - The library manifest declares <queries> for Code on the Go so the package is visible on API 30+. Code on the Go's receiver is declared in the app manifest, in the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7137 Docs: describe the debugger endpoint and database version 6 The sqlite-debugger README describes the endpoint broadcast; ARCHITECTURE.md and the Room ADR name Recent Projects database version 6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7137 Clear pending installs on failure and pin the endpoint broadcast contract A failed or cancelled install left its pendingInstalls entry behind, so a later install of the same applicationId from an APK file was paired with the wrong project. The editor now tells the repository when an install ends without a launch, and entries older than five minutes are ignored as a backstop. Tests: a discarded note is not used, an expired note is not used, a recent note still pairs (the first two fail with the discard and the expiry removed). The broadcast extra names are consts in the library, and EndpointBroadcastTest (Robolectric) checks the sent action, package, extras and creatorPackage. The library is not on :app's classpath, so DebuggerEndpointContractTest in :app pins the same literals; each test names the other. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7082: Vendor the sqlite-js 1.4.3 release, with no patches Upstream merged sqliteai/sqlite-js#33, our patches 0001 (cancel) and 0002 (a cancelled call's finals and result sets) unmodified, and released them in 1.4.3 with one fix of the maintainer's: a cancel no longer stops a stored function's code while js_init_table(1) loads it, as it already spared the JavaScript that loads the extension. Before, a cancel in flight left the connection without that function. Only that call is exempt: JavaScript the code runs through SQL is still cancelled. - upstream/ is plain 1.4.3; patches/ is gone. vendor.sh and test.sh apply any patches/ there may be later (nullglob). - The glue still loads a stored function up to three times, for the case 1.4.3 still cancels. glue_test.c: new test 20 checks that a cancel during a function's own load code does not stop it (fails on 1.4.2 with the two patches); the w and h tests now cancel JavaScript that the load code runs through SQL (they fail with one try). - README, SqliteJs.cancelAll() javadoc: a cancel interrupts the connection, so any other statement in progress on it fails too, and it spares loading stored functions. The README now says the 1.4.2 build passed on the phone and the 1.4.3 build has not run on one yet. test.sh: upstream's suite 17 of 17; glue test 50 of 50 normally and as on SQLite 3.40, and the same under ASan, LeakSanitizer and UBSan. vendor.sh --check passes. NDK 29 builds for both ABIs: no warnings, the same four exports, version string 1.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * style: spotless rewrap of the cancelAll() javadoc, no functional change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Answer the independent review of the 1.4.3 move No correctness defects; two nits: - F01: two glue-test comments still credited "patch 0002" for what sqlite-js 1.4.3 now does. - F02: the v test assumed cancel_calls was still 0; it now resets it, as the w and h tests do. Glue test 50 of 50 normally and as on SQLite 3.40. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7082: Record the phone run of the 1.4.3 build On the Note20, with an AAR built from 0c2e603ee: the trial app passes 7 of 7 as a 64-bit and as a 32-bit process, on a new and an existing database, and the template (dev-assets #79) stops its runaway query 11 to 12 ms after Cancel in its 64-bit and 32-bit debug builds and its release build. The README said the 1.4.3 build had not run on a phone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw * ADFA-7135: Correct two README lines the CI and device work made false "No workflow runs either yet" has been false since the test-sqlite-debugger workflow: it runs test.sh, the C and JNI tests. The JVM tests are still in no workflow, which the line now says. "Nothing has run in an app on a device" has been false since the device runs recorded on ADFA-7135. What is left is a device run of the current code, because those results predate the review fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Refuse SQL that holds more than one statement bridge_query prepared with no tail pointer, so SQLite compiled only the first statement: query with "SELECT 1; SELECT 2" ran the first, dropped the second and reported success, and explain_query_plan (which prefixes the client's SQL) did the same. A lone comment returned an empty result, and anything after a NUL character was dropped too, since SQLite reads no further. prepare_one now prepares the tail as well. Whitespace, comments and semicolons prepare to no statement and are accepted; anything else, including a tail that fails to prepare (the server's authorizer refuses a trailing write at prepare time), fails the call with SQLITE_ERROR, "the SQL holds more than one statement; run one statement per call". SQL with no statement, or with a NUL, fails with its own message. Every tool reaches SQLite through bridge_query, so this covers query and explain_query_plan; the other tools send fixed SQL, and get_stats builds its COUNT(*) from quoted table names, not client input. Preparing the tail is not running it: the only effects are those a PRAGMA can have at prepare time, under the same authorizer a client already meets by sending that statement alone. Test (JniQueryTest, the real JNI path on a host JVM, run by test.sh): two statements, a statement after a comment, a trailing DELETE, a trailing syntax error and EXPLAIN QUERY PLAN with a second statement give the more-than-one message; a lone comment, a lone semicolon and a NUL give theirs; trailing semicolons, whitespace, comments, an open comment and a leading comment still run. With the fix reverted the 8 refusal checks fail, each "null vs 1 the SQL holds ...": the call ran. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say when a query ran out of time waiting for another tool call A query's 50 s deadline is set before runChecked waits for the tools' lock, so a call queued behind a slow one could fail with "the time limit passed before the query started" or "the query ran past its time limit", and the agent would read that as its own query being too slow. The deadline still starts before the wait (decided in review, so it bounds the wait for an answer once set); only the error changes. runChecked times its wait for the lock, and when the time ran out (SQLITE_INTERRUPT) after that wait took at least half of what the call had left, the message adds "(this call waited N s of its 50 s for another tool call to finish; tool calls run one at a time, so retry it)". Not counted: get_stats sets its deadline before its path check, which also takes the lock, so a wait there is not attributed. A tool call's first wait, in the idle check, comes before any deadline is set. Test (DatabaseToolsTest, fake clock): a second call takes the lock just after the query set its deadline, as a third concurrent call can, and holds it while the fake clock moves. A wait of 50.001 s and of 30 s each get the note; a 10 s wait followed by the query's own timeout does not. Without the fix the first two fail: expected "...started (this call waited 50.001 s of its 50 s ...)" but was "...started", and "the query ran past its time limit" with no note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Start a tool call's time limit when the call begins The 50 s limit was meant to make the server give up before the client (60 s), so a timed-out call never leaves a query holding the lock after the client has stopped waiting. It did not: every call first waited for the lock in the idle check, and run() set its deadline only after that and the path check, so a call queued behind a slow one could run a full 50 s after the wait. Each tool call now gets a Call when it begins: its deadline (DEADLINE_MS, unchanged) and the time it has spent waiting for the lock. Every lock taken inside the call (idle check, path check, each query, get_stats included) goes through Call.locked, which adds the wait. The note from ff0bd0c6b now uses that total: when the time runs out after waits of at least half the limit, the error says the call waited N s for another tool call and should be retried. Test (DatabaseToolsTest, fake clock): a call starts while another holds the lock and waits for it in the idle check. After a 50.001 s wait a query fails with "the time limit passed before the query started (this call waited 50.001 s ...)"; after 30 s a query that then times out gets the note; get_stats after a 50 s wait fails the same way; a 10 s wait gets no note. Against ff0bd0c6b three fail: the 50.001 s query and get_stats succeed (AssertionError: {"isError":false,...}), and the 30 s case reads "the query ran past its time limit" with no note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7135 Let the query backstop's ROLLBACK past the server's authorizer After every query bridge_query ran ROLLBACK when the connection was not in autocommit, as a backstop for a transaction left open. On a read-only server connection, the kind every tool uses, the authorizer denies SQLITE_TRANSACTION, and SQLite authorizes ROLLBACK as that action: the ROLLBACK failed with "not authorized", its result was ignored, and the transaction and its lock on the app's database stayed. Nothing a client sends opens one today (BEGIN and SAVEPOINT are refused), so the backstop only mattered for a hole in the authorizer, and there it did nothing. sqlitedbg_end_transaction (sqlitedbg.h) now does the rollback. It sets a thread-local flag around its own sqlite3_exec("ROLLBACK"), and the authorizer lets SQLITE_TRANSACTION through only when that flag is set and the statement is ROLLBACK. A client's BEGIN, COMMIT, END and ROLLBACK are still refused, also while a transaction is open, and SAVEPOINT (with ROLLBACK TO) is untouched. bridge_query checks the result: a rollback that fails becomes the call's error, "a transaction was left open and rolling it back failed: <errmsg>", with ROLLBACK's code. If the query had already failed, that error is kept instead. The connection stays cached either way, so each later query tries the rollback again. Tests: - C (sqlitedbg_test.c, test_server_ends_transaction): a read-only server connection is put into a transaction holding a read lock by clearing the authorizer, running BEGIN and a SELECT, and putting the real authorizer back (a SQLITEDBG_TEST hook exposes it). The app's write gets SQLITE_BUSY. The client's ROLLBACK, COMMIT and BEGIN still get SQLITE_AUTH. sqlitedbg_end_transaction returns SQLITE_OK, the connection is back in autocommit, and the app can write. Afterwards the client's BEGIN and ROLLBACK are still refused. test_server_holds_no_locks also checks that COMMIT, END and ROLLBACK are refused. With the authorizer change reverted it fails with "sqlitedbg_end_transaction(srv) == SQLITE_OK (23 vs 0)", then autocommit stays 0 and the app's write is "database is locked". - JNI (JniQueryTest): a writable server connection holding BEGIN IMMEDIATE, with an authorizer that refuses ROLLBACK, fails the next query with "23 a transaction was left open and rolling it back failed: not authorized" while the app stays locked out. Once that authorizer is cleared, the next query rolls the transaction back and the app can write. With the old unchecked ROLLBACK restored it fails with "the failed rollback is reported: null vs 23 ...": the query returned as if nothing were wrong. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn * ADFA-7136 Say when get_schema cut a CREATE statement get_schema reads sqlite_master with a 64 KiB text limit but reported only truncated: result.hasMore, which means more rows exist. A view or trigger whose SQL is longer than 64 KiB came back as a prefix with truncated false, and an agent would read it as the full definition. Each entry now has truncated, true when a value in its row was cut. The result also has truncated_cells, the count of cut values, named as query names it. The top-level truncated is true when anything was cut or rows past the first 1000 were left out. The tool description gives the 64 KiB limit and the three fields. The limit is now a constant, MAX_SCHEMA_SQL_BYTES. The README's Limits paragraph says it too. Other tools checked: query already reports truncated_cells and has_more. explain_query_plan and integrity_check use the 4 KiB text limit and report neither, and were left alone: a plan line or an integrity message near 4 KiB, or more than 1000 of them, is not a realistic case, and integrity_check's ok compares against "ok", which a cut value cannot equal. get_stats reads only numbers and table names. Tests (DatabaseToolsTest with FakeDebugEngine): getSchemaSaysWhichCreateStatementWasCut gives get_schema a result whose view SQL is listed as cut. The top-level truncated is true, truncated_cells is 1, the view entry has truncated true, and the table entry has truncated false. getSchemaIsTruncatedPastMaxRowsEntries checks that 1001 entries still give truncated true with truncated_cells 0. getSchemaGroupsByType checks false and 0 when nothing is cut. With the reporting reverted the first fails with "a cut CREATE statement makes the result truncated",…
* ADFA-7082: Vendor sqlite-js 1.3.7 with our patches
sqlite-js 1.3.7 (Apache-2.0, with QuickJS/quickjs-ng amalgamated in
libs/quickjs.c, MIT), only the files the AAR build uses, with patches/
applied: 0001-0008 are the Termux package's (terminal-packages
packages/sqlite-js), 0009 makes each call measure its own thread's
stack, and 0010 adds sqlitejs_cancel_all(). 0001-0009 are sent upstream
as sqliteai/sqlite-js #11-#19.
vendor.sh rebuilds upstream/ and the license notices from the release
(checked against its SHA-256) and patches/, or with --check tells
whether they match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Build the sqlite-js AAR for apps in subprojects:sqlite-js
The AAR the JavaScript-in-SQLite project template depends on:
libsqlitejs.so for arm64-v8a, armeabi-v7a and x86_64 (minSdk 26), and
SqliteJs: cancelAll(), libraryPath(), ENTRY_POINT (loads the functions
stored in js_functions on every connection) and
ENTRY_POINT_FOR_DEFINING. sqlitejs_android.c, ours, holds the JNI and
that entry point; the version script exports only the entry points and
JNI_OnLoad. Nothing in CoGo depends on the module.
AndroidModuleConf leaves it without the v7/v8 flavors, like
:plugin-api, since one AAR serves every ABI, and without core-library
desugaring, like :logsender, so apps need not enable it.
Tested in a trial app (requery 3.49.0, Room 2.8.4) on a Galaxy Note20
Ultra as a 64-bit and a 32-bit process: scalar and aggregate from DAOs,
deep recursion on pool threads, 32 parallel queries under WAL, and a
runaway query stopped by cancelAll() within 5 ms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Release the sqlite-js AAR to sqlite-js-latest
A manual workflow, like release-plugin-api.yml: checks the vendored
sqlite-js, builds the AAR from main, and replaces the moving
sqlite-js-latest release, from which dev-assets fetches it into the
template that uses it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Build the sqlite-js AAR for arm64-v8a and armeabi-v7a only
Apps built with Code on the Go run on ARM phones, so the AAR no longer
carries x86_64. ADR 0005 says so. CLAUDE.md's ABI section now names the
two modules without v7/v8 flavors, as ARCHITECTURE.md and ADR 0005 do
(review of PR #2244, F07).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Run no stored code by default; test sqlite-js on pull requests
From the reviews of PR #2244 (independent F02, F03, F05, F06; CodeRabbit):
- ENTRY_POINT (sqlite3_sqlitejs_init, also the name SQLite derives from
libsqlitejs.so) now loads sqlite-js alone. The old entry point loaded
the functions stored in js_functions, which runs their code, so any
database file the app opened ran its stored JavaScript at once.
Loading them is now ENTRY_POINT_FOR_TRUSTED_DATABASE
(sqlite3_sqlitejs_trusted_init), for databases the app made.
ENTRY_POINT_FOR_DEFINING is gone: ENTRY_POINT does that job.
- The trusted entry point loads each stored function on its own, so one
that fails is logged and skipped instead of dropping those after it.
- cancelAll()'s Javadoc and the README say it stops JavaScript in every
query, so call it only for a known runaway and repeat it until the
query ends.
- test.sh runs upstream's test suite with patches/, and glue_test.c,
the first test of sqlitejs_android.c. test-sqlite-js.yml runs
vendor.sh --check and test.sh on pull requests for this module.
glue_test.c passes 14 of 14; against the old glue 5 fail (stored
functions loaded by ENTRY_POINT, functions after a broken one dropped).
The AAR builds and exports the two entry points, sqlite3_js_init and
JNI_OnLoad. Not run on a device.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Update sqlite-js-latest in place, out of latest-release selection
release-sqlite-js.yml deleted the release and its tag before making the
new one, so a failed upload left dev-assets nothing to fetch. It now
uploads the new assets over the old ones, putting the old ones back if
that fails, then moves the tag and the notes. The release is created and
kept with --latest=false, so it never becomes the repository's latest
release (CodeRabbit, PR #2244).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Sort the QuickJS copyright lines the same on every machine
vendor.sh built LICENSE.quickjs with sort -u in the machine's locale, so
the new test-sqlite-js workflow's vendor.sh --check failed on the runner:
en_US.UTF-8 and C order "2017" and "2017-2018" differently. It now sorts
with LC_ALL=C, and upstream/LICENSE.quickjs and the META-INF notice are
regenerated; only the order of their copyright lines changes. --check
passes under C, C.UTF-8 and en_US.UTF-8.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Log stored functions that cannot be listed; guard the tag move
From CodeRabbit's review of the previous commits:
- The trusted entry point returned silently when it could not list the
stored functions (busy, out of memory, an odd table), opening the
connection with some or none of them. Each failure is now logged; the
connection still opens. It first looks js_functions up in
sqlite_master, so a database without stored functions makes SQLite
log no "no such table" error on each connection, as it did.
- release-sqlite-js.yml moves the tag and edits the notes in the same
guarded sequence as the upload. If any step fails, the previous
assets and tag are put back.
glue_test.c passes 16 of 16; the two new tests fail on the previous
glue.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Vendor the reviewed sqlite-js patches
Patches 0002, 0003, 0004 and 0010 are regenerated after three reviews:
the independent reviews of terminal-packages #6 and of this PR, and
CodeRabbit's review of this PR.
- 0002: garbage is collected before the memory limit fills. Running
out of memory through small allocations reports "out of memory".
- 0003: the README says TEMP views and triggers can call the js_*
functions.
- 0004: db.exec throws for a buffer it cannot read instead of binding
NULL. A typed array's own offset and length are used, not properties
a script defines.
- 0010: a cancel also interrupts the cancelled call's statement, so a
runaway JavaScript collation stops. Before, nothing could stop one.
The other patches change only in their headers and line numbers.
upstream/ is regenerated with vendor.sh, and vendor.sh --check passes.
SqliteJs.cancelAll() and the README say a cancel interrupts the
statement too.
Tested:
- test.sh: upstream's suite passes 16 of 16, and the glue test 16 of 16.
- In the work repo, the same suite passes under ASan and UBSan with
leak checking, and each new test fails without its fix.
- The AAR builds for arm64-v8a and armeabi-v7a.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Put back both the assets and the tag if a release update fails
From CodeRabbit's review: under bash -e, a failed restore of the
previous assets stopped the rollback before it put the tag back, so the
tag could name the new build while the release held the old one. Each
restore is now attempted, reported if it fails, and the step still
fails.
Checked with gh stubbed out: when the update fails and the asset restore
fails, the tag restore still runs and the step exits 1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Find js_functions in any case; sync the cancel test; doc caveats
From CodeRabbit's review of the vendored patches:
- The trusted entry point looks up js_functions with COLLATE NOCASE, as
SQLite resolves a table name, so a table named JS_FUNCTIONS loads. A
new glue test, now 18 of 18, fails without it.
- Patch 0010's Cancel all test cancels once the JavaScript under test
has called started(), an SQL function, instead of after a fixed
200 ms. A slow start can no longer end the test at its alarm. It still
hangs without the fix it tests.
- SqliteJs.cancelAll() and the README now say two more things. An
interrupted INSERT, UPDATE or DELETE in an explicit transaction rolls
the whole transaction back. And a cancel reaches SQL that JavaScript
runs through db.exec only when that SQL returns to JavaScript.
Tested:
- test.sh: upstream's suite passes 16 of 16, also under ASan and UBSan
in the work repo, and the glue test 18 of 18.
- vendor.sh --check passes.
- The AAR builds with the new lookup for arm64-v8a and armeabi-v7a.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Let a re-run repair a release left without its assets
A run that stops during `gh release upload --clobber` can leave an asset
missing. The next run then failed at the backup download ("no assets match
the file pattern") before it uploaded anything, so re-running could not
repair the release. The step now backs up only the assets that exist and
puts the previous ones back only when it has both.
Tested with a stub gh over a fake release: both assets missing now ends with
the new pair and the tag moved (before: exit 1 at the download); the other
five cases are unchanged. Checked against gh 2.46: download fails only when
no pattern matches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Vendor sqlite-js main with our changes merged, one patch left
Upstream merged our patches 0001 to 0009 (sqliteai/sqlite-js #11 to #19)
on 2026-11-12, with fixes of its own. One fixes a bug in our 0002: a
memory limit lowered under memory that is garbage left the connection
out of memory until the limit was raised again (ef06558).
upstream/ is now sqlite-js main at c8ae85a, the same source as the Termux
package 1.3.7-p20261112, with one patch: 0001, sqlitejs_cancel_all(), our
old 0010 rebased. Its test now fails with a message when the JavaScript
under test has not started within 10 seconds, instead of cancelling
anyway, and uses upstream's watchdog thread instead of alarm(). The patch
is offered upstream in sqliteai/sqlite-js issue 20.
vendor.sh, test.sh and test-sqlite-js.yml take the commit (COMMIT, URL)
instead of the release tag. vendor.sh --check passes; test.sh passes:
upstream's suite 16 of 16 with Cancel all, glue_test 18 of 18. The
upstream suite with the patch also passes under ASan + UBSan; without the
patch's sqlite3_interrupt() its collation case runs until the watchdog,
and with started() never called the worker fails with its message. The
native library builds with NDK 29 for arm64-v8a and armeabi-v7a, with no
warnings in sqlitejs.c or sqlitejs_android.c, and exports the same four
symbols.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Vendor the sqlite-js 1.4.1 release
Upstream released 1.4.0 and 1.4.1 on 2026-11-12, after c8ae85a. Both
contain it, and 1.4.1 differs from it in src/ and libs/ only in
SQLITE_JS_VERSION, so js_version() now reports 1.4.1. vendor.sh, test.sh
and test-sqlite-js.yml take the release's archive again (VERSION,
SHA256, URL). Patch 0001 is unchanged but for its context.
The scripts now take the archive's one top directory whatever its name
(tar --strip-components=1). They named it after COMMIT, so the README's
"point URL at its tag again" would have failed: a tag's archive unpacks
to sqlite-js-<tag> (independent review). The README says how to vendor
a release, and a commit between releases.
vendor.sh --check passes on the 1.4.1 archive (SHA-256 d45d394f...3078).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Let a connection open, and its stored functions load, during a cancel
A cancelAll() that landed while another thread opened a connection made
that connection fail to load sqlite-js (SQLITE_NOMEM), so a Room query
on a new pool connection failed (independent review). Setting up the
runtime runs JavaScript of its own, which the interrupt handler stopped.
Patch 0001 now cancels only JavaScript inside a call (js_enter), and its
Cancel all test opens 200 connections while another thread cancels
without pause: the first one failed before.
A cancel that lands while the trusted entry point loads a stored
function stops that function's code the same way, and the function was
then missing from the connection for good. load_stored_function now
tries such a load again, up to three tries in all; its stored code runs
again each time. glue_test.c stores a function whose code cancels the
first time it loads: it loads on the second try, and with one try it is
missing. The README and SqliteJs's Javadoc say both.
test.sh passes: upstream's suite 16 of 16, glue_test 22 of 22.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Patch two stack-bound crashes and two garbage cases
0002, after CodeRabbit's review: code that called itself without end
crashed the process instead of failing with "Maximum call stack size
exceeded" in two cases.
- On a thread with less than 64 KB of stack left, js_enter kept the
connection's 1 MB size rather than the room it measured. It now keeps
any measurement, and 1 rather than 0, which turns the check off.
- On the main thread, RLIMIT_STACK was counted from where the first
measurement was taken. Loaded 2 MB deep, the extension allowed 10.2 MB
of an 8 MB stack. It is now counted from the stack's top, as the
kernel counts it.
0003, after the independent review of terminal-packages #6: garbage
could leave an allocation that fits in the memory limit failing on every
try. After 40 MB of cyclic garbage, new ArrayBuffer(30 MB) failed under
the 64 MB default. And after a limit was lowered to 32 MB above the
garbage, new ArrayBuffer(16 MB) failed. The extension now collects
after any "out of memory" error and whenever a limit is set.
Each patch adds tests to upstream's suite that fail without it. The
suite passes 16 of 16 with all three patches, also under ASan and UBSan,
and test.sh's glue_test 22 of 22. The NDK 29 build for arm64-v8a and
armeabi-v7a has no warnings outside QuickJS and exports the same four
symbols. Both fixes are offered upstream.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Let a re-run replace a release left as a draft
gh release create makes a draft and publishes it once its assets are
uploaded. A first run that stopped during that upload left a draft:
the next run found it, skipped the create, and failed fetching its tag,
which a draft does not have yet. Every re-run then failed (independent
review). The step now deletes a draft release, which dev-assets cannot
fetch from, and creates the release again.
Tested with a stub gh over a fake release, eight cases. The draft case
failed with a 404 before, and now ends with the new assets and tag. The
other seven are unchanged: no release, normal, upload fails, tag update
fails, both assets missing, one missing, and upload fails with both
missing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* style: spotless reformat, no functional change
Spotless wraps the cancelAll() Javadoc paragraph, which the previous
commits lengthened.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: End the result sets an interrupted call leaves open
CodeRabbit: SQLite keeps an interrupt in effect while any statement of
the connection runs, and a db.exec result set that JavaScript keeps open
is a running statement. After cancelAll() stopped JavaScript that kept
one in a global, every later statement on that connection failed with
"interrupted", until the connection closed. A stored function whose code
kept one could not load on any of its three tries. sqlite3_interrupt()
does the same, without our cancel patch.
Patch 0004 lists each connection's result sets. When the outermost call
into JavaScript returns on an interrupted connection, it finalizes those
still open. Reading on from one that JavaScript kept throws
"interrupted". Reproduced on the host, with a cancel and with
sqlite3_interrupt(): every later statement failed before, and all run
after.
Upstream's Interrupt test interrupts code that keeps a result set, in a
global and as garbage, and fails without the patch. glue_test.c stores a
function whose code keeps one and cancels the first time it loads. It
loads on its second try, and the connection runs SQL afterwards; without
the patch, those three checks fail.
test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan,
and glue_test 26 of 26. The NDK 29 build for arm64-v8a and armeabi-v7a
has no warnings outside QuickJS and exports the same four symbols.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Make ending result sets safe when it runs JavaScript, and on old SQLite
CodeRabbit, on 0004:
- 0005: finalizing a result set that is computing a JavaScript window
function runs the function's final, whose js_leave() ended the result
sets again on the interrupted connection, finalizing the same statement
twice. Under ASan that is a use after free in sqlite3VdbeMemFinalize,
reproduced on the host. Each statement is now taken from its result set
before it is finalized, the list is walked again from its head after
each one, and a nested call does nothing. Upstream's Interrupt test now
keeps a result set computing a window function; it fails under ASan
without 0005.
- 0006: on SQLite before 3.41, which has no sqlite3_is_interrupted(),
0004 never ran, though a cancel still interrupts the connection. The
interrupt handler now records the interrupt it sends. Built to report
SQLite 3.40, a cancel of JavaScript that keeps a result set left every
later statement failing before 0006, and not after.
test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan,
and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings
outside QuickJS and exports the same four symbols.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Stop what ending result sets runs; count the interrupts db.exec sees
CodeRabbit, two more cases on SQLite before 3.41, both in patch 0007:
- Ending result sets after a cancel can run a window or aggregate
function's final, which begins after the cancel, so nothing stopped
it: a final that never ended hung the cancelled query. The interrupt
handler now stops any JavaScript while result sets are being ended.
- A direct sqlite3_interrupt() that reached a db.exec statement's SQL,
with another result set kept open, went unseen. A result set whose
step returns SQLITE_INTERRUPT now records it.
Checked with the patched source built to report SQLite 3.40: the endless
final hung before and ends after, and a direct interrupt during
db.exec's SQL, caught or not, left later statements failing before and
not after. Still unseen before 3.41, and said in the README: an
interrupt that never reaches the SQL that JavaScript runs. Android's
cancelling never calls sqlite3_interrupt(), and cancelAll() is covered.
test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan,
and glue_test 26 of 26. The NDK 29 build for both ABIs has no warnings
outside QuickJS and exports the same four symbols.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Answer the independent review of patches 0004 to 0007
- 0009: a result set's SQLITE_INTERRUPT now counts as an interrupt only
before SQLite 3.41. A progress handler that stops a statement, as
Android's cancelling does, gives the same code and interrupts nothing
else, yet it ended the result sets earlier calls kept, on any SQLite.
- 0008: the Interrupt test's "garbage" result set was freed by
reference counting, so the case passed without 0004. It is now a
reference cycle, and fails on 1.4.1 without 0004. Also pushed to
sqliteai/sqlite-js#24.
- Tests for 0006, 0007 and 0009, which had none: glue_test.c cancels
JavaScript that keeps a result set, then a kept window function whose
final never ends, then has a progress handler stop a statement. test.sh
runs it twice, the second time with sqlitejs.c built to report SQLite
3.40. Without 0009 the progress-handler check fails; without 0007 the
3.40 run hangs until the test's 30 s alarm; without 0006 seven checks
fail in the 3.40 run.
- README: a cancel ends every result set open on the connection, not
only the stopped call's. And on any SQLite, an sqlite3_interrupt() that
lands while no JavaScript runs leaves the connection failing while
JavaScript keeps a result set, so finish result sets before a call
returns. Reproduced on 3.49: every later statement fails, and
sqlite3_close returns SQLITE_BUSY.
test.sh passes: upstream's suite 16 of 16, also under ASan and UBSan,
and glue_test 34 of 34 in both runs. The NDK 29 build for both ABIs has
no warnings outside QuickJS and exports the same four symbols.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Test a direct interrupt during db.exec with a result set kept
CodeRabbit: the case that 0007's record of a step's SQLITE_INTERRUPT is
for had no automated test. glue_test.c now keeps a result set, has
another thread call sqlite3_interrupt() while db.exec runs a query that
never ends otherwise, and checks that the connection runs SQL and that
the kept result set was ended. In the run as SQLite 3.40, those checks
fail without the record. The checks that a kept result set was ended
now tell an ended one (caught in JavaScript: "ended: interrupted") from
a connection that is still interrupted, whose error is the same word.
test.sh passes: upstream's suite 16 of 16, and glue_test 37 of 37 in
both runs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7135: Define the interface between the SQLite debugger extension and its server
sqlitedbg.h is what the extension implements and its JNI layer calls;
DebugEngine.kt is what the server (ADFA-7136) builds against, with a fake
for JVM tests. Not yet built by Gradle: the module has no build file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136: Copy the MCP server from ShareYourApps, renamed
McpHttp.kt and McpProtocol.kt from Local Store Server Combined with only the
package, server name, title, instructions and 401 texts changed.
McpProtocolTest.kt still names that project's tools and does not compile;
ADFA-7136 rewrites it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7135 Add the sqlite-debugger module skeleton
Module build file modelled on sqlite-js (no ABI flavors, both ABIs, no STL,
16 KiB pages), plus Kotlin at API 2.0 for apps built with CoGo. Registered in
settings, modulesWithoutAbiFlavors and disableCoreLibDesugaringForModules.
The CMake file arrives with the extension in the next commit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136: MCP server with the eight read-only database tools
Binds 127.0.0.1 on port 0 with a new token per process start, and serves
list_databases, list_connections, get_schema, query, explain_query_plan,
get_stats, integrity_check and get_events against DebugEngine. JVM tests
run against FakeDebugEngine (51 pass). DebuggerStartup.kt and the manifest
are Android-only and not yet compiled. Formatting follows in its own commit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7135 Implement the SQLite debugger extension and its host tests
sqlitedbg.c implements sqlitedbg.h as a loadable-extension client. Per-connection
state is freed only from the xDestroy of sqlitedbg_connection_id; the trace CLOSE
event only marks it closing. Events live in a ring of records in their exported
layout. Server connections are recognised by a thread-local flag set around
sqlitedbg_open_server's own open.
test.sh builds SQLite 3.49.1 from the amalgamation (pinned) and runs
sqlitedbg_test.c under ASan+UBSan and under TSan. The same run writes or checks
the fixture the EventDecoder JVM test reads.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7135 Add the JNI layer and NativeDebugEngine
sqlitedbg_jni.c registers NativeBridge's natives from JNI_OnLoad (the version script
exports nothing else) and reaches SQLite only through the extension's api table.
ServerConnection.query steps the statement in C, binds args by type, applies
QueryLimits, and stops at the deadline through a progress handler on the server
connection. EventDecoder mirrors the exported record layout and is tested against
the fixture the host C test writes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* style: spotless reformat of the SQLite debugger module, no functional change
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7135 Fix three review findings in the extension
- read_events moves the cursor past dropped events when it copies nothing, so a
drop is reported once.
- An internal failure in sqlitedbg_extension_init is logged and the connection left
untracked; the app's own sqlite3_open no longer fails because of it.
- A trigger is told apart from app SQL by X differing from sqlite3_sql(P), not by a
"--" prefix, so statements that start with a comment are expanded.
test.sh builds the extension with SQLITEDBG_TEST for the failure hook.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136: Document the SQLite debugger module
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136: List sqlite-debugger among the modules without ABI flavors
AndroidModuleConf.kt already excludes it; ARCHITECTURE.md and CLAUDE.md
named only plugin-api and sqlite-js.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136 Never let the debugger crash or miss the host app's early connections
- DebuggerStartup catches Throwable after the debuggable check, so a missing
requery library (UnsatisfiedLinkError) disables the debugger instead of
killing the app. The check itself still throws.
- install() runs synchronously in onCreate; only the server start is on the
thread, so connections opened in Application.onCreate are tracked.
- McpHttp: connection and accept threads catch Throwable; an Error while
handling a request is answered with a 500.
- McpHttp: a failed accept sleeps 100 ms, doubling to 2 s while failures
continue, and resets on success (no spin on EMFILE).
Tests: an Error thrown by a tool gives HTTP 500 and the server keeps serving;
a ServerSocket whose accept fails is retried with growing gaps, then serves.
DebuggerStartup imports android.* and has no JVM test.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7135 Keep read-only server connections from holding locks
The read-only authorizer allowed BEGIN, SAVEPOINT and PRAGMA locking_mode, so
a client could hold a lock on the app's database: BEGIN; SELECT left the app's
INSERT failing with SQLITE_BUSY until ROLLBACK.
- sqlitedbg.c: deny SQLITE_TRANSACTION, SQLITE_SAVEPOINT, PRAGMA locking_mode
and PRAGMA busy_timeout (any form) on read-only server connections.
- sqlitedbg_jni.c: bridge_query rolls back if the connection is not in
autocommit when it returns (covers writable connections).
- Host C test: each denied statement returns SQLITE_AUTH and the app can still
write after a read on that connection.
Without the authorizer change the test fails on all 8 statements (BEGIN and
SAVEPOINT: "database is locked" for the app's INSERT). The backstop is tested
with the JNI test.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136 Bound query results and report truncation per cell
- M4: QueryLimits.maxTotalBytes (DatabaseTools passes 4 MiB). bridge_query
counts the TEXT/BLOB bytes kept and 8 per number, and stops with hasMore
before the row that would pass the budget; the first row always goes in so
a page makes progress. The tool result text is serialised compact: it was
sent twice, pretty and as structuredContent.
- L11: the engine reports cut cells (QueryResult.truncatedCellIndexes, row *
columns + column) instead of DatabaseTools guessing from size >= limit, so
a BLOB of exactly maxBlobBytes is no longer flagged.
- L12: get_schema and get_stats read sqlite_master (sqlite_schema needs 3.33).
- L13: sqlite3_column_text/blob returning NULL (out of memory) is checked.
JVM tests: blob at the limit vs one byte over, the budget pages a result of
3 MiB rows, sqlite_master in the SQL sent, compact result text. Each fails
with its fix reverted. The native side (budget, cut cells) is tested by the
JNI test in a later commit; L13 has no test (needs an allocation failure).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136 Drop stale server connections and stop expanding SQL when idle
- M7: DatabaseTools cached a server connection per path forever, so after the
app deleted and recreated its database the server read the old file. Each
cached connection remembers the ids of the app connections to its path when
it opened. Before each tool call it is closed and dropped when no live app
connection has the path, or none of those ids is left.
- L14: the first get_events turned on bound-value expansion until the server
stopped, so every app statement was expanded twice forever. It now goes off
60 s after the last get_events call, checked on every tool call and by a
daemon timer; the tool description says so.
- L10 (one lock for all tool calls) is documented in the class KDoc.
Tests: recreated database reopens (opened 2, closed 1), a connection survives
while a seen app connection remains, a vanished path closes the cached one,
and expansion stops after 60 s. Each fails with its fix reverted (expected 2
but was 1; expected 1 but was 0; "60 s after the last get_events").
Limit accepted: a database replaced in place while the same app connections
stay open is not detected.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136 Test the JNI query path
test.sh now also builds the JNI layer as it ships (libsqlitedbg.so without
SQLITE_CORE, with the version script) against a requery-like libsqlite3x.so
(amalgamation, THREADSAFE=2, all symbols exported) and runs
src/test/jni/JniQueryTest.java on the host JVM through NativeBridge. It is
skipped with a message when no JDK is on PATH.
It uses Java stubs of NativeBridge and DebugEngineException (same names and
native signatures) rather than compiling the Kotlin, so only a JDK is needed;
test.sh fails if the native names in NativeBridge.kt and the stub differ. A
change of a Kotlin parameter type alone is not caught.
Covers: value types, paging and hasMore, the total-bytes budget (including
"first row always goes in" and the budget stopping on a row boundary), per-cell
truncation at, over and under the limit with row * columns + column indexes
and a budget-dropped row's cells, bound types, the deadline giving
SQLITE_INTERRUPT, refused writes giving SQLITE_AUTH, BEGIN/SAVEPOINT/PRAGMA
refusals leaving the app able to write, and the rollback backstop.
Checked to fail with each native fix reverted: budget (50 rows vs 4), cut cell
indexes ([] vs [1, 3]), rollback backstop (app INSERT 5 vs 0, SQLITE_BUSY),
authorizer (BEGIN: 0 vs 23), dropped row's cut cells ([0, 1] vs [0]).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7136 Document the JNI test and the requery trace limit
README: the JNI test and how it stands in for the Kotlin, and that requery's
own sqlite3_trace (log.tag.SQLiteStatements or SQLiteTime VERBOSE) replaces
ours on a connection, so its events stop. No code change for that.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
* ADFA-7082: Vendor the sqlite-js 1.4.2 release
Upstream released 1.4.2 with our stack, garbage-collection and
result-set patches merged (sqliteai/sqlite-js #22, with two maintainer
commits, #23 and #24) and with a fix for the use after free we reported
(#25). That fix also changes behaviour: a db.exec result set no longer
outlives the call into JavaScript that created it, and reading one
afterwards throws "The result set was closed when the call into
JavaScript that created it returned".
So patches 0002 to 0009 go:
- 0002 to 0005 and 0008 are upstream, by patch-id identical except for
0002, which has the maintainer's two commits on top.
- 0006, 0007 (its second half) and 0009 only told interrupts apart for
result sets kept across calls, which 1.4.2 no longer allows.
0001 (sqlitejs_cancel_all, issue 20) is rebased: the same changes, with
new context in the struct. A new 0002 keeps what 0006 and the first
half of 0007 did for a cancel on SQLite before 3.41: ending a cancelled
call's result sets runs the finals of the window and aggregate
functions they were computing, each a call that begins after the
cancel, which before 3.41 nothing else stops; and those result sets
read on as "interrupted". It is narrowed to a cancelled call, since in
1.4.2 result sets are also ended on every normal return. The next
commit updates the tests for 1.4.2.
vendor.sh --check passes on the 1.4.2 archive (SHA-256
1aa4c566...cf24). The libs/ and license files are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Test sqlite-js 1.4.2's result-set rule and patch 0002
glue_test.c, for 1.4.2:
- The progress-handler case kept a result set across calls, which
1.4.2 no longer allows. It now checks, within one call, that a
statement a progress handler stopped (as Android's cancelling does)
leaves the call's other result set readable, on any SQLite, and that
the connection runs SQL afterwards.
- A direct sqlite3_interrupt() before SQLite 3.41 shows nowhere, so its
kept result set reads as one that outlived its call; on 3.41 and
later, as interrupted.
- The cleanup that read a kept result set after its call is gone: it
now throws.
test.sh and the README name patch 0002 for the run as on SQLite 3.40,
and the README lists the two patches, states the 1.4.2 rule, and says
the 1.4.2 build has not been run on a phone yet.
test.sh: upstream's suite 17 of 17 (its 16 and 0001's Cancel all), and
glue_test 37 of 37 both normally and as on SQLite 3.40. Without patch
0002, the normal run still passes 37 of 37, and the 3.40 run fails as
expected: the kept result set after a cancel reads "The result set was
closed ..." rather than "interrupted", and the window function whose
final never ends hangs until the 30 s alarm stops the test. Both ABIs
build with NDK 29, and libsqlitejs.so exports only JNI_OnLoad and the
three entry points.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Keep a call's cancel for the finals its result sets run
From the independent review of 3a5cb5356 and 464e6e7ef (no critical,
high or medium findings; F01 to F05 low or nits). Patch 0002 told a
cancelled call apart only once, in js_leave(), and each final that
ending its result sets ran entered JavaScript as a new call with a new
cancel epoch. So, before SQLite 3.41:
- a cancel that landed while the result sets were ended stopped only
the final then running, and the next final that never ended hung the
statement (F01);
- a cancel that landed just before the call returned let the call
succeed with its finals skipped, on any SQLite (F02).
Patch 0002 now keeps the call's epoch while its result sets are ended
(js_enter), so a cancel during the call or the ending stops every
final, and a late cancel fails the statement with an interrupt. The
ending_cancelled flag and its interrupt-handler check are gone; the
patch is 8 lines. upstream/ is regenerated with vendor.sh.
glue_test.c, 44 tests (was 37):
- 31: a cancelled call that keeps two result sets whose window finals
never end (F03's case);
- 33-34: the cancel lands during the first final of a call that
returned normally (F01);
- 36-37: a cancel that lands as the call returns fails it (F02);
- 43: after a progress handler's stop, the kept result set reads as
outliving its call, not as interrupted (F04; it passes without the
fix too, as a guard against counting such a stop as an interrupt).
test.sh: upstream's suite 17 of 17; the glue test 44 of 44 normally and
as on SQLite 3.40. With the previous 0002, test 37 fails in the normal
run and the 3.40 run hangs at test 34; with 0001 alone, test 37 fails,
and the 3.40 run fails test 29 and hangs at test 31. README: what 0002
does now, and what the glue test covers (F05).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Say what a late cancel does to a call's finals
From the independent review of 5b9b062eb (no code defects; tests catch
what they're named for and are not flaky in 120 runs on 2 cores and 16
on 1; two low findings and a nit):
- F01: "those result sets read on as interrupted" holds only when the
cancel came before the call returned. js_leave() decides that once,
before ending them, so a cancel that lands while they are ended
stops their finals but leaves the "closed" message.
- F02: a cancel stops each final at QuickJS's next interrupt check. A
final that never ends is stopped and the statement fails, but a short
final can still run to its end, so "rather than skipping its finals"
overstated it.
The patch 0002 header and README say so; 5b9b062eb's message overstated
both in the same way. Patch 0002's code is unchanged.
- F03: test 36's final records that it ran, and a new test 38 checks
that the late cancel stopped it before it did; test 37 is renamed to
say its final is a long one.
test.sh: upstream's suite 17 of 17; the glue test 45 of 45 normally and
as on SQLite 3.40. With 0001 alone, tests 37 and 38 fail (the final ran
to its end) and the 3.40 run fails 29 and hangs at 31; with the
previous 0002, test 37 fails and the 3.40 run hangs at 34.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7135 Set the Kotlin JVM target on the compile tasks
The root build sets jvmTarget 17 on every KotlinCompile task, which
overrides the module's kotlin { compilerOptions } and made
compileDebugKotlin fail against compileOptions' Java 1.8 ("Inconsistent
JVM-target compatibility"). Setting it on the tasks keeps 1.8, as
sqlite-js uses.
First compile of the Android-only files (NativeDebugEngine.kt,
DebuggerStartup.kt, sqlitedbg_jni.c, the manifest): with this change
:subprojects:sqlite-debugger:assembleDebug builds both ABIs, the C
compiles without warnings under -Wall -Wextra, libsqlitedbg.so exports
only JNI_OnLoad, and testDebugUnitTest passes 56 tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* ADFA-7082: Read result sets as interrupted when the cancel lands while they are ended
From CodeRabbit's review of 5b5cd201c (4570522172), the same gap the
independent review noted as F01: js_leave() decides once, before ending
a call's result sets, whether they read on as "interrupted". A cancel
that landed while their finals ran stopped the finals but left the
"closed when the call ... returned" message.
Patch 0002 now has js_end_rowsets() number its passes and mark each
result set with the pass that ended it. After the loop, where nothing
runs JavaScript and so no final can have freed a listed result set, it
marks that pass's result sets interrupted if the cancel epoch has moved.
The README and the patch header say the message is "interrupted"
whether the cancel came before the call returned or during the ending.
glue_test.c: new test 36 reads both result sets after the cancel that
lands during the ending, and expects "interrupted". test.sh: upstream's
suite 17 of 17; the glue test 46 of 46 normally and as on SQLite 3.40,
and the same under AddressSanitizer and UBSan. With the previous 0002,
test 36 fails in both runs with the "closed" message.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Address review of the sqlite-js cancel patches
Patch 0002 (rebuilt from upstream PR sqliteai/sqlite-js#33) now:
- drops the redundant cancelled term from js_leave: the block after the
loop in js_end_rowsets marks a cancelled call's result sets interrupted;
- says only JavaScript the extension runs while it initialises a
connection is exempt from a cancel, not js_init_table's stored functions;
- initialises a rowset's end_pass where it is created;
- documents sqlitejs_cancel_all in sqlitejs.h.
upstream/ is regenerated with vendor.sh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7136 Bound the request head and refuse before reading the body; say the server is read-only
A local app could hold all 8 connection slots without authenticating: the 30 s timeout applied per read and the token was checked after the whole request. The head now has an overall deadline (5 s), and Host, Origin, path and token are checked before the body. The initialize instructions no longer mention a read-write mode that does not exist.
Tests: sockets that send nothing or trickle bytes are closed within the deadline and the real client is then served; an unauthenticated request with an unsent body gets 401; the instructions do not mention read-write. All three fail with the fix reverted.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7135 Refuse the process-wide heap limit and temp directory PRAGMAs on server connections
SQLite applies hard_heap_limit, soft_heap_limit and temp_store_directory to the whole process, so a client's PRAGMA hard_heap_limit=1 could make the app's own connections fail with SQLITE_NOMEM.
Test: each form (set and read) returns SQLITE_AUTH on a server connection; without the change all five return SQLITE_OK.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7135 Give server connections a 3 s busy timeout
With the app's database in rollback-journal mode, a server read failed at once with SQLITE_BUSY while the app held a write lock, exactly when the agent wants to look. The timeout is set in C and PRAGMA busy_timeout stays refused, so the client cannot change it.
Test: an app connection holds BEGIN EXCLUSIVE; a server read waits about 500 ms and succeeds once it is released, and reports SQLITE_BUSY after about 3 s if it is not. Without the timeout the first read failed after 0 ms with SQLITE_BUSY.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7135 Fail a query whose argument count differs from its parameter count
Too few arguments left the missing parameters unbound, which SQLite reads as NULL, so the query ran and returned a plausible empty result. It now throws SQLITE_RANGE with a message naming both counts.
Test (JniQueryTest, the real JNI query path on a host JVM, run by test.sh): zero args for one parameter and one for two give SQLITE_RANGE; the first expectation was NULL before, and both fail with the check disabled.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7136 List an open database once when the databases folder is reached through a link
list_databases matched the files of the app's databases folder against connection paths as strings, so on a phone (/data/user/0/<pkg> against /data/data/<pkg>) every open database was listed again as available: false. Both sides are now canonicalised before matching; paths are reported as the connections gave them.
Test: a folder listed through a symlink, and the reverse, list the open database once. Without the canonicalisation it was listed twice.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7135 Run the sqlite-debugger host tests in CI
test.sh (the extension's C tests under ASan/UBSan and TSan, and the JNI query test) ran in no workflow. The new workflow follows test-sqlite-js.yml and also triggers on the vendored SQLite headers test.sh compares against.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7137 Add debugger_endpoint_table and migration 5 to 6
The SQLite debugger in an app built by Code on the Go reports a token and
a port; Code on the Go needs to keep them per app and per project.
debugger_endpoint_table (RecentProjectRoomDatabase version 6) is keyed by
application_id and holds project_location, token, port and updated_at.
project_location is a foreign key to recent_project_table.location with
ON DELETE CASCADE, so removing a project removes its endpoints, and ON
UPDATE CASCADE, so renaming a project (which rewrites location) does not
fail once an endpoint row exists. Room enables PRAGMA foreign_keys itself
once the schema declares a foreign key, so no extra code is needed.
The pairing upsert is INSERT OR IGNORE plus UPDATE in one transaction:
minSdk 28 ships SQLite 3.22, which predates UPSERT (3.24).
Tests: migration 5 to 6 on a v5 file opened through Room (projects kept,
schema validated, cascade works on the migrated file); delete and rename
cascades.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* style: spotless reformat, no functional change
LaunchAppAction.kt was indented with spaces; the next commit edits it,
which pulls the whole file under the Spotless ratchet.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7137 Pair apps with projects and receive their debugger endpoint
Code on the Go must know which project an app belongs to before it
accepts that app's debugger token and port, otherwise any app could
register an endpoint.
- A project-started install records (application ID, project) once the
install succeeds. An existing pairing moves to the new project and its
stale token and port are cleared. LaunchAppAction only adds a pairing
when the app has none, and waits for it before launching. The Activity
is not captured in the pairing lambda.
- DebuggerEndpointReceiver (exported, action
com.itsaky.androidide.SQLITE_DEBUGGER_ENDPOINT) stores the endpoint off
the main thread. The token must be 1-128 URL-safe base64 characters and
the port 1-65535. A broadcast from an unpaired app stores nothing. A
database failure is logged, never thrown.
- Sender identity: the app attaches an immutable PendingIntent, and the
receiver trusts only its creatorPackage, which the framework sets and
another app cannot forge, on every API level. A forged broadcast could
otherwise point the AI Agent at another app's debugger server.
Tests: DAO and repository (pairing rules, failures reported as false,
move and clear on re-pairing); the receiver delivered through the
framework under Robolectric (stored, unpaired app ignored, no
PendingIntent ignored, malformed extras ignored); validation of token
and port.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7137 Send the debugger endpoint to Code on the Go once the server listens
The library broadcasts its token and port on every process start, after
the server listens, so a relaunched app (new port) updates its row.
- The broadcast carries an immutable PendingIntent, so Code on the Go can
identify the sender from its creatorPackage on every API level.
- FLAG_INCLUDE_STOPPED_PACKAGES and FLAG_RECEIVER_FOREGROUND deliver it
to Code on the Go when that is not running (cold start).
- The library manifest declares <queries> for Code on the Go so the
package is visible on API 30+.
Code on the Go's receiver is declared in the app manifest, in the
previous commit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7137 Docs: describe the debugger endpoint and database version 6
The sqlite-debugger README describes the endpoint broadcast;
ARCHITECTURE.md and the Room ADR name Recent Projects database version 6.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7137 Clear pending installs on failure and pin the endpoint broadcast contract
A failed or cancelled install left its pendingInstalls entry behind, so a later
install of the same applicationId from an APK file was paired with the wrong
project. The editor now tells the repository when an install ends without a
launch, and entries older than five minutes are ignored as a backstop. Tests:
a discarded note is not used, an expired note is not used, a recent note still
pairs (the first two fail with the discard and the expiry removed).
The broadcast extra names are consts in the library, and EndpointBroadcastTest
(Robolectric) checks the sent action, package, extras and creatorPackage. The
library is not on :app's classpath, so DebuggerEndpointContractTest in :app pins
the same literals; each test names the other.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7139 Add DebuggerEndpointService and the debugger.endpoints permission
Plugins such as AI-Agent-MCP need to reach the SQLite debugger of the app
the user just built, without the user typing a port or token.
DebuggerEndpointService.getEndpoints() returns the open project's
endpoints as DebuggerEndpoint values (application ID, port, token,
updated at), behind the new permission debugger.endpoints. Contract:
SecurityException without the permission; IllegalStateException on a read
failure or when called on the main thread; an empty list when no project
is open or no app has reported.
The API dump and docs/PLUGIN_API_CHANGELOG.md (26.43) are updated, and
the plugin docs list the permission. A plugin that declares it needs
plugin.min_ide_version 26.43: an older Code on the Go rejects the unknown
permission at validation.
Tests: the DebuggerEndpoint value class.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7139 Implement DebuggerEndpointService in plugin-manager
PluginManager hands each plugin a DebuggerEndpointServiceImpl, which
checks the debugger.endpoints permission, refuses the main thread, and
maps a read failure to IllegalStateException so a plugin cannot mistake a
failure for "no app has reported".
Tests: permission refused, no project, endpoints of another project not
returned, read failure, main thread refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7139 Serve the stored debugger endpoints to plugins
The app registers the service when it loads plugins, backed by
debugger_endpoint_table (ADFA-7137). The repository looks endpoints up by
the canonical project path, so a project opened through a symlink or a
non-normalised path still finds the rows stored under its real location.
Tests: repository lookup through a non-canonical path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7139 Docs: describe DebuggerEndpointService in the sqlite-debugger README
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7139 Leave uninstalled apps out of the endpoints and rethrow interrupts
reportedEndpoints no longer returns the stored port and token of an app that is
no longer installed (injected check, PackageManager in the app). No
<queries> is needed: Code on the Go targets SDK 28, below the package
visibility filter of SDK 30. The
Javadoc says an endpoint can still be stale after the process dies and that
updatedAtMillis is when it last reported. DebuggerEndpointServiceImpl rethrows
InterruptedException (restoring the flag) and CancellationException unchanged
instead of wrapping them. Tests: an uninstalled app is left out, installed ones
are returned, the interrupt and the cancellation pass through; all three fail
with the fix removed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7139 Docs: DebuggerEndpointService ships in 26.47, not 26.43
26.43 to 26.46 are released without it. The changelog entry moves to a new
26.47 section and the floor plugin.min_ide_version is 26.47.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7082: Vendor the sqlite-js 1.4.3 release, with no patches
Upstream merged sqliteai/sqlite-js#33, our patches 0001 (cancel) and
0002 (a cancelled call's finals and result sets) unmodified, and
released them in 1.4.3 with one fix of the maintainer's: a cancel no
longer stops a stored function's code while js_init_table(1) loads it,
as it already spared the JavaScript that loads the extension. Before,
a cancel in flight left the connection without that function. Only
that call is exempt: JavaScript the code runs through SQL is still
cancelled.
- upstream/ is plain 1.4.3; patches/ is gone. vendor.sh and test.sh
apply any patches/ there may be later (nullglob).
- The glue still loads a stored function up to three times, for the
case 1.4.3 still cancels. glue_test.c: new test 20 checks that a
cancel during a function's own load code does not stop it (fails on
1.4.2 with the two patches); the w and h tests now cancel JavaScript
that the load code runs through SQL (they fail with one try).
- README, SqliteJs.cancelAll() javadoc: a cancel interrupts the
connection, so any other statement in progress on it fails too, and
it spares loading stored functions. The README now says the 1.4.2
build passed on the phone and the 1.4.3 build has not run on one yet.
test.sh: upstream's suite 17 of 17; glue test 50 of 50 normally and as
on SQLite 3.40, and the same under ASan, LeakSanitizer and UBSan.
vendor.sh --check passes. NDK 29 builds for both ABIs: no warnings,
the same four exports, version string 1.4.3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* style: spotless rewrap of the cancelAll() javadoc, no functional change
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Answer the independent review of the 1.4.3 move
No correctness defects; two nits:
- F01: two glue-test comments still credited "patch 0002" for what
sqlite-js 1.4.3 now does.
- F02: the v test assumed cancel_calls was still 0; it now resets it,
as the w and h tests do.
Glue test 50 of 50 normally and as on SQLite 3.40.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7082: Record the phone run of the 1.4.3 build
On the Note20, with an AAR built from 0c2e603ee: the trial app passes
7 of 7 as a 64-bit and as a 32-bit process, on a new and an existing
database, and the template (dev-assets #79) stops its runaway query
11 to 12 ms after Cancel in its 64-bit and 32-bit debug builds and its
release build. The README said the 1.4.3 build had not run on a phone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
* ADFA-7135: Correct two README lines the CI and device work made false
"No workflow runs either yet" has been false since the test-sqlite-debugger
workflow: it runs test.sh, the C and JNI tests. The JVM tests are still in
no workflow, which the line now says.
"Nothing has run in an app on a device" has been false since the device
runs recorded on ADFA-7135. What is left is a device run of the current
code, because those results predate the review fixes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7135 Refuse SQL that holds more than one statement
bridge_query prepared with no tail pointer, so SQLite compiled only the first statement: query with "SELECT 1; SELECT 2" ran the first, dropped the second and reported success, and explain_query_plan (which prefixes the client's SQL) did the same. A lone comment returned an empty result, and anything after a NUL character was dropped too, since SQLite reads no further.
prepare_one now prepares the tail as well. Whitespace, comments and semicolons prepare to no statement and are accepted; anything else, including a tail that fails to prepare (the server's authorizer refuses a trailing write at prepare time), fails the call with SQLITE_ERROR, "the SQL holds more than one statement; run one statement per call". SQL with no statement, or with a NUL, fails with its own message. Every tool reaches SQLite through bridge_query, so this covers query and explain_query_plan; the other tools send fixed SQL, and get_stats builds its COUNT(*) from quoted table names, not client input.
Preparing the tail is not running it: the only effects are those a PRAGMA can have at prepare time, under the same authorizer a client already meets by sending that statement alone.
Test (JniQueryTest, the real JNI path on a host JVM, run by test.sh): two statements, a statement after a comment, a trailing DELETE, a trailing syntax error and EXPLAIN QUERY PLAN with a second statement give the more-than-one message; a lone comment, a lone semicolon and a NUL give theirs; trailing semicolons, whitespace, comments, an open comment and a leading comment still run. With the fix reverted the 8 refusal checks fail, each "null vs 1 the SQL holds ...": the call ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7136 Say when a query ran out of time waiting for another tool call
A query's 50 s deadline is set before runChecked waits for the tools' lock, so a call queued behind a slow one could fail with "the time limit passed before the query started" or "the query ran past its time limit", and the agent would read that as its own query being too slow. The deadline still starts before the wait (decided in review, so it bounds the wait for an answer once set); only the error changes. runChecked times its wait for the lock, and when the time ran out (SQLITE_INTERRUPT) after that wait took at least half of what the call had left, the message adds "(this call waited N s of its 50 s for another tool call to finish; tool calls run one at a time, so retry it)".
Not counted: get_stats sets its deadline before its path check, which also takes the lock, so a wait there is not attributed. A tool call's first wait, in the idle check, comes before any deadline is set.
Test (DatabaseToolsTest, fake clock): a second call takes the lock just after the query set its deadline, as a third concurrent call can, and holds it while the fake clock moves. A wait of 50.001 s and of 30 s each get the note; a 10 s wait followed by the query's own timeout does not. Without the fix the first two fail: expected "...started (this call waited 50.001 s of its 50 s ...)" but was "...started", and "the query ran past its time limit" with no note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7136 Start a tool call's time limit when the call begins
The 50 s limit was meant to make the server give up before the client (60 s), so a timed-out call never leaves a query holding the lock after the client has stopped waiting. It did not: every call first waited for the lock in the idle check, and run() set its deadline only after that and the path check, so a call queued behind a slow one could run a full 50 s after the wait.
Each tool call now gets a Call when it begins: its deadline (DEADLINE_MS, unchanged) and the time it has spent waiting for the lock. Every lock taken inside the call (idle check, path check, each query, get_stats included) goes through Call.locked, which adds the wait. The note from ff0bd0c6b now uses that total: when the time runs out after waits of at least half the limit, the error says the call waited N s for another tool call and should be retried.
Test (DatabaseToolsTest, fake clock): a call starts while another holds the lock and waits for it in the idle check. After a 50.001 s wait a query fails with "the time limit passed before the query started (this call waited 50.001 s ...)"; after 30 s a query that then times out gets the note; get_stats after a 50 s wait fails the same way; a 10 s wait gets no note. Against ff0bd0c6b three fail: the 50.001 s query and get_stats succeed (AssertionError: {"isError":false,...}), and the 30 s case reads "the query ran past its time limit" with no note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
* ADFA-7135 Let the query backstop's ROLLBACK past the server's authorizer
After every query bridge_query ran ROLLBACK when the connection was not in autocommit, as a backstop for a transaction left open. On a read-only server connection, the kind every tool uses, the authorizer denies SQLITE_TRANSACTION, and SQLite authorizes ROLLBACK as that action: the ROLLBACK failed with "not authorized", its result was ignored, and the transaction and its lock on the app's database stayed. Nothing a client sends opens one today (BEGIN and SAVEPOINT are refused), so the backstop only mattered for a hole in the authorizer, and there it did nothing.
sqlitedbg_end_transaction (sqlitedbg.h) now does the rollback. It sets a thread-local flag around its own sqlite3_exec("ROLLBACK"), and the authorizer lets SQLITE_TRANSACTION through only when that flag is set and the statement is ROLLBACK. A client's BEGIN, COMMIT, END and ROLLBACK are still refused, also while a transa…
Closes #20. This is the patch that issue offers, rebased on
mainafter 1.4.2, plus a second commit that 1.4.2's result-set lifetime calls for.1. Let the host cancel all running JavaScript.
sqlitejs_cancel_all()stops the JavaScript running in every connection. Each call fails with "interrupted", even code that catches every exception, and JavaScript that begins afterwards runs normally.Android has no other way to stop a runaway function:
How it works:
js_init_tablerun as a call, so a cancel can stop them.2. End a cancelled call's result sets as interrupted, and stop their finals. Since 1.4.2, ending a call's result sets at its return runs the finals of the window or aggregate functions they were computing. Each final entered JavaScript as a new outermost call and took the epoch of that moment, so the cancel no longer reached it. On SQLite 3.41 and later, the interrupt the cancel left stops it; before 3.41 nothing did, and a final that never ends hung the statement.
The finals now keep the call's epoch, and those result sets read on as "interrupted" rather than "closed when the call ... returned":
js_end_rowsets()marks them after its loop, by the pass that ended them, since a final it runs can free result sets of the list; before SQLite 3.41 that is the only way they read so.3. Export
sqlitejs_cancel_allfrom the Windows DLL. The DLL exports only what the generated.deffile lists, so the test program could not link the new function on Windows; the.deflist, the only export list in the project, now includes it.4. Address review (an independent review; no defects found):
js_leaveis upstream's again, since the marking above covers a cancel before the return too; the setup exemption above is stated precisely;end_passis initialised; and the header documentssqlitejs_cancel_all.Tests. Cancel all covers:
Each check fails without its change; the two new ones fail on the first commit alone. The suite passes 17 of 17, also under ASan, LeakSanitizer and UBSan, and this pull request's CI passes on all 14 platforms. Code on the Go's Android library carries these two commits as patches on 1.4.2. A further test there runs the same cases as if on SQLite 3.40.
This pull request originates with AI: it was written by Claude (Anthropic's model) for App Dev For All. The human contact is David Schachter, davidschachter@appdevforall.org.