Repository navigation
fix: Control UI test lane fails at random on unrelated pull requests - #123512
Conversation
…reset The non-isolated runner already resets the module graph after every test file, so each file evaluates its own component classes. The jsdom window it shares across the whole worker was never reset with it: every Control UI component registers with `if (!customElements.get(tag))`, so the first file to import a component owned that tag for the rest of the run and `document.createElement` kept building elements closed over that file's module instances. Later files' singletons, module mocks, and spies were never the ones production reached, so assertions failed as "expected ... to be called once, but got 0 times" in whichever files the size-based sequencer happened to place after a warming one. Drop repo-owned tags with the graph they came from. Dependency packages are externalized and register once per worker through native ESM, so their definitions are attributed by define call site and kept. The same window also carried mounted DOM forward, so helpers reading `document.body.querySelector(...)` answered an earlier file's leaked dialog and focus assertions read its stale activeElement. Clear the body with it; `document.head` stays, since dependency styles cannot be replayed either.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 2:11 AM ET / 06:11 UTC. ClawSweeper reviewWhat this changesThe PR cleans repository-owned jsdom custom-element registrations and leftover document body content between files in shared Vitest workers to stop Control UI test flakes. Regression provenancePossible regression — probable (reproduction; failure trace). No predecessor PR is attributed. Merge readinessKeep open for maintainer review: this maintainer-labeled PR has detailed claimed validation, but local read-only inspection failed before its runner and jsdom contract could be independently checked. Priority: P2 Review scores
Verification
How this fits togetherThe non-isolated test runner reuses a worker and jsdom window while resetting modules between files. Control UI tests create custom elements and DOM state in that environment, so the runner must align window cleanup with per-file module cleanup. flowchart LR
A[Test files] --> B[Shared Vitest worker]
B --> C[Module graph reset]
B --> D[jsdom window]
C --> E[Per-file test modules]
D --> F[Custom elements and DOM]
F --> G[Runner cleanup]
G --> E
Decision needed
Why: The Before merge
Agent review detailsSecurityNone. PR surfaceTests +190. Total +190 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep cleanup at the shared-runner boundary, with the private jsdom contract and exact-head shared-worker test coverage independently verified before merge. Do we have a high-confidence way to reproduce the issue? Unclear: the PR body provides detailed deterministic repro and after-fix results, but the local environment failed before those paths could be inspected or rerun. Is this the best way to solve the issue? Unclear: placing cleanup in the existing shared-runner boundary is plausible, but the jsdom-private registry contract was not independently verified. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 6bd21a11222a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…penclaw#123512) * fix(test): keep shared jsdom window in step with the per-file module reset The non-isolated runner already resets the module graph after every test file, so each file evaluates its own component classes. The jsdom window it shares across the whole worker was never reset with it: every Control UI component registers with `if (!customElements.get(tag))`, so the first file to import a component owned that tag for the rest of the run and `document.createElement` kept building elements closed over that file's module instances. Later files' singletons, module mocks, and spies were never the ones production reached, so assertions failed as "expected ... to be called once, but got 0 times" in whichever files the size-based sequencer happened to place after a warming one. Drop repo-owned tags with the graph they came from. Dependency packages are externalized and register once per worker through native ESM, so their definitions are attributed by define call site and kept. The same window also carried mounted DOM forward, so helpers reading `document.body.querySelector(...)` answered an earlier file's leaked dialog and focus assertions read its stale activeElement. Clear the body with it; `document.head` stays, since dependency styles cannot be replayed either. * fix(test): keep the jsdom definition shape local to its module
…unner ui/vitest.config.ts drives CI's checks-ui job (pnpm --dir ui test). Its unit project sets isolate:false but never wired runner: nonIsolatedRunnerPath, so the per-file cleanup in test/non-isolated-runner.ts — module-graph reset, repo-owned custom element dropping, DOM body reset, timer and spy restoration — never ran in the lane CI actually uses. Only the repo-root lane behind scripts/run-vitest.mjs loaded it. Files sharing a worker therefore kept the previous file's evaluated modules, so whichever file imported a component first pinned it to the real dependency and a later file's vi.mock factory never reached production code, surfacing as "expected 0 to be 1" in whichever sibling the size sequencer happened to pack alongside it. This is the class PR #123512 diagnosed and fixed at the runner; the fix never reached this lane, so the repo kept absorbing it one uiIsolatedTestFiles entry at a time. browser stays exempt (the runner imports node:fs and server modules that cannot load in browser mode) and unit-node stays exempt (it carries the Playwright-driven layout tests whose browser lives in module scope, which per-file module resets churn). The config test asserted runner was undefined for every project, pinning the broken wiring; it now asserts the invariant and fails on the pre-fix config.
…unner (#126071) * fix(test): run the shared Control UI lane on the cross-file cleanup runner ui/vitest.config.ts drives CI's checks-ui job (pnpm --dir ui test). Its unit project sets isolate:false but never wired runner: nonIsolatedRunnerPath, so the per-file cleanup in test/non-isolated-runner.ts — module-graph reset, repo-owned custom element dropping, DOM body reset, timer and spy restoration — never ran in the lane CI actually uses. Only the repo-root lane behind scripts/run-vitest.mjs loaded it. Files sharing a worker therefore kept the previous file's evaluated modules, so whichever file imported a component first pinned it to the real dependency and a later file's vi.mock factory never reached production code, surfacing as "expected 0 to be 1" in whichever sibling the size sequencer happened to pack alongside it. This is the class PR #123512 diagnosed and fixed at the runner; the fix never reached this lane, so the repo kept absorbing it one uiIsolatedTestFiles entry at a time. browser stays exempt (the runner imports node:fs and server modules that cannot load in browser mode) and unit-node stays exempt (it carries the Playwright-driven layout tests whose browser lives in module scope, which per-file module resets churn). The config test asserted runner was undefined for every project, pinning the broken wiring; it now asserts the invariant and fails on the pre-fix config. * fix(agents): stop passing an ignored resolver to instance-bound announce dispatch check-prod-types is red on main: #126062 threaded resolveGatewayContext into the announce dispatch call, but that call now goes through dispatchGatewayLifecycleMethod, whose options type does not carry the field. The type checker is right that it does not belong there. That dispatcher hands work to runtime.dispatchAgent, which resolves context from the Gateway instance it is bound to and forwards a fixed option allowlist, so a caller-supplied resolver was already being ignored. Dropping it is behavior-preserving. The delivery test asserted the resolver was forwarded, but production now binds to the instance dispatcher while the test injects a mock, so that assertion only proved the mock. It now asserts the resolver is deliberately not forwarded. Left for the owner of #126062: sendSubagentAnnounceDirectly and its callers still accept and thread resolveGatewayContext, which is now vestigial on this path. Deleting that chain or teaching the instance runtime to honor the resolver is a design call on a just-landed change.
…unner (openclaw#126071) * fix(test): run the shared Control UI lane on the cross-file cleanup runner ui/vitest.config.ts drives CI's checks-ui job (pnpm --dir ui test). Its unit project sets isolate:false but never wired runner: nonIsolatedRunnerPath, so the per-file cleanup in test/non-isolated-runner.ts — module-graph reset, repo-owned custom element dropping, DOM body reset, timer and spy restoration — never ran in the lane CI actually uses. Only the repo-root lane behind scripts/run-vitest.mjs loaded it. Files sharing a worker therefore kept the previous file's evaluated modules, so whichever file imported a component first pinned it to the real dependency and a later file's vi.mock factory never reached production code, surfacing as "expected 0 to be 1" in whichever sibling the size sequencer happened to pack alongside it. This is the class PR openclaw#123512 diagnosed and fixed at the runner; the fix never reached this lane, so the repo kept absorbing it one uiIsolatedTestFiles entry at a time. browser stays exempt (the runner imports node:fs and server modules that cannot load in browser mode) and unit-node stays exempt (it carries the Playwright-driven layout tests whose browser lives in module scope, which per-file module resets churn). The config test asserted runner was undefined for every project, pinning the broken wiring; it now asserts the invariant and fails on the pre-fix config. * fix(agents): stop passing an ignored resolver to instance-bound announce dispatch check-prod-types is red on main: openclaw#126062 threaded resolveGatewayContext into the announce dispatch call, but that call now goes through dispatchGatewayLifecycleMethod, whose options type does not carry the field. The type checker is right that it does not belong there. That dispatcher hands work to runtime.dispatchAgent, which resolves context from the Gateway instance it is bound to and forwards a fixed option allowlist, so a caller-supplied resolver was already being ignored. Dropping it is behavior-preserving. The delivery test asserted the resolver was forwarded, but production now binds to the instance dispatcher while the test injects a mock, so that assertion only proved the mock. It now asserts the resolver is deliberately not forwarded. Left for the owner of openclaw#126062: sendSubagentAnnounceDirectly and its callers still accept and thread resolveGatewayContext, which is now vestigial on this path. Deleting that chain or teaching the instance runtime to honor the resolver is a design call on a just-landed change.
What Problem This Solves
Resolves a problem where the Control UI unit suite failed at random on pull requests that never touched the failing file. Different runs blamed different files —
ui/src/app/app-host.test.ts,ui/src/pages/sessions/sessions-page.test.ts,ui/src/components/session-organizer-batch-mutations.test.ts,ui/src/components/sessions-hub-tabs.test.ts— usually asexpected "…" to be called once, but got 0 times, with no code change between a green and a red run.Because vitest orders files by size, adding or resizing any UI file reshuffles which files share a worker, so the failures moved around and read as infrastructure noise. Contributors re-ran CI instead of trusting it, and the shared UI lane also exited non-zero on unhandled
NotSupportedErrorrejections in roughly one run in four.Why This Change Was Made
test/non-isolated-runner.tsalready resets the module graph after every file in theisolate: falselanes, so each test file evaluates its own component classes. The jsdom window it shares across the whole worker was never reset alongside it, and two pieces of window state outlived the graph that owned them.Custom element registrations. Every Control UI component registers with
if (!customElements.get(tag))— correct in production, where the module evaluates once. In the shared lane the first file to import a component owned that tag for the rest of the worker: later files evaluated a fresh class the registry never adopted, sodocument.createElement(tag)kept building elements closed over the first file's module instances. Those elements called the first file'si18nsingleton and the first file's realshowConfirmDialog, while the test asserted on its own module mocks and spies — hence "called 0 times" with no error. The runner now drops repo-owned tags with the graph they came from. Dependency packages are externalized and register once per worker through native ESM, so their definitions are attributed by define call site and kept; dropping them leftwa-*permanently unupgraded (1851 errors in a discarded first attempt).Mounted DOM. The same window carried the previous file's mounted elements forward, so
waitForConfirmDialogActionsanswered a leaked dialog instead of the one under test and focus assertions read a staleactiveElement. The body is now cleared with the graph.document.headdeliberately stays: dependency styles register once per worker and cannot be replayed either.This lands at the runner because that is where per-file shared-worker cleanup already lives — the alternative, moving each affected file into
uiIsolatedTestFiles, is the reactive workaround this repo has been applying one flake at a time.Production LOC delta: 0. The whole diff is test infrastructure plus its regression test.
User Impact
No runtime behavior change. CI stops failing on unrelated PRs, and a mock that does not reach production now fails deterministically in the file that owns it instead of at random in a sibling.
Evidence
Root cause proven deterministically (before the fix), by adding one oversized probe file that imports the module under test so the size sequencer places it first:
ui/src/pages/sessions/sessions-page.ts→sessions-page.test.tsfails 7 tests, includingretargets the Gateway after deleting the current sessionandarchive-gates a confirmed archived row-menu deletion, withexpected "vi.fn()" to be called once, but got 0 times.ui/src/app/app-host.ts→app-host.test.tsfails exactlyretries a pending locale once when the Gateway becomes connectedwithexpected "retryPendingLocale" to be called once, but got 0 times.openclaw-modal-dialogmounted →session-organizer-batch-mutations.test.tsfails 12 tests withExpected an open confirm dialog.Instrumentation confirmed the mechanism directly: with the warm probe in place the test file's
i18nwas a different instance from the one the shell element used (sameI18n=false), while the registry still held the warm class (registryClassIsWarm=true,elementIsWarmClass=true). A separate two-file probe proved the jsdomdocumentandcustomElementsregistry are shared across files in a worker (registryShared=true sameDocument=true).All three repros pass with the fix.
Baseline flake rate, unchanged
main, fulluilane: 2 of 4 runs red (one real failure, one unhandled-error exit).After the fix: 6 parallel runs + 1 single-worker run (worst case — all 622 files share one worker) + a post-rebase parallel and serial run, all
612 passed | 10 skipped, zero failures, zero unhandled errors.ui-isolatedlane green (27 files). Newtest/jsdom-custom-elements.test.tsgreen.node scripts/check-changed.mjsgreen on Blacksmith Testbox (lanes: coreTests, ui, testRoot, tooling).Codex autoreview (
gpt-5.6-sol, xhigh): clean, no accepted/actionable findings.Follow-up now unblocked (not in this PR):
test/vitest/vitest.ui-isolated-paths.mjslists 27 files hand-moved out of the shared lane, and its stated reason — "custom-element registration matching the current registry" — is exactly what the runner now handles. Several of those files can likely return to the shared lane, which would cut ~48s from that lane. That needs its own per-file ordering proof.