Repository navigation
Description
Context
tests/index-query-consumers.test.ts:552, "each response is one snapshot, and the next call reads what is there now > the vocabulary keeps one WAL snapshot while a writer commits between its reads", fails intermittently on main.
Observed in main run https://github.com/schlessera/brain-kit/actions/runs/41671155878 (job unit (2), on 34cef57ce). It was that shard's only failure. The error comes from app shutdown, not from the test's assertions:
error: 1 native checkpoint(s) remain retained after shutdown: <id>. NativeBrainManagerError: This native root has no recorded checkpoint lease; arbitrary broker roots cannot be deleted.
reason: "native_journal_observation_unavailable",
at close (packages/ui-server/src/brain/native-journal-observer.ts:499:32)
at async close (packages/ui-server/src/brain/turn-journal.ts:764:107)
at async <anonymous> (packages/ui-server/src/app.ts:1280:82)
close() in packages/ui-server/src/brain/native-journal-observer.ts:490-500 retries every retained checkpoint release and throws if one still fails. Here the broker no longer holds a lease for that checkpoint's root, so the retry is refused and shutdown throws.
The same shutdown error also failed packages/ui-server/tests/app-wiring.test.ts "createApp principal retention > boot prunes an inactive ambient principal through the production path", in main run https://github.com/schlessera/brain-kit/actions/runs/41673315689 (job unit (3), on 90aebd916). So the cause is in the observer's shutdown path, not in one test.
Locally, on 90aebd916 (main) plus #3516, the file failed 2 of 9 runs. Both failures took about 1.5 s and were reported as (unnamed), which matches a throw from teardown. The other 7 runs passed 22/22. The two failures came straight after a tests/unit-workers.test.ts run on the same host, so host load may make it more likely.
Needs scoping: the cause is not yet known. Two candidates are a race between a queued release and the shutdown retry for the same checkpoint, and a lease the broker dropped before close() retried.
Scope
- Find out why a retained checkpoint has no recorded lease when the observer closes after this test.
- Fix the cause in the release/shutdown path, or in the test's teardown if the test is wrong.
Out of scope
- Weakening the "remain retained after shutdown" refusal or swallowing the error at
app.close(). - Unrelated failures in either test file.
Acceptance criteria
- The cause is named, with a
file:line. - A deterministic test reproduces the shutdown refusal before the fix and passes after it.
tests/index-query-consumers.test.tsandpackages/ui-server/tests/app-wiring.test.tseach pass 20 consecutive local runs.
Verification
bun run test tests/index-query-consumers.test.ts packages/ui-server/tests/app-wiring.test.ts, repeated, plus the new deterministic test.
Contract impact
None expected.
2026-11-03: added the second instance in app-wiring.test.ts (main run 41673315689).
Activity
[-]ui-server: index-query vocabulary WAL-snapshot test intermittently fails shutdown with a retained native checkpoint[/-][+]ui-server: app shutdown intermittently throws on a retained native checkpoint with no recorded lease[/+]schlessera commentedon Nov 3, 2026
Raised to p0. A green main run is required to clear red-main incident #3511, and this intermittent shutdown failure can turn any main run red (seen in runs 41671155878 and 41673315689).
schlessera commentedon Nov 3, 2026
Claiming (token
claim-3521-a7f3). Branchfix/3521-native-checkpoint-shutdown-race. Collision note: #3516 is the declared red-main fix; its files do not overlap this issue's paths.schlessera commentedon Nov 3, 2026
Draft PR #3529 (head
18d03b621). Cause: the journal observer retained a checkpoint id before the lease owner refused an already-aborted signal, which it does before recording any lease (packages/ui-server/src/brain/native-journal-observer.ts:291-302,packages/ui-server/src/brain/native-brain-leases.ts:121-128). Shutdown aborting an in-flight observation triggers it. The analogous worktree-journal window is filed as #3528. Releasing claimclaim-3521-a7f3; the PR carries the work.fix(ui-server): never retain a native checkpoint refused on an aborte…