Skip to content

ADFA-7081: Add sqlite-js, SQL functions written in JavaScript for sqlite3 - #6

Merged
davidschachterADFA merged 17 commits into
feat/ADFA-6635-sqlite-brotlifrom
feat/ADFA-7081-sqlite-js
Nov 16, 2026
Merged

davidschachterADFA merged 17 commits into
feat/ADFA-6635-sqlite-brotlifrom
feat/ADFA-7081-sqlite-js

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-7081 (phase 1 of ADFA-929)

Adds sqlite-js, a SQLite loadable extension for the sqlite3 shell that lets SQL functions be written in JavaScript: scalar functions, aggregates, window functions and collations. It packages sqliteai/sqlite-js (Apache-2.0) release 1.4.2, with no patches, as version 1.4.2-3, with quickjs-ng 0.12.1 (MIT) built in, and installs $PREFIX/lib/sqlite-js.so (.load sqlite-js), a README and its acceptance tests.

Merged into #5's branch; #7 brought it to main. This PR's base was feat/ADFA-6635-sqlite-brotli (#5), which adds the packages/ mechanism this package uses. #5 merged that branch into main at 21:00:07Z on 2026-11-16, and this PR merged into the branch 36 seconds later, so its commits did not reach main here. #7 brought the same head, fbc3be3, to main unchanged; it merged on 2026-11-17 as 96e4b0e. Run 44014027669 then published sqlite-js 1.4.2-3 to production, packages.appdevforall.org, for aarch64 and arm.

What upstream 1.4.2 has from us. The package carries no patches: every change it needed is upstream. Upstream released the first nine below in 1.4.0, and the last four in 1.4.2.

Upstream PR Change
sqliteai/sqlite-js#11 sqlite3_interrupt(), and so Ctrl-C in sqlite3, stops running JavaScript
sqliteai/sqlite-js#12 a 64 MB memory limit per connection, and js_set_memory_limit()
sqliteai/sqlite-js#13 js_eval and the other functions that run code, read files or change the runtime are SQLITE_DIRECTONLY, so a database's views and triggers cannot call them
sqliteai/sqlite-js#14 an ArrayBuffer or typed array result is a BLOB
sqliteai/sqlite-js#15 a whole-number result in the safe-integer range is an INTEGER
sqliteai/sqlite-js#16 an exception in an aggregate step or window inverse function is an SQL error
sqliteai/sqlite-js#17 js_set_max_stack_size() accepts only a size the thread's stack allows (0 still turns the check off), and the 1 MB default shrinks on a thread with less stack
sqliteai/sqlite-js#18 an SQL error while a db.exec statement runs is an exception from next() or toArray()
sqliteai/sqlite-js#19 the stack check follows the thread each call runs on (for apps; sqlite3 has one thread)
sqliteai/sqlite-js#22 the stack check stays within the stack on a thread with less than 64 KB left and on a main thread first measured deep in its stack; the maintainer added measuring the main thread from the kernel's [stack] mapping, and a 1 MB cap with no stack limit
sqliteai/sqlite-js#23 garbage is collected after any "out of memory" error and whenever a limit is set
sqliteai/sqlite-js#24 an interrupt ends the db.exec result sets the interrupted call leaves open
sqliteai/sqlite-js#26 (our report sqliteai/sqlite-js#25) a db.exec result set ends when the call into JavaScript that created it returns, and reading it later throws
  • build.sh exports only the entry points (sqlite-js.map), since SQLite opens extensions with RTLD_GLOBAL and the library would otherwise export QuickJS's symbols and sqlite3_api. It adds sqlite3_sqlitejs_init, the name SQLite derives from the file name, as an alias of upstream's sqlite3_js_init, and fails the build if anything else is exported.
  • It compiles against Termux's SQLite headers: $CPPFLAGS adds them with -isystem, so the copies bundled in libs/ go in with -idirafter, after them.
  • QuickJS's MIT license is only in source comments; termux_step_post_get_source collects its copyright lines and text into LICENSE.quickjs.
  • QuickJS's std and os modules stay registered: JavaScript cannot reach them, because nothing runs the job queue, so import() never completes. A test checks that this stays so.
  • packages.sh adds sqlite-js to COTG_PACKAGES; the README lists it under "Our own packages".

Tested at the head (fbc3be3, 1.4.2-3):

  • On x86_64 Linux with sqlite3 3.46.1, packages/sqlite-js/tests/run-tests.sh runs 104 tests: 103 pass and AC12 is skipped (no sqlite-brotli on the host). With sqlite-brotli, AC12 is two tests, so the phone runs 105. It runs the README's sql examples as written, sends SIGINT to runaway code once it is running, and checks that an interactive session survives Ctrl-C (through script(1)).
  • CI (run 43938979237) built 1.4.2-3 for aarch64 and arm and published it to stage. On a Galaxy Note20 Ultra, upgraded with apt from stage, run-tests.sh passes all 105 on aarch64 and on 32-bit arm. The 50,000,000-row runaway takes 26 s there (5.1 s on the host), so it runs long enough to be stopped.
  • Production debs, checked on 2026-11-21: production's index SHA-256 matches the debs it serves (aarch64 7d98b92af0b4…, arm e6c83e9464eb…). Each deb has the library, the README, LICENSE, LICENSE.quickjs (15 copyright lines) and an executable run-tests.sh. Both libraries export only the two entry points, need only libc, libm and libdl, and contain no com.termux strings; the aarch64 library is 16 KB-aligned.
  • ADFA-7081's Steps to QA, installed from production: every scenario passes on aarch64 and in Code on the Go's 32-bit build, on the Note20. AI agents ran them; no person has run them yet.
  • On a Galaxy J7 (Android 9, 32-bit), production's 1.4.2-3 fails test 58, "AC9: memory held by a global counts until the global is cleared": the 32-bit allocator rounds its 60 MB block up to the whole 64 MB limit. The test is at fault; ADFA-7200: Build sqlite-js 1.4.4, which has upstream #36 #8 holds 48 MB instead.

Review. Daniel-ADFA approved f882b35. The four later commits, c21aeb9 to fbc3be3, change only run-tests.sh, the READMEs and the package revision, and no person has reviewed them.

Follow-up. ADFA-7200 moves the package to sqlite-js 1.4.4 in #8, which is open; 1.4.4 is not in production.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw

davidschachterADFA and others added 5 commits November 10, 2026 21:53
…ite3

sqlite-js packages sqliteai/sqlite-js 1.3.7, a SQLite loadable
extension for scalar, aggregate, window and collation functions written
in JavaScript, with quickjs-ng 0.12.1 built in. It installs
$PREFIX/lib/sqlite-js.so, loaded with `.load sqlite-js`, plus a README
and acceptance tests.

Six patches, each to be sent upstream, fix what 1.3.7 gets wrong:
- 0001: sqlite3_interrupt() (Ctrl-C in sqlite3) stops running
  JavaScript. Before, `while (true) {}` hung the shell.
- 0002: a 64 MB memory limit per connection, and js_set_memory_limit().
  Before, code that kept allocating took all the memory there was.
- 0003: js_eval() and the other functions that run code, read files or
  change the runtime are SQLITE_DIRECTONLY, so a database's views and
  triggers cannot call them even with trusted_schema on.
- 0004: an ArrayBuffer or typed array result is a BLOB. Before, it was
  NULL, so no BLOB could pass through a function.
- 0005: a whole-number result in the safe-integer range is an INTEGER.
  Before, an INTEGER outside the 32-bit range came back as a REAL.
- 0006: an exception in an aggregate step or window inverse function is
  an SQL error. Before, it was ignored and the result silently wrong.
Each adds a test to upstream's test/main.c, which fails without it.

build.sh exports only the entry points (sqlite-js.map), since SQLite
opens extensions with RTLD_GLOBAL, and adds sqlite3_sqlitejs_init, the
name SQLite derives from the file name, as an alias of upstream's
sqlite3_js_init. It compiles against Termux's SQLite headers, putting
the copies bundled in libs/ last with -idirafter, and collects QuickJS's
MIT license, which is only in source comments, into LICENSE.quickjs.

QuickJS's std and os modules stay: JavaScript cannot reach them, since
nothing runs its job queue, so import() never completes. A test checks
that it stays so.

Tests: upstream's test/main.c passes 12 of 12, and its six new tests
fail on 1.3.7. tests/run-tests.sh passes 73 of 73 on x86_64 Linux with
sqlite3 3.46.1, and 25 fail against unpatched 1.3.7; it runs the
README's sql examples as written. The recipe's steps run outside Docker
on the host and with the NDK r29 toolchain at API 24 for aarch64 and
arm: six patches apply, only the two entry points are exported, and the
libraries need only libc, libm and libdl. Termux's linter passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
An independent Claude review of 500e38e found two bugs in the patches,
gaps in the tests, and two older problems. The package goes to 1.3.7-1.

- 0004: a typed array that tracks the length of a resizable buffer kept
  the length QuickJS recorded when it was made. After the buffer shrank,
  returning or binding the array read past the buffer: a 32 MB view of a
  buffer shrunk to 1 byte crashed sqlite3. The offset and length now come
  from the byteOffset and byteLength getters, read before the bytes, and
  are checked against the buffer's size.
- 0002: QuickJS can crash when it runs out of memory while it creates a
  context, which every aggregate does, so with the new limit an
  aggregate run with little memory left crashed sqlite3. Contexts are now
  created with the limit lifted; it applies again to the code that runs
  in them, and is set for the connection once its own context exists.
- 0003: the SQLITE_DIRECTONLY flag is computed from the function's name,
  not from an array that parallels the function list, which a function
  added later would also have to extend.
- run-tests.sh: without sqlite-brotli or script(1), the tests that need
  them are skipped rather than failed, and the summary says so. AC9
  checks each statement's output and bounds the default limit (48 MB
  fits, 70 MB does not); a 32 MB default passed before. AC10 checks the
  SQLITE_DIRECTONLY flag of every function in function_list; a missing
  flag on js_create_* passed before. New: typed arrays over resized
  buffers (AC6) and aggregates near the memory limit (AC9).
- README: a collation that throws or runs out of memory compares as
  equal, so ORDER BY gives a wrong order without an error, as upstream
  intends.

Not changed: QuickJS records the stack top of the thread that loads the
extension, so JavaScript run on that connection from another thread
fails with "Maximum call stack size exceeded". The sqlite3 shell has one
thread; this matters for apps (ADFA-7082).

Tests: upstream's test/main.c passes 12 of 12, also under ASan and UBSan
with leak checking, and its new checks fail against the previous
patches. run-tests.sh passes 77 of 77 on x86_64 Linux, also with the
extension under ASan and UBSan; against the 1.3.7 build, the two new
tests fail; without sqlite-brotli, 76 pass and 1 is skipped. The NDK
builds for aarch64 and arm export only the entry points, and Termux's
linter passes.

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

Patch 0007: js_set_max_stack_size() passed its argument to QuickJS
unchecked, so text (read as 0, which turns the check off) or a size
larger than the thread's stack made endless recursion crash sqlite3,
and the 1 MB default did the same on a thread with less stack. It now
measures the calling thread's stack, keeps a 256 KB margin, refuses
text, negatives and sizes beyond what the stack allows (the error names
the largest size), and lowers the default when the loading thread has
less. 0 still turns the check off, as upstream documents for use from
several threads.

run-tests.sh: AC13 checks the error cases, endless recursion at the
default, just below the largest size (also through db.exec) and with a
512 KB stack. README lists the seventh patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Patch 0008 (F20): db.exec's result set treated any sqlite3_step()
result but SQLITE_ROW as the end of the rows, so an error while the
statement ran was dropped: next() returned false and toArray() the rows
before the error, and a failed write looked like success. Both now
throw the connection's error message; the end of the rows is still
false. The README documents db.exec, including that a statement runs
only when next() or toArray() steps it (F21).

Patch 0007: its SQL-recursion test catches the deeper call's error
itself, so it passes with or without 0008 (only the test changed).

run-tests.sh: new AC14 for the error cases; AC13's recursion through
db.exec likewise. 91 tests.

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

The interactive Ctrl-C test ran js_eval('while (true) {}') under
timeout 30 script(1). Against a build where Ctrl-C does not stop
JavaScript, such as unpatched 1.3.7, timeout stopped script but not the
sqlite3 it ran, which kept a CPU core busy until killed; three were found
after 17 hours on a development machine.

Each runaway loop in the AC8 tests now gives up after 20 s, and the
interactive test must finish within 15 s, since the shell also reports
"interrupted" when a loop ends by itself. The AC9 allocation loops stop
at about 4 times the 64 MB default, so a build without the limit fails
the test instead of exhausting the device's memory. timeout also kills
script if it ignores SIGTERM.

Tested on x86_64 Linux: the 1.3.7-3 build passes 91 of 91. Unpatched
1.3.7 fails 39, including the four Ctrl-C tests and the allocation-loop
test, and leaves no process or test directory behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
@davidschachterADFA
davidschachterADFA marked this pull request as ready for review November 12, 2026 01:46

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated independent review by Claude Code (AI), not a human review. It had none of the authoring session's reasoning, only the code and this PR's description.

Verdict: the default rule gives REQUEST_CHANGES (two confirmed IMPORTANT findings). This review is submitted as COMMENT because GitHub refuses approve and request-changes from the PR's own author account. terminal-packages has no CLAUDE.md, REVIEW.md, CONTRIBUTING.md or PR template, so the review skill's default approve/request-changes rule applied.

Stack: this PR is the top of two layers: main <- #5 (feat/ADFA-6635-sqlite-brotli) <- #6. Only #6's own diff was reviewed. Its head, 6a10187, is also the stack tip, and every claim was checked there.

IMPORTANT

  • packages/sqlite-js/0002-Limit-the-memory-of-the-JavaScript-runtime.patch:95 - above ~2/3 of the memory limit, garbage is not collected before the limit is hit
  • packages/sqlite-js/0004-Return-ArrayBuffers-and-typed-arrays-as-BLOBs.patch:140 - db.exec silently binds NULL for a detached or out-of-bounds buffer

MINOR

  • packages/sqlite-js/README.md:164 - running out of memory through small allocations reports "Unknown JavaScript exception"
  • packages/sqlite-js/README.md:116 - TEMP views and triggers can call the js_* functions

How it was checked. The upstream 1.3.7 tarball's sha256 matches build.sh, and all eight patches apply with git am. The extension was built with gcc on x86_64 and run in a SQLite 3.46.1 shell.

  • Upstream test/main.c: 14 of 14 pass, also under ASan and UBSan with leak checking.
  • run-tests.sh: 90 of 90 pass with 1 skip (sqlite-brotli not installed), also with the extension built with ASan and UBSan.
  • Extra runs under ASan, with no crash and no sanitizer report: aggregates under memory limits from 60 KB to 600 KB in 4 KB steps; js_eval and db.exec under limits from 200 KB to 700 KB; typed-array getters that resize or detach their buffer during conversion.
  • Every finding was reproduced with the build without sanitizers.

Earlier round. The PR has no earlier review comments. The two bugs that the PR description says the review of 500e38e found are fixed at head: a typed array over a shrunken resizable buffer is bounds-checked (AC6 and the getter tests above), and aggregates near the memory limit no longer crash (the limit sweep above).

Checked and not raised:

  • js_set_max_stack_size measures from the calling frame, while QuickJS applies the size from the stack top it recorded at load. In the shell the two are under 200 bytes apart (measured), and the PR already discloses the case of several threads.
  • -0 comes back as INTEGER 0. That matches the documented safe-integer rule (Number.isSafeInteger(-0) is true).
  • A byteLength overridden on the instance changes the BLOB, but the result stays inside the buffer's bounds.
  • The 1 s sleep before SIGINT in expect_sigint_stops could race on a very slow device; this was not reproduced.
  • run-tests.sh repeats the TAP helpers of sqlite-brotli's tests. That keeps each package's tests self-contained.

Comment thread packages/sqlite-js/README.md Resolved
Comment thread packages/sqlite-js/README.md Resolved
davidschachterADFA and others added 2 commits November 11, 2026 18:36
From the independent review of PR #6:
- 0002: QuickJS sets its garbage-collection threshold to 1.5 times the
  memory in use. Past two thirds of the limit, that is beyond the limit,
  so garbage filled it and code that fits failed. The threshold is now
  kept between the memory in use and the limit.
- 0002: running out of memory through small allocations leaves no room
  for QuickJS's error, so QuickJS throws null. That now reports "out of
  memory" instead of "Unknown JavaScript exception".
- 0004: db.exec throws for a buffer it cannot read (detached, or a
  typed array out of its buffer's bounds) instead of binding NULL.
- 0004, from CodeRabbit on CodeOnTheGo #2244: a typed array's offset and
  length are read through getters taken when the runtime is made, so
  properties a script defines over them cannot change which bytes are
  read.
- 0003 and the README: TEMP views and triggers can call the js_*
  functions, since SQLite trusts the TEMP schema.

Patches 0001-0008 are regenerated from the work repo. Only 0002, 0003
and 0004 change in substance. The others change in their headers, hunk
line numbers and index lines.

run-tests.sh adds six checks, for 97 in all:
- garbage is collected with 48 of 64 MB held;
- an aggregate over 300 groups runs with 48 of 64 MB held;
- small allocations run out with "out of memory";
- db.exec throws for buffers it cannot bind;
- shadowed typed-array properties are ignored;
- a TEMP view can call js_eval.

On a host build, 97 of 97 pass, and 1.3.7-4 fails the five that test
the fixes. Upstream test/main.c passes 14 of 14 under ASan and UBSan
with leak checking, and each new test there fails without its fix.

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

Upstream merged our eight patches (sqliteai/sqlite-js #11 to #18) and #19
on 2026-11-12, with fixes of its own. One fixes a bug in our 0002, which
1.3.7-5 has: a memory limit lowered under memory that is garbage left the
session out of memory until the limit was raised again (ef06558).

Build from upstream main at c8ae85a, with no patches. The version follows
termux-packages' convention for a commit after a release, and dpkg sorts
1.3.7-p20261112 above 1.3.7-5. The README now lists the upstream PRs
instead of patches and says what a lowered limit does.

run-tests.sh gets a test for that bug: 98 of 98 pass on a host build of
this package, and on 1.3.7-5 only the new test fails. The aarch64 and arm
builds (emulated build.sh steps, NDK 29) export only the two entry points.
ADFA-7083's page examples pass, 64 of 64.

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

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review of commit 428a196 (sqlite-js 1.3.7-p20261112, upstream main at c8ae85a with no patches), anchored at the PR head 428a196. This PR is the top of a two-PR stack (#5, sqlite-brotli, sits below it on main), so the head is also the stack tip that the claims were checked against.

IMPORTANT

  • README.md:170-171 - cyclic garbage is not collected after a refused allocation, so a buffer that fits keeps failing

MINOR

  • README.md:109 - "0 ... for use from several threads" is out of date since upstream PR 19
  • README.md:172 - garbage is collected as the limit changes only within 64 KB of the memory in use
  • build.sh:6-8 - upstream 1.4.0 and 1.4.1 now include all nine changes; js_version() says 1.3.7

Checked, no comment needed:

  • Archive: the commit archive's SHA-256 is 4f4ebb7e...5561 as in build.sh, and its tree is identical to git archive c8ae85a. 1.3.7 plus patches 0001-0008 differs from c8ae85a only in README.md, src/sqlitejs.c and test/main.c.
  • Version: Termux builds 1.3.7-p20261112-0 (the CI debs say so). dpkg --compare-versions puts it above 1.3.7-5, it is valid, and it passes the linter's increase and revision-reset rules. termux-packages recipes use the same -p${_COMMIT_DATE} form.
  • run-tests.sh against host builds made with build.sh's compile line and sqlite3 3.46.1: c8ae85a passes 97 of 97 (1 skipped, no sqlite-brotli here). 1.3.7-5 fails only the new test, at js_eval('1 + 1'), with "out of memory". The new test is not vacuous: 1.3.7-5 passes it with up to 30,000 objects and fails from 40,000, so 200,000 leaves about a 5x margin on x86_64.
  • Upstream's test/main.c at c8ae85a passes on host, including "Stack on other threads".
  • README against c8ae85a: the 64 MB default, SQLITE_DIRECTONLY on all but js_version, quickjs-ng 0.12.1, the nine upstream PR numbers and titles (all merged), c8ae85a being an ancestor of upstream main, and "a limit under the memory that globals hold leaves no room for any JavaScript until it is raised again" (reproduced with 8 MB held and a 4 MB limit).
  • CI run 43183024875 built 428a196. Both debs are 1.3.7-p20261112-0, export only the two entry points, need only libc, libm and libdl, and carry this commit's README and run-tests.sh (only the shebang is rewritten). Nothing was run on a device.

Earlier findings, re-checked at c8ae85a now that the patches are gone:

  • GC threshold past two thirds of the limit: still fixed. js_keep_gc_below_limit is upstream, and AC9's 48-of-64 MB tests pass.
  • js_bind_value dropping the exception: still fixed. db.exec throws "ArrayBuffer is detached or resized" for the resized view and "ArrayBuffer is detached" after transfer(), and inserts nothing.
  • TEMP views: still fixed. The README says so, and AC10's TEMP view test passes.
  • "Unknown JavaScript exception" from small allocations: still fixed. AC9's small-allocation test passes.

Verdict: this repo has no written review rule, so the default applies, under which the IMPORTANT finding means request changes. GitHub does not let an author request changes on their own PR, and this account opened it, so the review is submitted as COMMENT.

Comment thread packages/sqlite-js/README.md Resolved
Comment thread packages/sqlite-js/README.md Resolved
Comment thread packages/sqlite-js/README.md Resolved
Comment thread packages/sqlite-js/build.sh Resolved
davidschachterADFA and others added 6 commits November 12, 2026 15:52
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. build.sh takes
the 1.4.1 tag again, as its comment asked (independent review).

Two patches, offered upstream as sqliteai/sqlite-js #22 and #23:
- 0001 keeps the stack check within the stack where endless recursion
  crashed: a thread with less than 64 KB of stack left, and a main
  thread first measured deep in its stack (CodeRabbit, on the AAR's copy
  in CodeOnTheGo #2244). Neither can happen in sqlite3; the README's
  stack claim now holds everywhere.
- 0002 collects garbage after any "out of memory" error and whenever a
  limit is set. With 40 MB of cyclic garbage under the 64 MB default, a
  30 MB ArrayBuffer failed on every try. After a limit lowered to 32 MB,
  above the garbage, a 16 MB one failed (independent review, both).

The README describes both. Its js_set_max_stack_size row no longer
suggests 0 for several threads, which upstream's #19 made unneeded
(independent review). run-tests.sh gets an AC9 test for each garbage
case, and AC2 expects 1.4.1.

On a host build of this package, run-tests.sh passes 99 of 99, with
AC12 skipped because sqlite-brotli is not installed. On 1.4.1 without
the patches, only the two new tests fail. Upstream's suite with the
patches passes 15 of 15, also under ASan and UBSan. The aarch64 and arm
builds (NDK 29, build.sh's compile line) have no warnings in sqlitejs.c,
and export only the two entry points.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
SQLite keeps an interrupt in effect until no statement of the connection
is running, and a db.exec result set that JavaScript keeps open is a
running statement. In 1.4.1, Ctrl-C during code that keeps one, in a
global say, left every later statement in the sqlite3 session failing
with "interrupted" until it was restarted. CodeRabbit found it on the
AAR's copy (CodeOnTheGo #2244).

Patches 0003 and 0004, offered upstream as sqliteai/sqlite-js #24: when
the outermost call into JavaScript returns on an interrupted connection,
the result sets still open are finalized, and reading on from a kept one
fails with "interrupted". 0004 makes that safe when finalizing runs a
JavaScript window or aggregate function's final. The README says so.

run-tests.sh's interactive Ctrl-C test is now a function, and a second
case keeps a result set open: Ctrl-C, then SELECT 'still' || ' alive'.
On a host build of this package, run-tests.sh passes 100 of 100, with
AC12 skipped (no sqlite-brotli). With only patches 0001 and 0002, only
the new test fails. Upstream's suite with the four patches passes 15 of
15, also under ASan and UBSan. The aarch64 and arm builds (NDK 29,
build.sh's compile line) have no warnings in sqlitejs.c and export only
the two entry points.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
An interrupt ends every db.exec result set still open in the session,
not only the stopped code's (independent review of the AAR's copy,
CodeOnTheGo #2244). And Ctrl-C while no JavaScript runs, during plain
SQL, leaves the session failing every statement while JavaScript keeps a
result set open, since no JavaScript runs to end it: reproduced on
SQLite 3.49, where SELECT 1 + 2 and js_eval() then fail with
"interrupted". The README says so, and to finish result sets before the
code returns. README only: the stage packages of 1.4.1 (CI run
43355418863) have the earlier wording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
Upstream merged sqliteai/sqlite-js #22, #23 and #24 and released them
in 1.4.2; the four patches have the same patch ids as upstream commits
ac17d4f, 7776629, 28fa507 and 347ee9d, so they are dropped. The
maintainer added two commits to #22: the main thread's stack is
measured from the kernel's [stack] mapping, and with no stack limit
(ulimit -s unlimited) js_set_max_stack_size allows at most 1 MB.

1.4.2 also has upstream's fix for our report #25 (#26): a db.exec
result set ends when the call into JavaScript that created it returns,
and reading it later throws "The result set was closed when the call
into JavaScript that created it returned". So a result set kept in a
global no longer keeps a statement open, and Ctrl-C during plain SQL no
longer leaves the session failing every statement.

run-tests.sh: AC2 expects 1.4.2; two new tests, one for each behaviour
above. On the host (sqlite3 3.46.1) plain 1.4.2 passes 102 of 102; the
1.4.1 build with the old patches fails both new tests for the reasons
they name. README: the release, the result-set rule, the stack limit,
1.4.2's changes, and no patches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
From the independent review of 86b48e5 (nothing blocking; three low
findings, three nits), and the review of the ADFA-7083 pages:
- README: a result set made in a call that SQL in another call's
  db.exec ran lasts until the outer call returns. Read later, it throws
  "interrupted" if Ctrl-C stopped its call, and one whose next()
  returned false or whose toArray() ran just reports no more rows (F01).
  #24's row again says reading on fails with "interrupted".
- README: four tests need other packages, not two (F02); #22's row
  names both of upstream's additions (F04); a long line rewrapped (F05).
- run-tests.sh: AC13 checks that with no stack limit sizes above 1 MB
  are refused, as the README says, and skips where `ulimit -s
  unlimited` is not allowed (F03).

Corrections to 86b48e5's message (F06): the maintainer's two commits on
#22 are bd3d6c4, which skips upstream's 64 KB-thread test where the
platform has no stack that small, and 31ed714, which has both changes
named there; and of its "102 of 102", one test (AC12) was skipped.

On the host (sqlite3 3.46.1, no sqlite-brotli): 1.4.2 passes 103 of 103
with AC12 skipped; the 1.4.1 build fails the new AC13 test, AC2 and the
two tests 86b48e5 added, each for the reason it names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
70f2643 changed run-tests.sh and the README, which the package installs,
but not the version, so apt on a phone with 1.4.2 would keep the old
files. Revision 1 makes it 1.4.2-1, which dpkg sorts above 1.4.2.

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

@Daniel-ADFA Daniel-ADFA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of f882b35 (sqlite-js 1.4.2-1). This PR is the top of a two-PR stack on #5 (sqlite-brotli), so its head is also the stack tip the claims were checked against. Upstream code was read from the 1.4.2 tag archive, whose SHA-256 matches build.sh. Nothing was built or run. The repo has no written approve/request-changes rule, so the default applied: MINOR findings only, so this is a comment, not a block.

MINOR

  • packages/sqlite-js/tests/run-tests.sh:496 - plain-SQL runaway has no 20 s cap
  • packages/sqlite-js/tests/run-tests.sh:201 - SIGINT after a fixed sleep can be lost
  • packages/sqlite-js/tests/run-tests.sh:334 - "stores the new code" is not checked
  • packages/sqlite-js/README.md:180 - "sqlite3 keeps running" holds only interactively
  • README.md:31 - "with our patches", but there are none
  • PR description - still says the package builds 1.4.1 with patches (below)

NITPICK - 1 inline, not listed

Findings without a diff anchor

MINOR: The PR description contradicts what the PR ships. The first paragraph says 1.4.2 with no patches; the third says "The package builds 1.4.1 with four new patches", and the first Tested list says "all six patches apply". QA reading from the top meets the history before the result. Keep the top describing f882b35 only, and move the per-commit history under a heading of its own.

Earlier rounds, re-checked at f882b35

The eight earlier threads are resolved. The two on patch files now describe upstream code, since the PR carries no patches; I read it but did not re-derive its arithmetic or run it.

  • 0002, GC threshold past two thirds of the limit: upstream keeps it below the limit (js_keep_gc_below_limit, src/sqlitejs.c:305).
  • 0004, db.exec binding NULL for an unreadable buffer: upstream's js_bind_value returns an error (src/sqlitejs.c:817, 887).
  • README, TEMP views and triggers: fixed, README lines 124-126, tested by AC10.
  • README, "out of memory" message: upstream's default error is "out of memory" (src/sqlitejs.c:1048), matching README line 173.
  • README, cyclic garbage after an out-of-memory error: upstream collects then (src/sqlitejs.c:1066-1070), matching README line 175.
  • README, stack size 0: fixed, README line 115.
  • README, lowering the limit collects: js_set_memory_limit collects when the limit is above 0, matching README line 177.
  • build.sh version: now the 1.4.2 tag.

Comment thread README.md Resolved
Comment thread packages/sqlite-js/README.md Resolved
Comment thread packages/sqlite-js/tests/run-tests.sh Resolved
Comment thread packages/sqlite-js/tests/run-tests.sh Resolved
Comment thread packages/sqlite-js/tests/run-tests.sh Resolved
Comment thread packages/sqlite-js/tests/run-tests.sh Resolved
davidschachterADFA and others added 2 commits November 16, 2026 02:54
From review 5918442139 of f882b35 (MINOR and NITPICK only):
- Ctrl-C tests: expect_sigint_stops slept 1 s and
  expect_ctrl_c_keeps_session 2 s before the signal, so on a slow start
  it could arrive before the runaway statement ran and be lost. Each
  runaway statement now creates the file "started" as it begins
  (WHERE writefile('started', '') IS NOT NULL), and the helpers wait
  for it, up to 10 s. The file is made inside the statement because
  SQLite drops an interrupt that arrives between statements.
- The plain-SQL runaway counted to 2,000,000,000, minutes past the
  20 s cap the other runaways keep; it counts to 200,000,000 (about
  18 s on the host).
- AC4 "stores the new code" checked only the session that redefined
  the function. A new test loads js_functions in a fresh session
  (js_init_table(1)) and expects the new code's result.
- README: sqlite3 keeps running after Ctrl-C only in an interactive
  session; from a file or arguments it exits. The repository README no
  longer says the package has patches.
- AC10: the view block's comment says what it checks.

Host (sqlite3 3.46.1): 104 tests, all pass but AC12, skipped (no
sqlite-brotli); 103 before. The SIGINT tests now take 0.2 s, not 1.2. With a sqlite3 wrapper that starts 4 s late, all six AC8
tests failed before and pass now. Against a js_functions row that kept
the old code, the new AC4 test fails (42, not 63).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
The package installs run-tests.sh and the README, which the previous
commit changed, so the revision goes up for apt to install them.

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

Copy link
Copy Markdown
Contributor Author

On the PR-description finding in review 5918442139: the description now opens with what the head (39a35c7, 1.4.2-2) ships and how it was tested, with upstream PR numbers instead of patch numbers, and the per-version history is under its own heading.

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated independent review by Claude Code (AI), not a human review. It had none of the authoring session's reasoning, only the code, this PR's description and the earlier review comments.
Scope: c21aeb9 and 39a35c7 (sqlite-js 1.4.2-2), the answers to the review of f882b35.

CRITICAL: none.
IMPORTANT: none.

MINOR: none.

NITPICK:

  • packages/sqlite-js/tests/run-tests.sh:207 and :485: when started never appears within 10 s the poll loop falls through silently and SIGINT/Ctrl-C is sent anyway, so the failure reads "still running 5 s after SIGINT" or "took N s", which points at the build, not at a statement that never started (for example writefile missing from the shell). Not reproduced; reasoned from the code.
  • packages/sqlite-js/tests/run-tests.sh:513: 200,000,000 rows take about 21 s on this host (x86_64, sqlite3 3.46.1, measured). On a phone several times slower, a lost Ctrl-C leaves this sqlite3 busy for minutes, unlike the 20 s cap on every other runaway. Much better than 2,000,000,000 and it meets the earlier comment's "roughly 20 s on a fast host"; phone time not measured.
  • PR description: "passes all 104 tests but AC12, which is skipped" is off by one. The host run prints 1..104 and "passed all 104, but skipped 1", so 103 ran and passed and AC12 is the 104th, skipped. The 105 on the phone is consistent with AC12 running there as two tests.

Checked, no comment needed:

  • Sibling sites for the Ctrl-C race: grep shows exactly two senders of an interrupt, kill -INT in expect_sigint_stops and printf '\003' in expect_ctrl_c_keeps_session. Both now wait for started. All six runaway statements (3 batch, 3 interactive) carry WHERE $STARTED or the writefile in the CTE seed. The remaining fixed sleep 1 calls (before the SQL, after Ctrl-C, before .quit) only delay input that the tty buffers, so they cannot race.
  • Ordering of writefile before the runaway: run on the host, with SELECT js_eval(...) WHERE writefile('started','') IS NOT NULL. writefile is not deterministic, so it is not folded away. It returns 1 for an empty file (the IS NOT NULL is true). The file exists once the statement is running, so SQLite cannot drop the interrupt as it does for a statement not yet started.
  • Race stress: 60 runs on the host that send SIGINT in a busy loop the instant started appears, with no sleep; all 60 exited within 2 s with "interrupted".
  • Slow start: the full suite with SQLITE3 set to a wrapper that sleeps 2 s before exec'ing sqlite3 (every sqlite3 start delayed): 104 of 104, AC8 included (each batch test 2.1 s, interactive 4.3 s). Not run against 1.4.2-1's tests, so "the old test failed here" is unverified.
  • Stale started: both helpers rm -f started before starting, in the same directory ($WORK, the cwd that sqlite3 and script -c inherit, so the relative path matches the poll). The directory is removed by the EXIT trap. After the run git status was clean, no /tmp/sqlite-js-tests.* directory and no sqlite3 process remained.
  • Portability: sleep 0.1 (coreutils on Termux), [[ -e ]], C-style for and timeout -k are the same constructs the file already used. writefile is built into the sqlite3 shell (the shell source includes fileio); Termux's libsqlite recipe (termux-packages/packages/libsqlite/build.sh) builds the stock shell and sets no OMIT flag for it. Per the PR description 1.4.2-2 passed 105 of 105 on the Note20, aarch64 and arm; I did not see that run (unverified).
  • Test names: "AC4: ... and stores the new code, which the next new session loads" now checks js_init_table(1) then twice(21) = 63 in a fresh session, which would give 42 if the REPLACE had not been stored. "AC8: ... Ctrl-C stops plain SQL" and the others say what they check. I did not mutate the extension to watch AC4 fail (unverified).
  • README line 180-182 now says interactive keeps running, batch exits, which matches the helper's own comment and the tests. The README's "Four tests ... skipped: one sqlite-brotli, three util-linux" matches the code (one AC12 test, three expect_ctrl_c_keeps_session). The TEMP/trusted_schema comment (lines 648-650) is accurate: the view test below it expects "unsafe use of twice".
  • Top-level README row says 1.4.2 which includes our changes; build.sh and the package README say "no patches", consistent. No other "with our patches" text was found with grep.
  • Revision bump: TERMUX_PKG_REVISION=2 with TERMUX_PKG_VERSION=1.4.2 gives 1.4.2-2, the Termux convention when only packaged files change; run-tests.sh and README are installed files, and the repo README says to raise the version or revision so a build or publish is not skipped. build.sh's other fields are unchanged and no other file in the repo mentions 1.4.2-1.
  • Whole suite on the host: SQLITE3=/usr/bin/sqlite3 with the host142 sqlite-js.so: 1..104, passed all 104 (103 ran, AC12 skipped), 12 s elapsed.

Earlier review comments, at 39a35c7:

  1. README.md:31 "with our patches": fixed. The row now reads "1.4.2, which includes our changes".
  2. packages/sqlite-js/README.md:180 "sqlite3 keeps running": fixed. It now says interactive sessions keep running and a file or arguments exit.
  3. run-tests.sh fixed one-second sleep: fixed in both helpers (expect_sigint_stops and expect_ctrl_c_keeps_session) by polling for started written by the statement; proven by the stress and slow-start runs above.
  4. run-tests.sh "stores the new code" test: fixed. Split into "can redefine it" and a fresh-session check that reads back 63 after js_init_table(1).
  5. run-tests.sh uncapped 2,000,000,000 runaway: fixed in substance; now 200,000,000 (about 21 s on this host), see the nitpick.
  6. run-tests.sh duplicated TEMP-schema comment: fixed. The comment now describes the trusted_schema check.

Verdict: approve (no CRITICAL or IMPORTANT findings). This review is submitted as COMMENT because GitHub refuses approve and request-changes from the PR author's own account.

Comment thread packages/sqlite-js/tests/run-tests.sh Resolved
Comment thread packages/sqlite-js/tests/run-tests.sh Resolved
davidschachterADFA and others added 2 commits November 16, 2026 11:24
- A runaway statement that has not started within 10 s now fails its
  AC8 test as such ("the statement did not start within 10 s"), in
  both helpers, instead of sending Ctrl-C anyway and blaming the build.
  The batch helper also stops waiting once sqlite3 has exited. With a
  sqlite3 that starts 12 s late, all six AC8 tests report that; the
  old tests reported "still running 5 s after SIGINT" or "took 13 s".
- The plain-SQL runaway counts to 50,000,000, not 200,000,000: about
  5 s on an x86_64 host (measured), so a lost Ctrl-C leaves sqlite3
  busy for about as long as the other runaways' 20 s cap on a phone.

Host: passed all 104, AC12 skipped (no sqlite-brotli).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
The package installs run-tests.sh, so the test changes need a new
revision for the publish to pick them up. The library is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAXGyHbMzjSsi2zbrkw
@davidschachterADFA
davidschachterADFA merged commit be0a7a7 into feat/ADFA-6635-sqlite-brotli Nov 16, 2026
davidschachterADFA added a commit that referenced this pull request Nov 17, 2026
ADFA-7081: Bring sqlite-js to main (#6 merged into #5's branch after #5 merged)

What the above gibberish says is that someone (I wonder who? Stop looking at me!) merged 6 into 5 AFTER 5 had already merged to main. You can drag a dead horse to water but he's not going to drink and likewise, 6 isn't going anywhere because it's been merged to a branch that was already dead, having been merged into main.

7 is 6 with some minor changes. 6 already had Daniel's approval, so I'm merging 7 to get 6's work into main.

If you understand this, give yourself a gold star.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants