Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,13 @@ available, with the pinned image and diagnostics unchanged.

Browser shards use a committed per-project/file timing table, not live CI
artifacts or a fixed allowlist. Unknown specs get a positive one-second weight;
invalid tables fail visibly. Refresh explicitly from two successful browser jobs:
`bun scripts/refresh-browser-costs.ts <run-id> <attempt>`. Review the source
head/checkout/tree, job IDs and seconds/median metadata alongside the table.
invalid tables fail visibly. Refresh explicitly from one successful CI run
attempt in which every shard of the domain, as configured in `PROOF_SHARDS`
(`scripts/proof-shards.ts`), ran fresh and succeeded:
`bun scripts/refresh-browser-costs.ts <run-id> <attempt> [browser|layout]`
(browser by default). Cancelled, partial or retained-only proof supplies no
measurements. Review the source head/checkout/tree, job IDs and seconds/median
metadata alongside the table.
Unsharded discovery is unchanged and existing browser file concurrency is kept.

`bun run test:browser` runs every configured browser project in the pinned
Expand Down
41 changes: 41 additions & 0 deletions docs/process/test-waits.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,47 @@ Existing issues #1242 (PDF effect readiness), #1685 (hygiene layout readiness),
#1837 (repeated build attribution), and the recording/matrix children retain their
ownership rather than being duplicated here.

### Re-census of later files

The inventory above is a snapshot. Waits added after it are held to the same
rule ([#3332](https://github.com/schlessera/brain-kit/issues/3332)). The
[re-census](https://github.com/schlessera/brain-kit/tree/a13f2247adcc3946d44c023553ff662e926143ea/scripts/measurements/wait-census-3332-2026-11-02)
runs the same expression at `3984040f199cbadbee6e4ce3f1beff816b68dc36`. It
classifies every match in files that do not match at the inventory source
(604 lines in 204 files) as justified, replaceable or not a wait. The
classification is rule-based and does not count executions. A slice that
replaces waits re-reads each enclosing test first, and its pull request records
any reclassification and its mutation receipts.

| Source / assertion | Attributed role and retained proof | Completion control / native boundary |
| --- | --- | --- |
| `private-index-cache.test.ts`, idle expiry and active-base skip | Registered idle timers, armed and delivered while a turn holds the base; expiry still applies once the turn finishes | `privateIndexClock` owns only the cache's timers and `Date.now`. Checkpoints, files and the held delta stay native. |
| Same file, advance/close ordering | The advance holds the base's queue before a turn arrives; close stops a delta or run that has actually started | The bench's `entered`/`running` signals replace 50–100 ms sleeps. Dropping either await reorders the outcome. |
| `reference-source.test.ts` and `reference-tools.test.ts`, admission, eviction and exposure ordering | Each step starts after the scripted fetch, admission or held pool call it depends on; a cancelled fetch's reservation is released only after its teardown | Conditions on the scripted transport and pool replace 5–20 ms sleeps. A held teardown barrier replaces the 30 ms `settleDelayMs` latency. The collaborators are in memory, so one macrotask turn runs all work up to the held barrier. |
| `application-index-timing.test.ts`, deferred index update | Twenty writes return before a slow index update; one targeted update covers them | The update is held until the writes are measured, instead of sleeping 1500 ms. On a route where a write waits for it, each update still takes 1500 ms and the median assertion fails. |
| `chat-lifecycle.test.ts` and `writer-gate-offloop.test.ts`, work queued behind a held writer | The retirement, or the host downgrade, is posted to the real write worker before the racing step | A `Worker.prototype.postMessage` observer replaces 20–50 ms sleeps and fixed timers; the descriptor is restored after each case. |
| `write-worker.test.ts`, app writes against a running procedure | The worker is inside the held procedure before the app writes | The probe sets an `entered` flag that the test awaits with `Atomics.waitAsync`, instead of sleeping 20–50 ms. |
| `native-brain-leases.test.ts`, `storage-offloop.test.ts` and `turn-egress.test.ts` | A lost reply after a newer release started; failures settled before close; a pending taint | The newer release's arrival, one macrotask after the synchronous tick, and a bounded taint poll replace fixed 20–100 ms waits. |
| `worker-steps-event-loop.test.ts`, a supervisor lost during a status request | The request is outstanding when the supervisor is lost; its late answer neither settles again nor releases the broker | The status step is held open, so the request is outstanding by construction. The test releases it and awaits its answer, instead of sleeping 150 ms and then 200 ms. |
| `maintenance-worker-kill-child.ts`, every thread confirms its stop | A non-leader thread that reports itself running delays the snapshot until it confirms | The thread reports running for exactly two polls, instead of until a 10 ms timer fires. The zero-delay heartbeat timers in the fork-ordering cases are the observation: they prove that stop confirmation yields. |
| Claude `worker-cleanup.test.ts` and `worker-stdio-release.test.ts`, reservation and settlement held | The reservation stays charged, and settlement waits, while only the held close or release remains | The state handle's real close is observed, or the release request is polled for. One macrotask then runs any continuation, instead of 20–50 ms windows. |
| ui-react `runtime-hook-phases.test.ts`, pending output | Exit and stderr completion are reported while stdout is held | A condition on those two records, then one macrotask, replaces a 20 ms window. |
| Root `build-concurrency.test.ts`, optional dependency before its consumer | A consumer never compiles before its optional dependency, despite a peer cycle | The dependency's compiler wrapper holds until a peer has finished and its slot has been refilled, instead of sleeping 500 ms. A consumer started in that slot compiles, and fails, while the dependency is held. |
| Root `helpers/planning-observer.ts`, first sampler reading | The sampler has a reading before the observed call blocks the main thread | The sampler posts `ready` after its first reading. The observer awaits that message, instead of one 250 ms interval, with the existing stop budget as its failure maximum. |
| ui-server negative observations behind a real write-worker hold (`drafts-settings-offloop`, `inbox-writes-offloop`, `retry-proposal-offloop`, `storage-offloop`, `storage-scan-offloop`, `writer-gate-offloop`) | The queued commit, and everything after it, has not run while an earlier probe call holds the worker | The worker answers in submission order on one port, so the test reads its main-thread flags when the hold answers, instead of after a 20–50 ms window. Rows the worker commits to the database file are read while the hold is still running, because once it answers the worker may already be committing. |
| ui-server negative observations behind an in-memory hold (`app-writes-offloop`, `drafts-settings-offloop`, `push-drain`, `native-journal-observer`, `private-index-stdio-release`, `reference-source`, `reference-tools`) | Settlement waits for the one held write, release or acquisition | The test waits until the held step has started, then one macrotask runs every continuation that does not wait for it, instead of 10–50 ms. |
| `http-mount-timers.test.ts` and `live-history-adapters.test.ts` | Cancelled native timers never fire; no history frame precedes the first input | A live control timer due after the cancelled ones, and an input frame on the same ordered socket, replace 60–80 ms and 20 ms windows. |
| Failure maxima, reason in source | `app-http-drain`, `app-metadata-cancellation`, `close-cancels-shared-runs`, `dialogue-storage`, `reference-source`, `reference-tools` and `write-worker` races whose expected outcome settles first | The deadline branch is never awaited on success. |
| Negative windows kept, reason in source | Writer-gate waiters in `host-fallback-gates` and `schedule-ignore-admission`; the `reference-writes-offloop` `pending` helper; app shutdown in `app-writer-cleanup`; the replayed tombstone in `contextual-refusals`; the `relayed-runtime-traffic-probe` exit window | A gate waiter polls every 5 ms and reports no refused attempt. The `pending` helper's callers read database rows that must be read inside the hold. A marker request for the replayed tombstone would start its own turn and change the counts. The shutdown windows cover real-IO round trips that correct code never completes, so no event marks them. |
| Kept real time, reason in source | `native-identity-inspector` abort during a blocking FIFO open; geo `routing` admission-write latency while the transport deadline is armed; the delayed-fsync spies in `native-observation-storage`, `transcript-archive` and `native-observation-settlement` (event-loop liveness under slow IO) | The inspector's blocked state has no portable signal. The geo latency and fsync delays are the stimulus itself. |
| ui-react `share-review/commands.ts`, review admission refused or retired | A failed copy, another account, a live owner in another tab, a racing tab or an expired record never admits review | The fixture counts its share-review lock requests and their settlements; a request that admits stays open. The command waits until a request made after a mark has settled, or a review is admitted, instead of 1.2–1.5 s. The racing loser waits for an attempt made after the winner admitted. Where the account's review rows and stashed originals are empty or sealed, nothing can be admitted, so no window is needed. Dismiss waits for the queue to empty, which follows the durable delete. |
| Same file, a lost response | The upload's response opens, then loses its body, so Chromium cannot retry it transparently | The socket closes from the write callback of the partial body, instead of 50 ms later. Closing before the flush lets Chromium retry, and the case fails. |
| ui-react `storage-guidance.layout.tsx`, late and refused responses | A response for the prior account or a replaced root never replaces current evidence; a refused route never opens Settings | The fixture counts the responses it answers and the bodies the consumer reads. The tests wait for the held response to be read, or for the route's refused read to be answered, instead of 50 ms. The route change is committed with `flushSync`, so its open decision has run. |
| ui-react `transcript-qualifiers.offline.tsx` and `conversation-controls.offline.tsx`, tooltip and reply holds | Escape keeps a qualifier hint hidden; the pointer can rest on a hint; short playback gaps keep Speaking | The qualifier's 300 ms show and 150 ms hide timers, and the strip's 300 ms reply hold, run on vitest's fake `setTimeout`. The tests advance them or run every pending timer, instead of 350 ms windows and real gaps. |
| ui-react `conversation-endpoint`, `conversation-consent` and `conversation.offline.tsx` | No speech block arrives after the drain; consent alone, or a pending opening after Mute, never reopens capture | The first audio frame below the speaking threshold follows every queued speaking block, instead of a 200 ms drain. Frames are handled on delivery and a capture calls `getUserMedia` synchronously, so the consent cases read the open count once epoch 2 is applied, or at once, instead of after 100 ms or 30 ms. |
| Kept, reason in source | ui-react `recording-limits` source starvation; the drains in `dialogue-browser-server` and `contextual-conversation-browser-server` | The starvation is the real-time stimulus. The fixture drains only pace or batch frames: tests poll step replies for every outcome. |
| Reclassified, no change | `hygiene-lifecycle-command` 234 (cancellation-safety release cap); `storage-server-command` 39 (startup failure maximum); `liveness-clock` 53 (the page timer under the controlled clock) | Each is a maximum or the timer under test, and its reason is in source. |

## Continuity settling boundaries

Networked continuity contexts start with native offline state, create their
Expand Down
37 changes: 37 additions & 0 deletions docs/process/theme-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,42 @@ remain independently parameterized. This gives ten tests: six responsive
scenario cases, three stale-history cases and one readiness control. Cleanup,
negative observation windows and timing/deadline behavior are unchanged.

## Answer and journal coverage runtime cells

Two later families run 320px dark and 1280px light instead of all four
width/theme cells (#3329). The theme selector sets only `color-scheme`,
which picks one half of each `light-dark()` colour token. No geometry,
focus, key or settlement path in these surfaces branches on it. The removed
copies are 320px light and 1280px dark. Every assertion in them is also made
by the retained cell at the same width. Each theme still paints once in the
runtime, and two central consumer stories own the paint in both Storybook
projects.

(`Phone`, `packages/ui-kit/stories/conversation/AnswerTheme.stories.tsx:33-57`)
mounts the actual consumer `AskUserCard` with the built consumer stylesheet.
The kit's `Decisions/AskUserCard` stories cannot stand in for it, because their
meta disables the axe contrast rule for a known selected-option gap. The
journal stories now render configuration coverage as well
(`Phone`, `packages/ui-kit/stories/conversation/JournalTheme.stories.tsx:50-129`).

| Assertions in the removed copies | Coverage that remains |
| --- | --- |
| `answer-delivery-runtime.test.ts`, `1887: Other has explicit current-text Submit`: `OTHER_LAYOUT_USES_REAL_THEME` | Both themes: 320px dark and 1280px light in the runtime. `Conversation/Answer theme/Phone`, `Desktop`: `painted` and the Other field's computed `color-scheme`, in both projects. |
| Same case: one explicit Submit, blank text disabled, blank Enter sends nothing, draft kept across switching, keyboard reach, ≥44px Submit, no document overflow | The retained cell at each width. The story repeats aria-disabled, the ≥44px Submit and the field/Submit bounds, then runs scoped WCAG A/AA, contrast included, on the field and Submit. |
| Same case: touch tap at 320px, Space at 1280px, single settlement of the original request, one `ask_user_response` frame | The retained cell at each width. The story's Submit dispatch is a fixture callback only. |
| `turn-journal-runtime.test.ts`, `journal configuration coverage keeps small changes first and preserves inspection`: badge description, visible, outside truncation, not clipped; row order and counts; index group; Turn facts; ≥44px disclosure and search; complete, height-bounded inventory; filtering, announcement debounce, refetch retention and error | The retained cell at each width. `Conversation/Journal theme/Phone`, `Desktop` add badge visibility and truncation, the ≥44px coverage disclosure and search, the inventory count and bounds, and scoped WCAG A/AA on the journal with coverage open, in both projects. |
| Same case: no external egress | The retained cell at each width. No replacement claimed. |

Two mutations prove the story side. A light-only typed-text colour in
`AskOtherField` fails `Answer theme/Phone` and `Desktop` in `storybook-light`
on `color-contrast` (`input`). The same mutation leaves the kit
`Decisions/AskUserCard` stories green. A light-only inventory colour in
`JournalCoverage` fails `Journal theme/Phone` and `Desktop` in
`storybook-light` (`.font-mono > .break-all`). The journal stories without
coverage stay green. Both families keep the original scenario bodies, so the
settlement, frame, keyboard, touch, filter and refetch oracles above still run
at both widths.

## Replay assertion ownership

`connection-replay.layout.tsx` keeps native Chromium, built consumer CSS,
Expand Down Expand Up @@ -246,6 +282,7 @@ node scripts/visual.mjs --project=storybook --project=storybook-light \
--filter=ComposerTheme.stories --filter=SessionTheme.stories \
--filter=AccountTheme.stories --filter=JournalTheme.stories \
--filter=ArtifactTheme.stories \
--filter=AnswerTheme.stories \
--filter=InPrint.stories
```

Expand Down
7 changes: 6 additions & 1 deletion packages/geo/tests/routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ const footDemo="https://routing.openstreetmap.de/routed-foot/route/v1";
const footUrls=[dataset("foot").url,footDemo].map(endpoint=>endpoint+
"/driving/20.71,38.36;20.72,38.37?geometries=geojson&overview=full&steps=false&alternatives=false");

/** Instance-local latency observation; retain the real fsync/rename writer. */
/**
* Instance-local latency observation; retain the real fsync/rename writer.
* Kept real time (#3332): the second admission write runs after dispatch, while
* the transport's real deadline timer is armed, so the latency itself is the
* stimulus. A barrier would order the steps but spend none of that deadline.
*/
function delayAdmissionWrites(geo: GeoClient, delayMs: number, admissionDir: string) {
const instrumented = (geo as unknown as {transport: {writeAtomic(path: string, value: unknown): Promise<void>}}).transport;
const original = instrumented.writeAtomic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ try {
} finally {
clearTimeout(timer);
// A connection opened while the runtime exits still reaches the recorder.
// Negative window: no event reports that the exiting runtime opens no more
// connections. A barrier on the runtime's close, a FIFO marker connection and
// every accepted socket closing was tried (#3440): Bun's node:http reported the
// marker about 1 s late, so it was slower than this window.
await Bun.sleep(500);
recorder.close(); relay.stop(true);
}
Expand Down
12 changes: 9 additions & 3 deletions packages/ui-backend-claude/tests/worker-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.skipIf(!native)("Claude keeps a worker's reservation charged until its awai
mkdirSync(brain); mkdirSync(saved); mkdirSync(home); writeFileSync(join(saved, "settings.json"), "{}");
const sandbox = prepareWorkerSandbox(brain, { home, profile: "governed", areas: [] });
const original = internal.launchAgentWorkerAsync;
let gate = Promise.withResolvers<void>(), closing = Promise.withResolvers<void>();
let gate = Promise.withResolvers<void>(), closing = Promise.withResolvers<void>(), stateClosed = Promise.withResolvers<void>();
const retries: Array<() => Promise<void>> = [];
// The real worker and handles; only the turn temp's awaited close is held at a gate.
const launch = spyOn(internal, "launchAgentWorkerAsync").mockImplementation(async input => {
Expand All @@ -33,6 +33,9 @@ test.skipIf(!native)("Claude keeps a worker's reservation charged until its awai
retries.push(close);
turnTemp.close = () => { throw new Error("CLAUDE_SYNC_TURN_TEMP_CLOSE_ON_AN_ASYNC_LAUNCH"); };
turnTemp.closeAsync = async () => { closing.resolve(); await gate.promise; await close(); };
// The state handle's real close runs beside the held one; its completion is observed, not waited out.
const state = worker.state!, closeState = state.closeAsync.bind(state);
state.closeAsync = async () => { await closeState(); stateClosed.resolve(); };
return worker;
});
// Retries run when the test says so, not on a timer racing the worker's release wait.
Expand All @@ -50,13 +53,16 @@ test.skipIf(!native)("Claude keeps a worker's reservation charged until its awai
const confirmed = createStateLedger();
const finished = turn(confirmed);
await closing.promise;
await Bun.sleep(20);
// Everything the release awaits besides the held gate has completed, and one
// macrotask runs any continuation of it: only the gate now holds the release.
await stateClosed.promise;
await new Promise(resolve => setTimeout(resolve, 0));
expect(confirmed.live, "CLAUDE_RESERVATION_HELD_WHILE_CLOSE_PENDING").toBe(1);
gate.resolve();
await finished;
expect(confirmed.live, "CLAUDE_CONFIRMED_CLOSE_RELEASES_RESERVATION").toBe(0);

gate = Promise.withResolvers<void>(); closing = Promise.withResolvers<void>();
gate = Promise.withResolvers<void>(); closing = Promise.withResolvers<void>(); stateClosed = Promise.withResolvers<void>();
const refused = createStateLedger();
const refusing = turn(refused);
await closing.promise;
Expand Down
Loading
Loading