Skip to content

test(showcase): bring the teardown-race and approval-resume test files under the 10 s budget - #23273

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-23185-showcase-slow-tests
Oct 13, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-23185-showcase-slow-tests

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #23185
Clause-②: no

Brings both @objectstack/example-showcase rows of #23185 under the 10 s per-file budget. This PR closes both rows:

file card reading (slowest of 20 hourly runs) before, this container after, this container
test/vitest-console-teardown-race.test.ts 20.8 s (38335967790) 6.34 s 2.2–2.5 s idle (5 runs), 2.2–3.2 s beside four concurrent vitest loops (10 runs), 2.95 s inside the full package suite
test/approval-resume-relation-expand.test.ts 10.2 s (38202645321) 7.30 s 2.2–2.3 s idle (3 runs), 2.1–2.5 s beside four concurrent vitest loops (5 runs), 2.55 s inside the full package suite

"File wall" is the vitest JSON reporter's per-file endTime - startTime, the same module duration the refresh lane reads; module loading is outside it. Before is at the base afbf960c26 and after is at this branch, both on the same 4-vCPU container under the shared verify lock. No timeout was raised, nothing was deleted, and nothing moved to another project. Pin, per the card: the next refresh PR's list no longer names either file.

The fix replaces clocks with sync points. Where the time went, per file:

vitest-console-teardown-race.test.ts: from a race with a retry budget to two ordering facts

Where the time went. Each leg spawns a real child vitest, about 1 s each. The ablation leg retried up to 8 times until the teardown race happened to open, and the guarded leg repeated 4 times. On a loaded runner the race rarely opens, so a run paid all 12 children. That is the 20.8 s.

What was measured on the way. The race has two windows, both inside vitest, and a green run exits 1 only when both open:

  1. In the worker, a console RPC must still be unacknowledged when teardown's $rejectPendingCalls sweep runs.
  2. In the main process, the worker sends its unhandled-rejection report after it reports the file finished. vitest reads its unhandled errors for the exit code as soon as the pool settles, so a report that arrives after that read is recorded but never graded.

Instrumented traces of the child's main process showed the second window: in the non-reproducing runs the rejection did happen, and its catchError landed after onTestRunEnd.

The change. Both legs now run their child with a harness reporter, test/fixtures/late-console-teardown/hold-console-acks.reporter.ts:

  • Window 1 is held open. vitest's main process answers a console RPC only after every reporter's onUserConsoleLog settles. The reporter acknowledges log N only when log N+1 arrives, so the newest console RPC is always unacknowledged, and the sweep always finds one pending. This depends on ordering, not on load. The reporter docblock carries the full argument.
  • Window 2 is read, not raced. At main-process exit every worker has answered stop, after sending its rejection report on the same ordered channel. So the reporter's verdict file records delivered (every teardown rejection the main process received) beside graded (the ones vitest's exit code saw). The path comes in through vitest's own --outputFile.holdConsoleAcks=... option.

As a result, each leg runs once. The ablation grades on delivered, and when graded is non-zero it also requires a non-zero exit with the error printed. The guarded leg requires delivered == 0 and exit 0. The skip path and its retry budget are gone: with the hold in place, a premise-intact ablation that delivers nothing is a broken instrument and fails as one. The premise probe gains a sixth marker for the one link the hold adds: the cli-api chunk's console RPC handler awaiting the reporters. PREMISE CONTROL gains the matching mutation case.

The fixture's first tick() now runs synchronously inside its test, so a console RPC exists before teardown takes its rpcDone() snapshot. That makes the hold's precondition true by construction. types/node-shim.d.ts gains only the members the new code imports.

Prototype measurements (one child per attempt, 4 vCPU, under the verify lock):

arm teardown rejection exit 1
idle, vitest defaults, no hold 20/20 20/20
idle, ablation config + hold 40/40 40/40
four concurrent vitest loops, defaults, no hold 4/20 4/20
four concurrent vitest loops, ablation config + hold 40/40 32/40
four concurrent vitest loops, app config + hold 0/10 0/10
four concurrent vitest loops, app config + hold, interception re-armed 20/20 19/20

The last column is window 2. It is vitest's own race and no reporter hook can close it, which is why the pin grades the defect on the middle column.

approval-resume-relation-expand.test.ts: the stays-quiet watch ends on a settle point

Where the time went. The pre-fix reverse check spent 5.2 s waiting out the full INBOX_WATCH_MS window on every run, to conclude that nothing arrived. The first case added a fixed sleep(200).

The change.

  • inboxStayedQuiet takes an optional settled predicate. It is asked before the verdict read and ends the observation early. 'quiet' still rests only on a fresh read taken after the observation ended, which is the [finding] deliveredInbox returns SHORT on timeout, so a slow run is asserted as a wrong value — and in one call site that makes the test PASS for the wrong reason #10106 contract, and now records endedBy: 'settled' | 'deadline'.
  • The call site's predicate is inboxSettled: the stranded run is failed, and every sys_notification_delivery row is in a final state (success, dead or suppressed). Any other state, including one added later, keeps the watch open. These two facts are sufficient because the inbox is a materialization of delivery: no producer writes sys_inbox_message directly. The call site asserts endedBy === 'settled', so the 5 s cannot come back silently. INBOX_WATCH_MS is unchanged and still only shrinkable.
  • The sleep(200) is gone. decide() awaits the resume (ApprovalService.serviceResume awaits automation.resume), so the run is already terminal when it returns. Measured with a probe: completed right after decide, with the inbox row still pending in the outbox. That pending row is what deliveredInbox already waits for.
  • Three new contract cases, deterministic and with no clock: a settled system ends the watch after exactly two reads; a row that lands before settlement is still seen, because the verdict read comes after the settle check; and inboxSettled needs both halves, including fail-safe on an unknown delivery state.

Ablations (one-time proofs, nothing left in the tree)

Every mutation went through node scripts/ablation-replace.mjs in wrap mode. Each one showed the anchor count going 1 to 0, a changed blob hash, and, on restore, a blob equal to HEAD and an empty git diff HEAD. The expected direction was red each time, and red is what was observed. All runs were at 53ed69f184, before the merge of main, which touched no file of this package.

ablation runs result
A1: delete disableConsoleIntercept: true from vitest.config.ts 5 idle + 5 beside four concurrent vitest loops GUARDED red 10/10 (delivered: 1)
A2: the hold reporter returns Promise.resolve() (no hold) 12 beside four concurrent vitest loops ABLATION red 11/12, each on the "instrument" branch (premise intact, nothing delivered), never a skip
control: no mutation 5 idle + 10 beside four concurrent vitest loops green 15/15, file wall 2.2–3.2 s
B1: the watch's verdict read becomes the pre-settle sample 1 3 contract cases red
B2: the call site settles on completed instead of failed 1 pre-fix case red on endedBy, after paying the 5 s window (file 7.23 s)
B3: inboxSettled drops its outbox half 1 "both halves" contract red

Local verification (at 5ea05a3201, the head of this PR)

  • vitest run over the whole package (examples/app-showcase, --maxWorkers=2): 33 files, 412 tests passed, 0 skipped. It ran beside the gate battery, so the box was loaded. The two files read 2.95 s and 2.55 s, and no other showcase file was over 1.8 s.
  • pnpm --filter @objectstack/example-showcase typecheck: exit 0. tsc --listFiles counts all 5 touched files in the program.
  • Gates derived by node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack: 39 derived, 38 exit 0, 1 NOT MEASURED. The reconciliation (--ran, exit codes recorded) reads "39 derived, 38 run, 1 NOT-MEASURED, 0 UNRUN". The NOT MEASURED one is pnpm check:dual-build-cjs-loads: its self-test passed (93 cases), then it exited 3 with PREREQUISITE NOT MET, because 8 packages outside this package's dependency closure (studio, client-react, embedder-openai, knowledge-memory, knowledge-ragflow, organizations, service-cluster-redis, service-knowledge) have no dist/ in this worktree. No package's dist/ changes in this diff. CI reads it from a full build.
  • Extra: node scripts/check-console-intercept-disarm.mjs passed (74 packages disarmed). pnpm check:nul-bytes passed.
  • Lint, as a proven narrowing. ① Population: the five touched files, which the repo's eslint.config.mjs lints; all five were reported, none ignored. ② --format json reports 5 files, 0 errors and 0 warnings. ③ Invariance: this config never enables type-aware linting (no parserOptions.project, no projectService), so this diff cannot move the verdict for any untouched file. The full pnpm lint is CI's.
  • No changeset: @objectstack/example-showcase is "private": true and this diff only touches its tests and type shim, so it publishes nothing. Label: skip-changeset.

Acceptance notes (observations, not filed)

  • vitest's window 2 (a teardown rejection reported after the pool settles is recorded but never graded) is upstream behaviour. It is outside our contract and moot behind disableConsoleIntercept: true. Carrier: none.
  • examples/app-showcase/vitest.config.ts and the header of scripts/check-console-intercept-disarm.mjs still describe the window as one load-width span inside rpcDone(). The measured second window refines that description but does not contradict either file's prescription, so they are left untouched. Carrier: none.
  • The #10106 watch-contract cases still spend about 1.1 s on real sleeps, by design (latency fakes). That is under budget and unchanged here.

Generated by Claude Code

…owcase test files

vitest-console-teardown-race: both legs now run their child vitest with a
harness reporter that acknowledges console log N only when log N+1 arrives,
so the newest console RPC is always pending at the teardown sweep (window 1,
deterministic), and that records every teardown rejection the child's main
process received at its exit beside the ones vitest graded (window 2, read
rather than raced). One child run per leg replaces up to 8 ablation attempts
plus 4 guarded repetitions; the skip path is gone because a silent ablation
is now a broken instrument. The premise probe gains the main-process link
the hold relies on.

approval-resume-relation-expand: the stays-quiet watch ends on a settle
point (the stranded run is failed and the delivery outbox owes nothing)
instead of waiting out its 5 s window; the fixed 200 ms sleep before
reading a run that decide() already resumed to its end is gone. Two new
contract cases pin the settle end on read order, not on the clock.

Claude-Session: https://claude.ai/code/session_012zwsLMxQBwHUYJgPyrpEvx
Co-authored-by: Claude <noreply@anthropic.com>
The settle predicate is asked over a fake run log and a fake outbox: a run
in its named status with only final deliveries settles; a pending,
in-flight or unknown delivery state, or a run in any other status, keeps
the watch open.

Claude-Session: https://claude.ai/code/session_012zwsLMxQBwHUYJgPyrpEvx
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Oct 13, 2026
@github-actions github-actions Bot added the tests label Oct 13, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review October 13, 2026 13:39
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge October 13, 2026 13:39
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit 6c18162 Oct 13, 2026
44 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-23185-showcase-slow-tests branch October 13, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test budget (domain:devx): 2 test file(s) over 10 s of wall in the hourly full battery (Part of #23151)

2 participants