Skip to content

test: load @zitadel/sdk-qwik's server build once and lengthen its listener deadline - #2571

Merged
fforootd merged 1 commit into
mainfrom
claude/lucid-lamport-778003
Nov 1, 2026
Merged

fforootd merged 1 commit into
mainfrom
claude/lucid-lamport-778003

Conversation

@fforootd

@fforootd fforootd commented Nov 1, 2026

Copy link
Copy Markdown
Member

Context

Summary

Attempts 2–4 of that run had a warm cache and no optimizer activity. They failed on load, in three specs of src/index.spec.tsx:

  • ZitadelLogin > binds an empty proxyPath as the origin root, matching its attribute: listener for "zitadel-flow-step" never forwarded within 1000ms, all three attempts (2042–2952 ms with the failure screenshot).
  • resuming a server-rendered login > starts its first flow with the purpose the server rendered and > loads the supplied flow on its first request instead of creating one: Test timed out in 15000ms five times, and one pass at 14737 ms.

Cause 1: every server render rebuilt Qwik's server build

  • renderServerLogin (src/__tests__/server-markup.ts) started a new worker per call. The worker started a new Vite server and ran ssrLoadModule on server-login.tsx: 28 modules and about 7 MB of transformed code, over 4 MB of it Qwik's dev core.

  • Each test paid that inside its own 15 s budget. Probes in the worker split one call:

    Phase Idle 450 busy loops
    worker start and imports 54–71 ms 857–1577 ms
    createServer 21–27 ms 30–618 ms
    ssrLoadModule 331–405 ms 8412–10569 ms
    render 5–7 ms 6–16 ms
    resume → first flow step 5–53 ms 6–54 ms
  • So this is load on the server build, not a slow resume. On main at 450 loops the two tests took 9.5–12.3 s of their 15 s; at 700 loops one timed out.

Cause 2: a fixed 1 s deadline on a wait that takes seconds under load

  • dispatchUntilForwarded re-dispatches an event until the wrapper's useVisibleTask$ has wired its listener and the spec's $() callback has run. Under Vitest's dev server, qwikVite uses the segment entry strategy, so that first call also fetches the callback's module. On a busy main thread the task itself runs late.

  • Only ZitadelLogin's copy failed. It is the file's first spec to wait on a visible task. Its Logout and Session twins took 175–398 ms in the same attempts.

  • Busy loops barely slow Chromium on this machine: the spec took under 0.25 s at 450 loops. Throttling Chromium's CPU through CDP does slow it, and at 30× and 40× main fails exactly as CI did: only this spec, never forwarded within 1000ms, at 2555 and 2974 ms. With the deadline lifted, the wait took:

    Chromium CPU throttle Wait Rest of the file
    1× 37 ms passes
    20× 934 ms passes
    30–40× 1227–1766 ms passes
    80× 3277 ms passes
    120× 5153 ms passes
    160× 16431 ms two expect.poll specs fail too
  • At 30–40× the rest of the file takes 10–12 s; in CI's attempts it took 10–18 s. So CI's browser ran at roughly that speed, and 120× is several times slower.

Fix

  • One worker loads the server build once and renders every request, through loadServerLogin, renderServerLogin and closeServerLogin commands. As in the svelte and solid specs, the worker closes its Vite server after loading, and the loaded module keeps rendering. The markup is unchanged: the old and the new worker render byte for byte the same HTML, apart from Qwik's random per-render instance id.
  • resuming a server-rendered login loads the build in beforeAll and stops the worker in afterAll. The hook gets a 60 s budget, which only bounds a hang; the load took 9.7–11.2 s at 450 loops and 13.4–16.5 s at 700. The tests' 15 s timeout stays, and their bodies are unchanged: they still await serverMarkup(props), which is now one fast round trip.
  • The worker is unref()ed, so a run that never reaches afterAll can still exit. With neither unref() nor the close, Vitest waits out its close timed out after 10000ms.
  • dispatchUntilForwarded allows 10 s. That is above the 5.2 s the wait took at the slowest throttle at which the rest of the file still passes. It is also under the 15 s test timeout, so a listener that never attaches still fails with its own message.

This is the pattern #2496 and #2497 used for sdk-svelte and sdk-solid.

Validation

Local loaded runs

  • Setup: 18-core Mac, vitest run --maxWorkers=3 in packages/sdk-qwik, beside N perl -e 'while(1){}' busy loops killed afterwards. The .vitest deps cache was warm, as in CI's failing attempts.
  • "30×" adds a temporary browser command that sets Chromium's CPU throttling through CDP (Emulation.setCPUThrottlingRate). The hook's load times come from a temporary log line in beforeAll. Neither is part of this PR.
Load Code Empty proxyPath (Login) Resume tests Result
450 loops main 39–46 ms 9505–12325 ms 2/2 pass, at 63–82% of the 15 s budget
450 loops this PR 42–228 ms 14–23 ms, 54–57 ms 5/5 pass, 157/157
700 loops main 48 ms 15076 ms Test timed out in 15000ms, 14874 ms 1/1 fails
700 loops this PR 42–285 ms 14–128 ms, 55–368 ms 2/2 pass, 157/157
450 loops + 30× main 2137 ms never forwarded within 1000ms 10686, 10969 ms 1/1 fails
450 loops + 30× this PR 1029–1203 ms 218–538 ms 2/2 pass, 157/157

With #2569, from a cold cache

Deterministic stand-ins (idle)

  • vitest run --testTimeout=300: on main both resume tests time out; this PR passes 157/157, 2/2 runs.
  • Chromium throttled 30×: on main the empty-proxyPath spec fails (never forwarded within 1000ms); this PR passes 157/157, 2/2 runs, that spec at 1371–1497 ms.

Mutation checks (this PR)

  • Drop purpose from loginAttrs: "starts its first flow…" fails (expected { project_id: 'proj-global', …(1) } to match object { purpose: 'register' }).
  • Drop resume-flow-id: "loads the supplied flow…" fails (expected null to be 'flow_123').
  • Drop the zitadel-flow-step listener: the empty-proxyPath spec fails at 10106 ms with listener for "zitadel-flow-step" never forwarded within 10000ms, its own message, not the test timeout.

Other checks

  • corepack pnpm run typecheck in packages/sdk-qwik: 0 errors.
  • biome check packages/sdk-qwik: clean.
  • vitest run idle: 157 passed; the resume tests take 11–12 ms and 53–54 ms, against about 470 ms on main.
  • node scripts/check-changesets-status.mjs --pending --summary, as CI runs it: ok.
  • node scripts/check-pr-title.mjs --title "…": ok.

No gh workflow run ci-turbo.yml dispatch was run for this branch.

Release notes / changeset

No changeset required — no shipped behavior changed.

Notes

  • .github/semantic.yml has no sdk-qwik scope, so the title has no scope.
  • check-changesets-status.mjs --base origin/main reports failed: its test-file pattern does not match vitest.config.ts or src/browser-commands.d.ts. Neither ships (files: ["dist"]), and test: stop Vite reloading @zitadel/sdk-qwik's browser suite mid-run on a cold cache #2569 merged a vitest.config.ts-only change without a changeset.
  • The other 1 s waits in this file (expect.poll, vi.waitFor) held up to 120× throttling, so this PR leaves them alone.
  • The cold load still takes about 11 s at 450 loops, now in the hook. Most of it is Vite's SSR transform of Qwik's dev core. Externalizing dependencies in the worker could cut it, but would change how the server build resolves, so it is not done here.

🤖 Generated with Claude Code

…tener deadline

The resume specs started a worker, a Vite server and Qwik's server build
for every server render, inside each test's 15 s budget: 9.5-12.3 s of it
at 450 busy loops, and a timeout on CI. One worker now loads the build in
the describe block's beforeAll, whose 60 s budget only bounds a hang,
renders every request, and is stopped in afterAll.

dispatchUntilForwarded's 1 s deadline was shorter than the first visible
task and spec segment take on a loaded runner. It is now 10 s, under the
15 s test timeout, so a listener that never attaches still fails with its
own message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 1, 2026 19:02
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Nov 1, 2026 7:05pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-01T19:03:09.420813Z d7670d7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ No Changeset found

Latest commit: d7670d7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewer thoroughly examined the worker protocol, shared-build lifecycle, command registration, deadline change, and import removal, and surfaced no objective defects or unresolved concerns warranting PR comments.

No open issues 🎉

What changed in this PR

This PR hardens the @zitadel/sdk-qwik browser test suite against slow/loaded CI runners. Previously, renderServerLogin spun up a fresh Vite+Qwik worker and ran ssrLoadModule on every server-render call, so each test paid ~10s of server-build cost inside its own 15s budget — causing the resuming a server-rendered login specs to time out and the empty-proxyPath spec to miss a tight 1s listener deadline. The change loads the Qwik server build once in a reused worker and renders each request over a MessageChannel, and lengthens the dispatchUntilForwarded deadline to 10s (still under the 15s test timeout). This mirrors the pattern established for sdk-svelte (#2496) and sdk-solid (#2497). No shipped behavior changes, so no changeset is required (consistent with the changeset decision table).

Changes:

  • Reworked the server-markup worker to compile the build once and serve renders per incoming message, with new loadServerLogin/closeServerLogin lifecycle commands and a reused, unref()ed worker.
  • resuming a server-rendered login now loads the build in beforeAll (60s budget) and tears it down in afterAll, so each test's budget covers only render + resume.
  • Raised dispatchUntilForwarded's deadline from 1000ms to 10_000ms and updated the surrounding comments/error message.
File Description
packages/​sdk-qwik/​vitest.config.ts Registers the new loadServerLogin/closeServerLogin browser commands alongside renderServerLogin.
packages/​sdk-qwik/​src/​index.spec.tsx Loads the server build once via beforeAll/afterAll, scopes serverMarkup to the resume block, and widens the listener deadline to 10s with updated comments.
packages/​sdk-qwik/​src/​browser-commands.d.ts Declares the two new browser command signatures.
packages/​sdk-qwik/​src/​__tests__/​server-markup.worker.mjs Loads the Qwik server build once, closes the Vite server, then renders per message over the transferred reply port.
packages/​sdk-qwik/​src/​__tests__/​server-markup.ts Adds a cached shared-worker loader plus loadServerLogin/renderServerLogin/closeServerLogin using MessageChannel, with graceful close/error handling.
packages/​sdk-qwik/​src/​__tests__/​resume-server-markup.ts Exposes loadServerMarkup/closeServerMarkup wrappers around the new commands.

Review effort: Balanced

Merged via the queue into main with commit 3f6f5fb Nov 1, 2026
23 checks passed
@fforootd
fforootd deleted the claude/lucid-lamport-778003 branch November 1, 2026 19:12
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 1, 2026

This branch was successfully deployed

1 active deployment
Preview — d7670d73 Deployed Nov 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants