Repository navigation
fix: guard against a second sqlite library opening a shared database - #32398
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The one shared-file open moves to the resolver-bound driver, and the static pin makes the next stdlib open name its database. Notes
[DESIGN-REVIEWED] a22b0c1 Description read[DESCRIPTION-READ] 1993a0fbe26bb80570107cf1db6f70d794210f51c7de9cca7ec1b1c6374f4df1 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The one-line driver swap is the fix for #26091. The new test enforces the Goal's second clause by listing every module, which the existing hand-kept What this change shipsInventory (3 items) — 3 justifiedIntent: stop the gateway crashing with a bus error when a second SQLite library opens a database it already holds, and make the next such open fail a test before it ships. FIX.
[FIRST-PRINCIPLES-REVIEWED] a22b0c1 Description read[DESCRIPTION-READ] 7169e13a8493f132be62e02dc57a6b23b088a4610871fe9b9e657cc0cdbbc87b That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving. On head 62b618e the review checked four things. The new AST scan finds exactly the 10 modules pinned in STDLIB_CONNECT_SITES, both on the head tree and on a merge into current main. Reverting the one-line driver swap in pod/runtime_home.py makes the test fail and name that module. The snapshot keeps its read-only URI, fd pinning, 0600 temp file and except (OSError, sqlite3.Error), and that except now catches the error class of the driver that opens the store. The blocking repo rules for src/ and test/ are not hit. Done well: the auth-store test fixtures also moved to _sqlite_compat. Without that, the test would have held two SQLite libraries in one process, the exact hazard from #26091.
- Optional: the pin compares module paths, so a second stdlib
sqlite3.connectinside a module already on the list still passes. Pinning a count of connect references per module would catch it. Otherwise, say in## Teststhat the check is per module. - Optional:
pod/runtime_home.pynow reads the Kiro CLI sign-in store through the resolver, so it belongs inSHARED_DATABASE_OPENERStoo. - Optional: pod staging runs in the
kirocrew pod _runprocess, not the host gateway, so the runtime swap mainly keeps the package on one driver. The Proof line also names 0955f8731d23, which is not the head. Re-run it on 62b618e.
Where pysqlite3 is installed, the stdlib sqlite3 is a second SQLite library in the gateway. Its open of a database the gateway already holds through _sqlite_compat resets the -shm under that connection, whose next read fails with SIGBUS or "database disk image is malformed". Pod sign-in staging snapshotted kiro-cli's data.sqlite3, which the gateway also reads through _sqlite_compat, with the stdlib driver; it now uses _sqlite_compat too, as does the test that stands in for kiro-cli. A new test lists every module that references the stdlib connect with the database each opens, so the next such open has to say what it opens.
62b618e to
a22b0c1
Compare
…32398) Where pysqlite3 is installed, the stdlib sqlite3 is a second SQLite library in the gateway. Its open of a database the gateway already holds through _sqlite_compat resets the -shm under that connection, whose next read fails with SIGBUS or "database disk image is malformed". Pod sign-in staging snapshotted kiro-cli's data.sqlite3, which the gateway also reads through _sqlite_compat, with the stdlib driver; it now uses _sqlite_compat too, as does the test that stands in for kiro-cli. A new test lists every module that references the stdlib connect with the database each opens, so the next such open has to say what it opens. (cherry picked from commit 666f962)
Problem / Motivation
Goal: No part of Kiro Crew opens a database the gateway already holds through a second SQLite library, and the next stdlib
sqlite3.connectadded to the package has to say which database it opens.Where
pysqlite3is installed, the stdlibsqlite3module is a second copy of SQLite inside the gateway. When it opens a database the gateway already holds through_sqlite_compat, it resets the-shmthat the other connection still maps. That connection's next read then fails withFatal Python error: Bus errorordatabase disk image is malformed, which is what the repro in #26091 shows. #25852 removed one such open (the diagnosis probe onmemory.db), but nothing stops the next one. About 30 modules import the stdlibsqlite3, and nobody had checked which of them open a shared database.Why it matters
A bus error kills the gateway process, and every session it serves drops. Every host with
pysqlite3is exposed: Linux x86_64, where it is a dependency, and any other host where it is installed, such as the reporter's Linux aarch64.Not a goal
-waland-shm(fix(memory): keep the shared -wal when another process closes the memory store #25852, fix(memory): keep the shared -wal on close when the driver has no setconfig #26486), and the page-cache prefetch read (fix: read the page-cache prefetch in a child to keep sqlite locks #26302). All three are already on main.import sqlite3, the other guard shapes the issue thread lists.What changed (motivation → approach → change)
Starting a pod can no longer make the gateway's own read of kiro-cli's sign-in store crash with a bus error, and the next module that opens a database through a second SQLite library fails a test before it ships.
Every stdlib
sqlite3.connectinsrc/kiro_crewwas checked. None opensmemory.dborknowledge.db. One opens a file the gateway also reads through_sqlite_compat: pod sign-in staging snapshots kiro-cli'sdata.sqlite3, whichkiro_cli.pyreads too. The other sites open a database only they use, or run outside the gateway.pod/runtime_home.pysnapshots kiro-cli's store through_sqlite_compattest_every_stdlib_connect_names_the_database_it_openslists every module that references the stdlibsqlite3.connect, with the database each one openssqlite3from_sqlite_compator names its database in the listtest_pod_runtime_auth_store.pywrites its stand-in kiro-cli store through_sqlite_compatThe issue also asks to widen #25852's known-gaps note from Linux x86_64 to every host with
pysqlite3. That note lived in #25852's description, not in the repository. #26486 has since closed the gap it named: the store's close keeps the shared-walfor any driver withoutsetconfig, whatever the architecture.Backwards compatibility
Compatible: on a host without
pysqlite3,_sqlite_compat.sqlite3is the stdlib module, so nothing changes; with it, the snapshot uses the same backup API, the same read-only URI and the same error handling throughpysqlite3.Removes nothing: only the driver of one read-only open changes.
Tests
test/test_sqlite_compat_resolver.py::test_every_stdlib_connect_names_the_database_it_opensparses every module insrc/kiro_crew, finds each reference toconnecton a name bound byimport sqlite3, or to aconnectimported fromsqlite3, soasyncio.to_thread(sqlite3.connect, path)counts too (an import underif TYPE_CHECKING:binds nothing), and asserts the set of modules equals the pinned list. With the pod change reverted it fails and namespod/runtime_home.py.test/test_pod_runtime_auth_store.pyis unchanged apart from the driver its fixtures use.Proof: PROVEN test/test_sqlite_compat_resolver.py::test_every_stdlib_connect_names_the_database_it_opens (head 0955f8731d23)
The related backend set passes locally (180 tests in
test_pod_runtime_auth_store.py,test_pod_runtime_refactor_facade.py,test_runtime_home_write_paths.py,test_snapshot_refactor_ownership.pyandtest_sqlite_compat_resolver.py). The new test andtest_pod_runtime_auth_store.pypassed 20 serial repeats, 10 repeats at-n 4besidetest_pod_runtime_refactor_facade.pyandtest_runtime_home_write_paths.py, and one shuffled order oftest_sqlite_compat_resolver.pywithtest_pod_runtime_auth_store.py(seed 10031). The flake-pattern ratchet and the repository's semgrep rules on the diff pass.Manual verification
N/A: the change is the driver of one read-only snapshot plus a static test. The pod staging tests drive the real snapshot against a live WAL database.
Screenshots / video
N/A: no user-visible frontend surface is touched.
Related Issues
Closes #26091
Sibling sweep
Swept: every reference to the stdlib
sqlite3.connectinsrc/kiro_crew(the AST walk the new test runs)Sibling: src/kiro_crew/pod/runtime_home.py -- changed here
Sibling: src/kiro_crew/acp/codex_sqlite.py -- not affected -- Codex's own state database; nothing in the package opens it through
_sqlite_compatSibling: src/kiro_crew/taskq/store.py -- not affected -- the task queue database, which only the stdlib driver opens
Sibling: src/kiro_crew/onboarding_scan.py -- not affected -- it opens a private snapshot copy, never the source file
Sibling: src/kiro_crew/apps/builtins/auto_research/campaign/storage.py -- not affected -- the app's own database, opened by the stdlib driver only
Sibling: src/kiro_crew/apps/builtins/personal_shopper/backend/store.py -- not affected -- the app's own database, opened by the stdlib driver only
Sibling: src/kiro_crew/apps/builtins/aws_control/crew/runtime/container/supervisor/kiro_login.py -- not affected -- it runs inside the app's container, not in the gateway
Sibling: src/kiro_crew/builtin_skills/security-conductor/scripts/ledger.py -- not affected -- a skill script that runs in its own process
Sibling: src/kiro_crew/builtin_skills/security-conductor/scripts/scope_check.py -- not affected -- a skill script that runs in its own process
Pattern harvest
Rule candidate: lint
Pattern: a stdlib
sqlite3.connecton a database the gateway also opens through_sqlite_compat;test_every_stdlib_connect_names_the_database_it_opensnow enforces it for the whole package.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)