Skip to content

fix(ui-sdk): a read-only index connection no longer refuses native publication - #4011

Merged
schlessera merged 3 commits into
mainfrom
fix/2878-index-sidecar-publication
Nov 15, 2026
Merged

schlessera merged 3 commits into
mainfrom
fix/2878-index-sidecar-publication

Conversation

@schlessera

Copy link
Copy Markdown
Owner

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_search holding 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 with stale 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. Whenever brain.db or brain.db-wal publishes, 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

  • Not a sidecar exemption that leaves the live -shm in 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 with SQLITE_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 -shm bytes are never read, which removes the -shm variant of the before-copy refusal.
  • -wal stays 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.
  • Only .brain-index/brain.db-shm (from INDEX_DB_PATH), not every *-shm name. Any other file keeps its bytes and its refusal.
  • The ruling is recorded in 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 head a3293ee80e96348623d7ddf307180da015b7faec: path collisions only on docs/decisions/governed-writable-workers.md with #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 real prepareNativeWorkerOutput publisher over copied acquisition metadata, the same boundary as the existing tests in that file. Every SQLite connection is the product's openDatabase running 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.

  • Failing first. Same file with worker-native-output.ts from origin/main: 9 pass, 3 fail. All three reader cases (holds; creates an absent sidecar; holds while the refresh removed its sidecar) fail on READONLY_SEARCH_MUST_NOT_BLOCK_INDEX_REFRESH with error: stale maintenance output: .brain-index/brain.db-shm at publish (worker-native-output.ts:390). The same test also asserts that the real reader changed the live -shm bytes (REAL_READONLY_CONNECTION_CHANGED_LIVE_SHM).
  • After the fix: 14 pass, 0 fail. The refresh publishes while the reader is still open (READONLY_CONNECTION_OVERLAPPED_PUBLICATION), and a new connection reads the refreshed value.
  • Still refused: a concurrent live index writer (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.
  • Mutations, each restored (cmp against the saved fix):
    • M1, never publish the wal-index: NEW_CONNECTION_READS_THE_REFRESH_NOT_THE_OLD_WAL_INDEX received SQLITE_IOERR_SHORT_READ, and the planted-link test fails on OTHER_CONCURRENT_OUTPUT_CHANGE_STILL_REFUSES.
    • M2, wal-index type check blind: planted-link test fails on OTHER_CONCURRENT_OUTPUT_CHANGE_STILL_REFUSES.
    • M3, exempt the whole index family: concurrent index writer test fails on OTHER_CONCURRENT_OUTPUT_CHANGE_STILL_REFUSES.
    • M4, keep an existing live -shm instead of replacing it: SQLITE_IOERR_SHORT_READ.
    • M5, keep the live -shm when the refresh removed its own: SQLITE_IOERR_SHORT_READ in the removed-sidecar variant.
  • Related suites: native-*.test.ts, db-repeat-observation, ui-server native-suite-fixture and maintenance-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.
bun run check:pr --base origin/main
{"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

  • Focused local preflight/behavioral receipts passed; complete selected hosted proof is required by integration.
  • Acceptance criteria from the issue are all met (both bullets); scope gaps are named below.
  • The PR and ui-sdk: native index publication intermittently refuses changed database or sidecar stamps #2878 carry the 0.45.0 milestone.
  • A changeset is included (.changeset/2878-index-wal-index-publication.md, @schlessera/brain-ui-sdk patch).
  • No personal data anywhere in the diff; Odysseus fixture data only.
  • Nothing in the machine surface moved (error strings gain a parenthesised suffix only on the before/during-copy refusals, which are not contract).
  • Docs under docs/ reflect the change (decision record section; moved citations to this file repaired).
  • Proportionate-containment checklist answered below.
  • Provider history: nothing on a turn's provider path changed.

Proportionate containment (changed guard)

  • What triggers it, and what does it not cover? The stale-input refusal still triggers on any change to a published output between snapshot and publication, except the content of .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 unexplained Native output changed before copy: .brain-index/brain.db stage writer (ui-sdk: attribute the native stage writer behind 'Native output changed before copy' on brain.db #4010).
  • What does it restrict, and why is nothing narrower enough? It refuses one refresh, as before. The change narrows the guard: one derived path no longer trips it.
  • What restricted mode was considered? Publishing everything except the -shm, and leaving the live one in place. Rejected: it breaks new readers with SQLITE_IOERR_SHORT_READ (M1/M4).
  • How does it clear? Automatically: the next queued refresh republishes. Nothing latches.
  • Where is the cause recorded? In the refusal message that reaches the server log (governed index refresh failed: …). Before/during-copy refusals now carry both stamps.
  • Which test shows one scope's failure leaves another usable? The refusal tests show that a conflicting writer refuses only that refresh and publishes no index or note bytes, and the live index stays readable.

Anything left open

🤖 Generated with Claude Code

schlessera and others added 2 commits November 15, 2026 13:25
…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>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. labels Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-sdk: native index publication intermittently refuses changed database or sidecar stamps

1 participant