Skip to content

test(ui): await web push settle points instead of wall-clock waits - #180235

Merged
RomneyDa merged 2 commits into
mainfrom
test/web-push-bun-settle
Oct 22, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
test/web-push-bun-settle

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes: ui/src/app/web-push.test.tsx > "serializes rapid preference edits without dropping the latest full object" flaking on the Bun UI shard (CI run 39569175257 attempt 1, checks-ui (3/3): expected undefined to be truthy after 1003ms; the same test passed in 103ms on Node).

User Impact

There is no user-visible change. This removes a deterministic-tier CI flake from the Control UI Bun shard.

Why This Change Was Made

Root cause. createWebPushCapability loads web-push.runtime.ts with a lazy import(). In a Vitest worker that import is a module fetch from the Vitest main process: forks over IPC on Bun, threads on Node. The rest of initial reconciliation runs on microtasks, with no timers and no pending mocks. So whether snapshot.preferences is set depends on how fast the runner answers the fetch and schedules the worker. It does not depend on the code under test. The test wrapped that wait in vi.waitFor, whose default 1000ms deadline is much shorter than the 60s test timeout. On the failing shard the 4-vCPU runner had load 5.4, with 3 Bun forks plus Chromium. Sibling tests in the same file were also slow there. For example, the fully event-driven "refreshes routed canonical profile defaults" test took 841ms on Bun and 2ms on Node. A slow import fetch or a stalled worker therefore loses the race against the 1000ms deadline. A longer timeout would only make that race less likely.

Fix. Wait for the real settle points:

  • the next preferences publication (the existing nextPreferencesPublication helper, moved to file scope and shared),
  • a deferred that the Gateway mock resolves when it receives the request being waited for (preferences.set, push.web.vapidPublicKey),
  • or the published read receipt.

Each wait is bounded only by the test signal through withinTest. The same fix applies to the six sibling tests (two of them are the it.for Settings cases) whose first wait was gated on the lazy import. Each of them fails the same way under the reproduction below. The assertions are unchanged. Assertions that used to be waitFor conditions are now direct expectations after the settle point.

Evidence

  • Reproduced the CI failure deterministically. I added a scratch Vite plugin (not committed) that delays the main process's answer to the worker's fetch of web-push.runtime.ts by 1.1s. I ran the target test alone under the pinned Bun with OPENCLAW_VITEST_FS_MODULE_CACHE=0:
    • before: 10/10 failed with expected undefined to be truthy at 1004–1010ms, which matches the CI signature
    • after: 10/10 passed at about 1.12s
  • Same harness, per test. Before, 7 more tests failed: "preserves initial reconciliation failures…", "retires pending reconciliation…", "reruns full reconciliation…", "ignores stale reconciliation…", "ignores a stale preference action…", "keeps the current Gateway error…", and both "resets a mismatched browser subscription…" cases. After, every test in the file passed alone, and 5/5 full-file runs passed.
  • Plain Bun. Before the change, an unloaded Bun run of the target test took about 103ms (two 50ms waitFor polls) and never failed locally, even under CPU stress. After the change, 20/20 Bun runs passed and the target test took 1–5ms.
  • pnpm test ui/src/app/web-push.test.tsx --maxWorkers=1 wall time is 3.4s on Node and 2.7s on Bun. Vitest reports a duration of 1.7s on Node and 1.2s on Bun for 23 tests. There is no added CI cost, and the file runs faster because the waitFor polling intervals are gone.
  • pnpm tsgo:ui, oxlint on the file (including max-lines, now 999 of 1000 counted lines), run-format --check, and git diff --check are all clean. Autoreview (Codex, P2 threshold) came back scoped-clean.
  • Does not cherry-pick cleanly onto origin/release/2026.10.6: the file there is still ui/src/app/web-push.test.ts and its tests have diverged (it has "keeps subscribers independent…" and "schedules initial reconciliation…" and calls vi.resetModules()). A release backport needs a manual port of the same settle-point pattern.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@RomneyDa

Copy link
Copy Markdown
Member Author

Inherited red: checks-ui (2/3) fails in ui/src/pages/chat/components/chat-details-output-intent.test.tsx (from #179729), a file this PR does not touch. On a clean main checkout at 317f939, pnpm test ui/src/pages/chat/components/chat-details-output-intent.test.tsx --maxWorkers=1 fails the same 5 tests. Landing with the admin exception; the main fix is tracked separately.

@RomneyDa
RomneyDa merged commit 1bfe96f into main Oct 22, 2026
67 of 70 checks passed
@RomneyDa
RomneyDa deleted the test/web-push-bun-settle branch October 22, 2026 03:29
RomneyDa added a commit that referenced this pull request Oct 22, 2026
…80235)

Release adaptation: release/2026.10.6 keeps these tests in
ui/src/app/web-push.test.ts with different cases, uses vi.resetModules(),
and has no snapshot.read receipt, so the main change was ported by hand.
Each vi.waitFor that waited on state behind the lazy web-push runtime import
now settles on the capability publication, a deferred resolved by the Gateway
mock when the awaited request (preferences.set, the VAPID key) arrives, or the
Settings reconcile publication, bounded only by the test signal. The release
helper nextPreferencesPublication is hoisted and shared; the lazy runtime
failure test, which the release test order makes the first cold import, is
also settled on its publication.

(cherry picked from commit 1bfe96f)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…penclaw#180235)

* test(ui): await web push settle points instead of wall-clock waits

* test(ui): type the Settings read deferred for the ui-app test project
tideclaw-bot pushed a commit that referenced this pull request Nov 4, 2026
Backport #180235 with release-native publication settlement.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 20554c17d7c0eba60585aaacff7d47ebf73c7c6b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant