Skip to content

test(ui-server): keep the real storage budget out of queue-adoption holds (#3561) - #4062

Merged
schlessera merged 2 commits into
mainfrom
test/3561-queue-adoption-storage-budget
Nov 16, 2026
Merged

schlessera merged 2 commits into
mainfrom
test/3561-queue-adoption-storage-budget

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3561

What changed

The queue-adoption cases in packages/ui-server/tests/dialogue-queue-adoption.test.ts no longer let the real 10 s storage budget expire writes they hold on purpose. storageDeadlineClock gains a manual mode: a registered budget fires only through expire() or captureLatest(), never by elapsed time. It also counts registrations. The fixture installs the manual clock and restores it in close(). Each of the five case families now ends by asserting that budgets were armed (STORAGE_BUDGET_ARMED_DURING_HOLD) and that every one was cleared by its write settling (STORAGE_BUDGET_CLEARED_BY_SETTLEMENT). No product code changes, and no assertion was weakened or removed.

Why this shape

The race. DialogueJournal.track arms withinStorageBudget for every tracked write at submission (track, packages/ui-server/src/ws/dialogue.ts:342-355; STORAGE_SETTLEMENT_MS, packages/ui-server/src/db/settlement.ts:2-16). Each case submits up to 256 writes behind a native writer hold. The writer then drains them one at a time after f.release(). On a loaded host, the time from a write's submission to its settlement can pass 10 s. The budget then withholds the owner and reports storage_indeterminate. Whichever assertion next reads callbacks, pages or failures goes red. That matches the issue cell (saved received []) and both assertions in the 2026-11-10 reproduction.

The product behaves as documented, because a write held past its budget is indeterminate. The fault is in the test, which let a real deadline run over a load-dependent window it does not test. This follows docs/process/test-waits.md: a production timer that a case does not claim is controlled, not spent in real time. The budget's own behaviour keeps its tests in dialogue-owner-drain, dialogue-drain-deadline, sqlite-cleanup-owner-deadline and app-writer-cleanup, which use the helper's unchanged default mode.

Not the cause: the hold control's own 5 s cap (Atomics.wait(..., 5000) in tests/helpers/dialogue-test-writes.ts). Every fill loop in this file is synchronous, so nothing can run between the hold and the overflow check, whether a worker reply or a timer. I confirmed this, then left the cap alone.

Rejected: raising the budget or the test timeout. That only moves the threshold, and the brief rules it out.

Proof

All runs are local at head 7134c7d51 on base origin/main eb3c53ac2. Bun 1.4.4, 16 cores, with other workers' suites running concurrently.

Deterministic reproduction (forced ordering). Install the default storageDeadlineClock() in the original fixture and call clock.expire() in release(). That forces the budget to fire before the held writes settle. Result: 18/18 cells fail. Assertions include expect(saved).toEqual(Array(100).fill(true)) (received []) in the issue's fresh-owner … outstanding=true cells, expect(f.failures).toEqual([]) (received ["storage_indeterminate"]) in the canonical-archive cells, and the pages-evidence assertion in the outstanding=false cells.

Failing-first, real time. In fresh-owner inactive-bind shares count admission with its canonical target outstanding=true, three extra capped holds are queued on the same worker ahead of the fill, so the worker drains it about 15 s after submission. That is the slow drain a loaded host causes, with no await added in the held window.

  • Original tree: fails at expect(saved).toEqual(Array(outstanding ? 100 : 0).fill(true)), received [] (15.7 s).
  • This branch: passes.

Mutations (each restored afterwards):

  1. storageDeadlineClock({ manual: false }) with the same slow drain: fails at the same saved assertion, received [].
  2. The helper intercepts STORAGE_SETTLEMENT_MS + 1 instead of the production value, as if the budget constant drifted: 18/18 fail at STORAGE_BUDGET_ARMED_DURING_HOLD.

Repeated runs under load. bun scripts/test-health.ts measure packages/ui-server/tests/dialogue-queue-adoption.test.ts --runs 10 --shuffle --stress: verdict stable, 30 runs, 0 failures, median 11.3 s, host load average 25 to 47 during the run. The same command produced 2 failures in 30 runs before this change (issue comment, 2026-11-10).

Other checks:

  • The helper's other users pass in default mode: dialogue-owner-drain, sqlite-cleanup-owner-deadline, dialogue-drain-deadline, app-writer-cleanup, 34/34.
  • Root tsc --noEmit is clean.

Bug-class audit. The other users of the capped hold control (dialogue-storage.test.ts and others) fill synchronously or hold only a few writes. None of them has a hold window that depends on load and is covered by an armed budget the test does not claim. No other instance found.

bun run check:pr --base origin/main
{"version":1,"kind":"brain-check-pr-receipt","head":"7134c7d5174535fbcbb8ff7f0e6c92ab1d6fe1b4","base":"origin/main","mode":"focused","startedAt":"2026-11-15T21:41:59.411Z","finishedAt":"2026-11-15T21:43:23.005Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":49720.850059000004},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":307.25147400000424},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":396.20750899999985},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":33.054051999992225},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":33080.99366800001}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof. (Hosted proof runs at confirmation.)
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see. (Test-only.)
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only: the provider-history guard passes, or nothing on a turn's path changed.

Collisions

bun scripts/collisions.ts --json --pr 4062 at head 7134c7d5174535fbcbb8ff7f0e6c92ab1d6fe1b4: 22 closure reports and no path or unknown report. The closure reports are test-selection overlap through the ui-server workspace: #3622, #3806, #4002, #4018, #4028, #4041, #4050 and #4060 select some of the same ui-server tests, including this file. No other open PR edits dialogue-queue-adoption.test.ts or helpers/storage-deadline-clock.ts.

Anything left open

Nothing.

🤖 Generated with Claude Code

…olds (#3561)

Every write the dialogue journal tracks arms the real 10 s storage budget
at submission. The queue-adoption cases submit up to 256 writes behind a
native writer hold, and the worker drains them serially after release, so
on a loaded host a write can stay pending past 10 s. The budget then
withholds the owner and reports storage_indeterminate, and the case fails
on whichever assertion reads the withheld callbacks or pages.

The budget is not what these cases claim. storageDeadlineClock gains a
manual mode, in which a registered budget fires only through expire() or
captureLatest(), and counts registrations. The fixture installs it, and each
case now asserts that budgets were armed and that every one was cleared by
its write settling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 10:01
@schlessera
schlessera merged commit e19300f into main Nov 16, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. type: test Coverage, harness or proof work with no behaviour change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: dialogue-queue-adoption fresh-owner outstanding case fails intermittently under load

1 participant