ui-server: the host-token-fallback budget tests race a 200 ms adapter window against the worker commit

Open Beginner friendly
#3,009 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, sqlite, typescript
Domain
testing

Research direction

Start with packages/ui-server/tests/ws-turn-budgets.test.ts around lines 58 and 66, then read packages/ui-server/src/brain/turn-budgets.ts to understand when the budget report settles and the host aborts. Replace the fixed 200 ms wait with a wait for the abort decision that has a long deadline. Run the test repeatedly; it should pass under load and fail if the host abort is removed.

Written by the indexing model from the issue text.

Description

agent-ready area: ui-server type: test

Context

ws-turn-budgets.test.ts's "actual claude/pi completed response crosses the host token fallback and stops with budget_exceeded, preserving partial work" cases fail intermittently with BUDGET_HOST_ABORTS_ACTUAL_ADAPTER (expected true, received false).

The fixture adapter waits for the host's abort for at most 200 ms after emitting usage that crosses the budget: Bun.sleep(200) in the Promise.race after each fixture adapter emits its usage, packages/ui-server/tests/ws-turn-budgets.test.ts:58 (Claude) and :66 (Pi). Since #2896 the blocking budget report commits on the SQLite write worker (observe, packages/ui-server/src/brain/turn-budgets.ts), and the host aborts only once that commit settles. On a loaded host the commit plus the abort can take longer than 200 ms, so the adapter returns first and the test reads it as "not aborted".

Observed on 2026-10-26, running the file alone on a loaded shared host:

  • main c47483196: 2 failures in 22 runs;
  • an unmerged #2850 slice branch: 6 failures in 33 runs.

The full ui-server suite also failed both cases once.

Scope

Make the test wait for the host's abort decision rather than a fixed 200 ms. For example, the adapter could hold until the budget report has committed (budgets.settled() or an equivalent hook) or the turn's abort signal fires, with a long deadline. The test must still prove that the host aborts the adapter, and fails if it never does.

Out of scope

Changing how or when the host aborts a turn over budget.

Acceptance criteria

  • The file passes 20 consecutive runs on a host under three dd … conv=fsync writers.
  • A mutation that removes the host's budget abort still fails BUDGET_HOST_ABORTS_ACTUAL_ADAPTER.

Verification

bun run test packages/ui-server/tests/ws-turn-budgets.test.ts, repeated.

Contract impact

None.

Dominant language
TypeScript
Stars
3
Forks
0
Avg merge
5h 8m
Merged PRs (30d)
946

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from schlessera/brain-kit

All issues in schlessera/brain-kit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.