Skip to content

fix: Control UI test lane fails at random on unrelated pull requests - #123512

Merged
steipete merged 2 commits into
mainfrom
steipete/strange-lovelace-b94412
Aug 14, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/strange-lovelace-b94412

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 as expected "…" 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 NotSupportedError rejections in roughly one run in four.

Why This Change Was Made

test/non-isolated-runner.ts already resets the module graph after every file in the isolate: false lanes, 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, so document.createElement(tag) kept building elements closed over the first file's module instances. Those elements called the first file's i18n singleton and the first file's real showConfirmDialog, 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 left wa-* permanently unupgraded (1851 errors in a discarded first attempt).

Mounted DOM. The same window carried the previous file's mounted elements forward, so waitForConfirmDialogActions answered a leaked dialog instead of the one under test and focus assertions read a stale activeElement. The body is now cleared with the graph. document.head deliberately 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:

  • probe importing ui/src/pages/sessions/sessions-page.ts → sessions-page.test.ts fails 7 tests, including retargets the Gateway after deleting the current session and archive-gates a confirmed archived row-menu deletion, with expected "vi.fn()" to be called once, but got 0 times.
  • probe importing ui/src/app/app-host.ts → app-host.test.ts fails exactly retries a pending locale once when the Gateway becomes connected with expected "retryPendingLocale" to be called once, but got 0 times.
  • probe leaving one openclaw-modal-dialog mounted → session-organizer-batch-mutations.test.ts fails 12 tests with Expected an open confirm dialog.

Instrumentation confirmed the mechanism directly: with the warm probe in place the test file's i18n was 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 jsdom document and customElements registry are shared across files in a worker (registryShared=true sameDocument=true).

All three repros pass with the fix.

Baseline flake rate, unchanged main, full ui lane: 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-isolated lane green (27 files). New test/jsdom-custom-elements.test.ts green.

node scripts/check-changed.mjs green 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.mjs lists 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.

…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.
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 14, 2026 05:59
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 2:11 AM ET / 06:11 UTC.

ClawSweeper review

What this changes

The 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 provenance

Possible regression — probable (reproduction; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep 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
Reviewed head: 1a1075c801cdf33e37ea5a385bf569c764f07885
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The submitted rationale and reported validation are strong for a focused test reliability repair, pending independent contract inspection.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal test-infrastructure PR is not subject to the external-contributor real-behavior-proof gate; its body nevertheless records after-fix test-lane evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal test-infrastructure PR is not subject to the external-contributor real-behavior-proof gate; its body nevertheless records after-fix test-lane evidence.
Evidence reviewed 3 items Submitted test-only change: The provided PR diff adds jsdom registry tracking tests and modifies the non-isolated runner; the PR body reports no production runtime behavior change.
Reported after-fix validation: The PR body reports parallel and single-worker UI runs, the isolated UI lane, and changed-file checks passing after the repair; this could not be independently rerun or inspected locally.
Local inspection unavailable: Read-only shell commands failed before executing with bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted, so current-main source, scoped policy, git history, and jsdom dependency internals were not inspected.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Decision needed

Question Recommendation
Should this maintainer PR proceed after a reviewer verifies the pinned jsdom registry-internal contract and exact-head runner behavior? Verify and merge: Confirm the pinned jsdom internal shape and exact-head shared-worker UI behavior, then land the focused test reliability repair.

Why: The maintainer label requires explicit human handling, and the review environment could not inspect the relevant source or dependency contract.

Before merge

  • Resolve merge risk (P1) - The change relies on jsdom registry internals and call-stack attribution; without local dependency-contract inspection, compatibility with the repository’s pinned jsdom version remains unverified.
  • Complete next step (P2) - A maintainer must review the protected PR after exact-head and dependency-contract verification; no safe automated repair is identified.
Agent review details

Security

None.

PR surface

Tests +190. Total +190 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 190 0 +190
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 190 0 +190

Review metrics

Metric Value Why it matters
Production versus test LOC production +0, tests +190 The submitted diff is confined to test infrastructure and regression coverage, so it does not add runtime product code.

Merge-risk options

Maintainer options:

  1. Verify the jsdom contract before merge (recommended)
    Confirm the repository-pinned jsdom registry representation and run the affected shared-worker lane on the exact head before merging.
  2. Pause if the private seam is unstable
    Do not merge if the needed registry cleanup cannot be tied to a stable, tested jsdom contract.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This is a bounded repair for flaky Control UI test automation rather than a user-facing runtime outage.
  • add merge-risk: 🚨 automation: The PR changes the shared Vitest runner and depends on jsdom internals, so a mismatch could destabilize CI lanes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal test-infrastructure PR is not subject to the external-contributor real-behavior-proof gate; its body nevertheless records after-fix test-lane evidence.

Label justifications:

  • P2: This is a bounded repair for flaky Control UI test automation rather than a user-facing runtime outage.
  • merge-risk: 🚨 automation: The PR changes the shared Vitest runner and depends on jsdom internals, so a mismatch could destabilize CI lanes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal test-infrastructure PR is not subject to the external-contributor real-behavior-proof gate; its body nevertheless records after-fix test-lane evidence.

Evidence

What I checked:

  • Submitted test-only change: The provided PR diff adds jsdom registry tracking tests and modifies the non-isolated runner; the PR body reports no production runtime behavior change. (test/non-isolated-runner.ts:1, 1a1075c801cd)
  • Reported after-fix validation: The PR body reports parallel and single-worker UI runs, the isolated UI lane, and changed-file checks passing after the repair; this could not be independently rerun or inspected locally. (1a1075c801cd)
  • Local inspection unavailable: Read-only shell commands failed before executing with bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted, so current-main source, scoped policy, git history, and jsdom dependency internals were not inspected.

Likely related people:

  • steipete: The available PR context identifies steipete as author of both commits; local feature-history inspection was unavailable. (role: current test-infrastructure proposer; confidence: low; commits: b7aaec330f8f, 1a1075c801cd; files: test/non-isolated-runner.ts, test/jsdom-custom-elements.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the pinned jsdom registry-internal contract and exact-head shared-worker UI lane before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit e7a2d17 into main Aug 14, 2026
133 checks passed
@steipete
steipete deleted the steipete/strange-lovelace-b94412 branch August 14, 2026 06:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
…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
steipete added a commit that referenced this pull request Aug 19, 2026
…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.
steipete added a commit that referenced this pull request Aug 19, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant