Repository navigation
fix(ui-sdk): a read-only index connection no longer refuses native publication - #4011
Merged
Merged
Conversation
…cation A read-only brain_search connection on the live index writes its read mark into .brain-index/brain.db-shm, or creates it, so native publication's stale-input check saw a changed sidecar and refused the whole refresh. The wal-index is shared memory, not data: it now follows its database, is never compared or copied, and is replaced by a fresh empty inode whenever the database or its WAL publishes, so no new connection pairs the published WAL with a wal-index an earlier reader still holds. Changes to the database, its WAL and every other output still refuse. Before-copy refusals now name the inspected and found stamps. Refs #2878 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #2878 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
schlessera
marked this pull request as ready for review
November 15, 2026 13:50
2 tasks
This was referenced Nov 15, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2878
What changed
Native index publication no longer refuses a refresh because a read-only search connection touched the index's SQLite wal-index. Before, a worker's
brain_searchholding the live index open while a refresh was prepared wrote its read mark into.brain-index/brain.db-shm, or created the file. The stale-input check then failed the whole refresh withstale maintenance output: .brain-index/brain.db-shm, and search kept serving the old index. Now the wal-index follows its database. It is never hashed, compared or copied. Wheneverbrain.dborbrain.db-walpublishes, a fresh empty file replaces it, or it is removed if the refresh removed its own. Publication still refuses a wal-index that is a link or a directory. The database, its WAL and every other output keep the full stale-input refusal. A changed stage file refused before or during its copy now names the inspected and found stamps (Native output changed before copy: <rel> (inspected …, found …)), so a recurrence of the unexplained variant shows what changed.Why this shape
-shmin place. A reader that is still open keeps its wal-index mapped. If the published WAL were paired with that file, a new connection would follow frames the file still describes. The new test shows this fails withSQLITE_IOERR_SHORT_READ(mutations M1/M4/M5 below). So the wal-index needs a fresh inode whenever its family publishes. The first connection to open an inode nobody holds discards its contents and rebuilds them from the WAL, so an empty file loses nothing. This also means the stage's-shmbytes are never read, which removes the-shmvariant of the before-copy refusal.-walstays guarded. Every write to the index changes the database or its WAL. The product opener keeps the WAL persistent (SQLITE_FCNTL_PERSIST_WAL), so readers do not create it in practice. Exempting it would let a concurrent writer through..brain-index/brain.db-shm(fromINDEX_DB_PATH), not every*-shmname. Any other file keeps its bytes and its refusal.docs/decisions/governed-writable-workers.md, "The index's wal-index at native publication — 2026-11-15 (ui-sdk: native index publication intermittently refuses changed database or sidecar stamps #2878)".Proof
Collision check (
bun scripts/collisions.ts --json --paths …) at heada3293ee80e96348623d7ddf307180da015b7faec: path collisions only ondocs/decisions/governed-writable-workers.mdwith #4002, #4007 and #4008, which are separate sections of the decision record. The rest are closure-only: #3054, #3056, #3059, #3069, #3116, #3437, #3581, #3622, #3806, #4006.New tests are in
packages/ui-sdk/tests/native-worker-publication.test.ts. They use the realprepareNativeWorkerOutputpublisher over copied acquisition metadata, the same boundary as the existing tests in that file. Every SQLite connection is the product'sopenDatabaserunning in its own process (packages/ui-sdk/tests/fixtures/index-sqlite-connection.ts), so its locks and shared-memory mapping are a separate connection's.worker-native-output.tsfromorigin/main: 9 pass, 3 fail. All three reader cases (holds; creates an absent sidecar; holds while the refresh removed its sidecar) fail onREADONLY_SEARCH_MUST_NOT_BLOCK_INDEX_REFRESHwitherror: stale maintenance output: .brain-index/brain.db-shmatpublish (worker-native-output.ts:390). The same test also asserts that the real reader changed the live-shmbytes (REAL_READONLY_CONNECTION_CHANGED_LIVE_SHM).READONLY_CONNECTION_OVERLAPPED_PUBLICATION), and a new connection reads the refreshed value.stale maintenance output: .brain-index/brain.db), a concurrent note writer (… notes/odysseus.md) and a link planted over the-shm(… brain.db-shm). Each also asserts that no index or note bytes were published.cmpagainst the saved fix):NEW_CONNECTION_READS_THE_REFRESH_NOT_THE_OLD_WAL_INDEXreceivedSQLITE_IOERR_SHORT_READ, and the planted-link test fails onOTHER_CONCURRENT_OUTPUT_CHANGE_STILL_REFUSES.OTHER_CONCURRENT_OUTPUT_CHANGE_STILL_REFUSES.OTHER_CONCURRENT_OUTPUT_CHANGE_STILL_REFUSES.-shminstead of replacing it:SQLITE_IOERR_SHORT_READ.-shmwhen the refresh removed its own:SQLITE_IOERR_SHORT_READin the removed-sidecar variant.native-*.test.ts,db-repeat-observation, ui-servernative-suite-fixtureandmaintenance-startup-view, with base vs fix source in the same sandbox: identical failing sets (37 sandbox-only bwrap/userns failures) apart from the three new tests, which fail on base and pass here.bun run typecheck: clean.{"version":1,"kind":"brain-check-pr-receipt","head":"a3293ee80e96348623d7ddf307180da015b7faec","base":"origin/main","mode":"focused","startedAt":"2026-11-15T13:27:13.628Z","finishedAt":"2026-11-15T13:28:31.213Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":16865.049786000003},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":164.16141199999402},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":121.58194100000401},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":23.54233799999929},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":60386.622468999994}]}Checklist
.changeset/2878-index-wal-index-publication.md,@schlessera/brain-ui-sdkpatch).docs/reflect the change (decision record section; moved citations to this file repaired).Proportionate containment (changed guard)
.brain-index/brain.db-shm. For that file it triggers only when the file is a link or a directory, in the stage or live. It does not cover copy-staged publication without native storage (ui-sdk: copy-staged maintenance publication refuses a refresh when a reader touches the index wal-index #4009). It also does not cover the unexplainedNative output changed before copy: .brain-index/brain.dbstage writer (ui-sdk: attribute the native stage writer behind 'Native output changed before copy' on brain.db #4010).-shm, and leaving the live one in place. Rejected: it breaks new readers withSQLITE_IOERR_SHORT_READ(M1/M4).governed index refresh failed: …). Before/during-copy refusals now carry both stamps.Anything left open
worker-output.ts) has the same comparison. Its tests need bubblewrap and user namespaces, which this sandbox lacks, so it was not changed unproven here.Native output changed before copy: .brain-index/brain.dbtiming-cell variant, now instrumented with both stamps. This came from the issue's scope list, not its acceptance criteria.bun scripts/prove-native-host.ts --backend=pi --app-uid=1000 --observation-timingverification needs the native manager host. It was not run here, and the squash's main run carries the native categories.🤖 Generated with Claude Code