Repository navigation
Description
Context
During the native hosted proof's --observation-timing measurement (#2834) on main at 650caaf (pi, governed, UID 1000, 2,000 notes), the automatic index refresh queued after the timing turns failed, and the proof's final drain stopped on it:
NATIVE_AUTOMATIC_INDEX_COMPLETED: Error: stale maintenance output: .brain-index/brain.db-shm
Maintenance publication compares each output path's live entry with the one its worker started from and refuses a change (if (!equal(previous, live.entry, packages/ui-sdk/src/server/worker-native-output.ts:383). Those turns ran brain_search in governed pi workers, which open the live index read-only (function openRead, packages/ui-backend-pi/src/brain-access.ts:185-191). A read-only SQLite connection to a WAL database can still create or rewrite brain.db-shm, so a reader can change an index sidecar while maintenance prepares its output, and publication then refuses the whole refresh. This is a plausible cause, not an attributed one.
The default proof does not hit it; the timing mode runs 20 brain_search calls in quick succession while refreshes are queued.
Later recurrence (2026-10-25)
The #2853 native pi apply-timing cell (UID 1000, 2,000 notes) failed index publication in two of seven runs: one Native output changed before copy: .brain-index/brain.db-shm at automatic refresh drain, and one on .brain-index/brain.db at the same-turn search barrier (IndexFlushError, APPLY_TIMING_SEARCH_WAITED_FOR_INDEX). Every host apply succeeded. These are output-copy stamp failures, distinct from the original stale-input comparison; no common writer is attributed. Capture both input-versus-live and native-output-before-copy identities before choosing a fix. A sidecar-only exemption cannot be inferred to repair the database-file occurrence.
Scope
- Attribute each refusal boundary: record which writer changed the input/live or native output entry, including both
brain.db-shmandbrain.db, between snapshot/copy/publication. - If it is a reader's shared-memory sidecar, decide how publication treats the index family's
-shm(and-wal) so a concurrent reader cannot fail the refresh, without letting any other concurrent writer through.
Out of scope
- The journal's handling of index versions (ui-server: the turn journal retains a whole new index version after every automatic refresh, adding seconds to journal finish #2873).
- Changing how workers search the index.
Acceptance criteria
- A test with a real concurrent read-only connection reproduces the refusal on the current code, or the receipt names the actual writer.
- After the fix, that test publishes the refresh, and a test that changes any other output path between input and publication still refuses with
stale maintenance output.
Verification
bun run test packages/ui-sdk packages/ui-server and bun scripts/prove-native-host.ts --backend=pi --app-uid=1000 --observation-timing.
Contract impact
None expected.
Found while measuring #2834.
2026-10-25 triage at main 827861e1fa71cd4a26b52f1ef0f96b849381acdf: Folded both later native-output-copy recurrence variants into the current reproduction brief. Preserve needs: repro: the reader-sidecar theory is unproven and does not explain the database-file variant.
2026-10-26 triage at main c670449d3bf1b0639e50ce554d728961f4313add: verified the current cited code and corrected literal source anchors/start lines. This navigation correction preserves historical receipts, decisions, scope, classification and unresolved prerequisites; no new runtime result or readiness is inferred.
Later matched base/head observation-timing recurrence — 2026-10-26
Reporter evidence from the retained recurrence:
2026-10-26 recurrence while validating #3001. The same pi UID 1000 --observation-timing cell, without fsync load, failed its final automatic-index drain on both trees:
- Base
c47483196f02c1098128207ce68c4f0de6b571ab, before the inbox migration: exit 1 after 114.2 seconds. - Inbox branch
b9b7d099ba362838f22407902c9d3a4b9fc70cc6: exit 1 after 118.6 seconds.
Both report exactly:
NATIVE_AUTOMATIC_INDEX_COMPLETED: Error: stale maintenance output: .brain-index/brain.db-shm
The branch's observation artifact contains all 220 calls across 11 tool cases, with zero tool errors; the error comes later at queued refresh drain. Its default four-cell hosted matrices pass both without load and under three fsync writers, including the expected retained-index negative control and owned cleanup. The timing wrappers correctly await the now-asynchronous host bridge.
This confirms the existing failure on the base as well as the branch; it does not attribute which writer changed the sidecar or settle the publication policy. Input/live and native-output identities were not captured, so the current needs: repro qualification remains applicable.
2026-10-26 triage at main 2f10e0407769b685083c17a1c90bb43a060b94a0: Folded the additional source-qualified observation into the active brief. The failed identities remain uncaptured, so needs: repro and the existing guards remain.
Real-install recurrence — reported 2026-11-02
From the maintainer's report: a hosted 0.44.0 install with managed native storage (not a fixture) logged four index publication refusals in about one day of server uptime. All four name the -shm sidecar:
[brain] the keyed reindex after an application failed: stale maintenance output: .brain-index/brain.db-shm
[brain] governed index refresh failed: Error: stale maintenance output: .brain-index/brain.db-shm (x3)
They happened in ordinary interactive sessions. In each, the agent applied several Markdown edits through edit_file and brain_update, and each edit queued an index update. User-visible effect: the edits were applied, but search served the old index until a later refresh succeeded. This failure therefore happens outside the timing proof: it affects search freshness in a real install. It is not only a fixture artifact.
Bounded SQLite-level observation — triage 2026-11-03
This checks the reader-sidecar premise and does not reproduce the publication refusal. Bun 1.4.2 bun:sqlite, local Linux, temporary directory, fictional one-row table. Each step recorded the size, mtimeNs and content SHA-256 of each file:
- A writer created a WAL database and closed it.
brain.db-walandbrain.db-shmwere then absent. - One
readonly: trueconnection opened and ranSELECT. This createdbrain.db-wal(0 bytes) andbrain.db-shm(32 KiB). Both remained after that read-only connection closed. - A second read-only
SELECTrewrotebrain.db-shmin place: itsmtimeNs(and so its stamp) changed, but its content hash at rest was identical before and after. - With a read-write connection held open, 20 read-only open/select/close cycles left the
-shmstamp and content unchanged. When that read-write connection, the last one open, closed, SQLite deleted-waland-shmagain. brain.dbwas unchanged throughout.
Publication's stale-input check compares entries (if (!equal(previous, live.entry, packages/ui-sdk/src/server/worker-native-output.ts:383). For a file, an entry is its type, mode and content hash (async function inspect, same file:183-209). So the stale-input -shm signature is consistent with a reader creating an absent -shm, or a last read-write close deleting it, between the input snapshot and publication. An mtime-only rewrite like step 3 would not trip that check. Content sampled during a live transaction was not measured. The output-copy checks compare full stamps (Native output changed before copy, same file:428), so a step-3 style rewrite of the native output's -shm would trip them.
This evidence supports a sidecar mechanism for the -shm occurrences. It does not explain the brain.db output-copy variant, show which connection touched the live index in any failed run, or choose a publication policy. The script used temporary paths only and is not committed.
What still completes the repro: a product-path test that opens or closes a real connection on the live index between the input snapshot and publication (the first acceptance criterion), or a failed-run receipt naming the writer.
Related: #2921 attributes native automatic-index aborts on main (Native manager outcome is unknown … AbortError). That is a different signature, and no shared cause is claimed.
Triage 2026-11-03 at main 3d3516a0247702560c09c5a0889bdec39b8313fb: added the 2026-11-02 real-install -shm recurrence and its user-visible effect, plus a bounded SQLite observation: read-only connections create an absent -shm/-wal and touch its stamp, and the last read-write close deletes them. needs: repro remains for the product-path test or writer receipt; p2 kept, with a priority question raised in the triage comment.
Activity
schlessera commentedon Oct 25, 2026
Seen twice more in the native pi
--apply-timingcell (UID 1000, 2,000-note fixture) while proving #2853, at the same branch head, in 2 of 7 runs. Every host apply in both runs succeeded; the failures were in index publication:Native output changed before copy: .brain-index/brain.db-shm(NATIVE_AUTOMATIC_INDEX_COMPLETED);brain.dbitself, at the same-turnbrain_searchbarrier: the deferred targeted update failed withNative output changed before copy: .brain-index/brain.db, so the barrier refused (IndexFlushError) and the cell failedAPPLY_TIMING_SEARCH_WAITED_FOR_INDEX.The second one is the same output-stamp check (
packages/ui-sdk/src/server/worker-native-output.ts, theNative output changed before copythrow) hitting the main database file rather than its shared-memory sidecar.[-]ui-sdk: an automatic index refresh is refused as stale maintenance output when a reader touches brain.db-shm[/-][+]ui-sdk: native index publication intermittently refuses changed database or sidecar stamps[/+]schlessera commentedon Oct 25, 2026
2026-10-25 triage at main
827861e1fa71cd4a26b52f1ef0f96b849381acdf: Folded both later native-output-copy recurrence variants into the current reproduction brief. Preserve needs: repro: the reader-sidecar theory is unproven and does not explain the database-file variant.schlessera commentedon Oct 26, 2026
2026-10-26 recurrence while validating #3001. The same pi UID 1000
--observation-timingcell, without fsync load, failed its final automatic-index drain on both trees:c47483196f02c1098128207ce68c4f0de6b571ab, before the inbox migration: exit 1 after 114.2 seconds.b9b7d099ba362838f22407902c9d3a4b9fc70cc6: exit 1 after 118.6 seconds.Both report exactly:
The branch's observation artifact contains all 220 calls across 11 tool cases, with zero tool errors; the error comes later at queued refresh drain. Its default four-cell hosted matrices pass both without load and under three fsync writers, including the expected retained-index negative control and owned cleanup. The timing wrappers correctly await the now-asynchronous host bridge.
This confirms the existing failure on the base as well as the branch; it does not attribute which writer changed the sidecar or settle the publication policy. Input/live and native-output identities were not captured, so the current
needs: reproqualification remains applicable.schlessera commentedon Nov 2, 2026
Seen on a hosted 0.44.0 install with managed native storage (not a fixture). Within one day of server uptime, the server log has four index publication refusals:
All four name the
-shmsidecar. They happened during ordinary interactive sessions in which the agent applied several Markdown edits throughedit_fileandbrain_update, each followed by a queued index update.Effect: the agent's edits were applied, but search kept serving the old index until a later refresh succeeded.
schlessera commentedon Nov 3, 2026
2026-11-03 triage at main
3d3516a0247702560c09c5a0889bdec39b8313fb: added the 2026-11-02 real-install recurrence to the body. A bounded SQLite observation (in the body) also supports the-shmmechanism: a read-only connection creates an absent-shm/-wal, and the last read-write close deletes them. Either change can trip the stale-input entry comparison. It does not explain thebrain.dbvariant or name the writer in any failed run, soneeds: reprostays.Priority question for the maintainer: this now affects search freshness in ordinary interactive use, not only the timing proof. Edits apply, but search serves the old index until a later refresh succeeds. Labels still say p2 with milestone 0.45.0. Raise to p1 if 0.45.0 should commit to fixing it; otherwise p2 stands. I left it at p2.
schlessera commentedon Nov 4, 2026
Reproduction findings — 2026-11-04
Verdict: the original
stale maintenance output: .brain-index/brain.db-shmdefect is reproduced in the unmodified production publisher with a real concurrent read-only SQLite connection. This completes the first acceptance criterion for that refusal boundary. It does not attribute the two laterNative output changed before copyvariants.Inspected revision and environment
origin/main:53b862123d7b8e4c9d039859fabdc9fc6ad4cd36; checkout clean before and after the investigation.7.0.0-42-generic, x86_64; UID 1001; Bun1.4.4 (38afee6c8), bundled SQLite3.53.4; Nodev26.13.0; git2.53.0; gh2.103.3.bun install --frozen-lockfile). Fixture databases/checkpoint copies/stages are ordinary temporary directories on Btrfs outside the checkout; the script is outside authored source. All data is fictional Odysseus data. SQLite child processes receive only PATH, disable env-file loading and use the repository's network guard. No provider/model requests, credentials, private instances or paid services are involved.GET /repos/schlessera/brain-kit/issues/2878/parentreturns the explicit404 No parent issue found; this is an ordinary standalone issue. No dependency or assignment change is made.Minimal conditions and observed result
openDatabaseto seed one fictional row, then let that writer process exit. Unlike a barenew Database(...)probe, the product opener enables WAL persistence (db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 1),packages/core/src/lib/db.ts:117). The closed writer leaves the complete database/WAL/SHM family in place.prepareNativeWorkerOutput, and update the stage's row using the real opener in a separate writer process. Let that process exit before publication.openDatabase(livePath, { readonly: true }), execute onlySELECT value FROM odysseus, and hold that connection open through publication. This uses the same opener/options as pi'sopenRead(function openRead,packages/ui-backend-pi/src/brain-access.ts:185-191).output.publish().Expected: a reader that changes no indexed document should not prevent publishing the prepared refresh. Observed: publication refuses the whole refresh, and the live index continues to return the old
Ogygiarow rather than stagedIthaca.Exact runtime boundary:
The input/live
brain.dbandbrain.db-walhashes and stamps are identical. Both SHM files are 32,768 bytes with mode 0600, but the reader changes actual SHM content, not just its mtime: 162 bytes differed in the sampled failing run, including the word at byte offset 104 changing from0to4294967295. Sample checkpoint/live SHM SHA-256:The script verifies the reader process is still alive through publication, checks the exact error, and checks that refusal published no index-family bytes. The only post-snapshot actor touching the live database is that real read-only connection; no fabricated sidecar bytes, timestamps, exceptions or product mutations are used.
Bounded controls: five fresh fixtures per condition, 15 cases total. The after-snapshot reader refuses in 5/5; no intervening reader publishes in 5/5; priming the read-only connection before the input snapshot and reading again after it publishes in 5/5. Both successful controls verify a fresh read sees
Ithaca. With--expect-refresh, the desired-behavior assertion exits 1 for the actual defect:These observations attribute a concrete reader-caused stale-input failure. The content comparison is the issue's cited
if (!equal(previous, live.entry,packages/ui-sdk/src/server/worker-native-output.ts:383; file entries include a content hash (async function inspect, same file:183-209). Those anchors and the separate output-copy check (Native output changed before copy, same file:428) still match at the inspected SHA.Reusable reproduction
From the inspected checkout, save the following block as
/tmp/odysseus-2878-repro.ts. Its parent directory must be writable and on Btrfs: the copied acquisition fixture deliberately uses the repository's existing acquisition checks without patching filesystem predicates. This is the same testing boundary aspackages/ui-sdk/tests/native-worker-publication.test.ts: the manager supplies copied acquisition/inspection metadata, while the actual publisher opens, hashes, copies and publishes real files. It does not qualify Btrfs snapshots, trusted OverlayFS, separate worker identity, the native manager or the complete hosted timing cell.Attempts, limits and next step
brain_search, the full indexer, the 2,000-note hosted proof, provider traffic or any production install. No assertion about those complete flows is inferred from it, and no live-provider evidence is necessary to establish this reader/publication mechanism.brain.dbvariant, remain unattributed. The independent native automatic-index abort signature in ci: attribute recurring native automatic-index aborts on main #2921 remains separate. No common writer/cause or sidecar-only remedy is claimed.Readiness: the original SHM refusal now has the requested real-reader product-path reproduction. Remove
needs: repro; if the fresh issue read still has no otherneeds:label, addagent-ready. Preservetype: fix,area: ui-sdk,priority: p1, milestone0.45.0, state and assignments. Other-variant attribution and post-fix/native verification remain implementation work under this issue, not results claimed here.schlessera commentedon Nov 15, 2026
Claimed for implementation. Claim token:
claim-10321159. Branch:fix/2878-index-sidecar-publication.closure reports only (no direct path overlap with worker-native-output.ts): #3054 #3056 #3059 #3069 #3116 #3393 #3437 #3464 #3581 #3622 #3806 #4002
fix(ui-sdk): a read-only index connection no longer refuses native pu…
schlessera commentedon Nov 15, 2026
Delivered by #4011, squash
5af68976988140d8d916f74d7342959a4cc4e66don main (verified to be an ancestor oforigin/main). Candidate run 43721145240 passed. The squash's main CI run 43723553262 was still in progress at merge.stale maintenance output: .brain-index/brain.db-shm. After the fix it publishes, and a new connection reads the refresh. A concurrent index writer, a note writer and a link planted over-shmall still refuse. The PR has the failing-first and mutation receipts.docs/decisions/governed-writable-workers.md). The wal-index follows its database: it is never compared or copied, and a fresh empty file replaces it wheneverbrain.dborbrain.db-walpublishes. Leaving the live-shmin place was rejected: a new connection that pairs the published WAL with a wal-index an earlier reader still holds fails withSQLITE_IOERR_SHORT_READ.Native output changed before copy: .brain-index/brain.dbtiming variant. Those refusals now name the inspected and found stamps.prove-native-host.ts --observation-timingcell needs the native manager host.