Repository navigation
fix(runtime): share one lazy load of the session-tabs apply modules across refreshes - #33939
Conversation
…cross refreshes Concurrent refreshes each re-imported the same four modules. Under vitest, overlapping imports of a vi.mock'd module share one importer callstack and fall through to the real module, so the second and third of three rapid browser creates loaded and transformed the real session-tabs graph inside the test (about 20-28s) instead of using the mocks.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 6 minutes. View limit details
No actionable comments were generated in the recent review.
|
ELI5
When a web client refreshes its tab list, it loads a few helper modules on demand. Several refreshes running at once each loaded them separately. That works in the app, but in tests it made vitest load the real modules instead of the test's fakes, which took about 20-28 seconds. Now all refreshes share a single load.
What Changed
refreshWebRuntimeSessionTabsSnapshotlazy-loadssnapshot-api,store-patch,tracking-decisionsandtracking-lifecyclethrough one module-level promise, so concurrent refreshes share one load. The promise is cleared on rejection, so a failed load is retried on the next refresh, as before.import('./web-session-tabs-sync/tracking-lifecycle')foracceptReplayedWebSessionTabsSnapshotis gone; that export is now read from the module already loaded.Why
web-runtime-session-browser-create-staging.test.ts> "keeps three rapid creates distinct when the host mints every page id" took 21-28s run alone on main, against a 30s timeout. I instrumented it:The cause is in vitest 5's
requestWithMockedModule. It pushes the mock id onto a callstack shared by the importing module, and its own comment says this "will not work if user does Promise.all(import(), import())". An overlapping request for the same mocked module sees its id in that callstack and falls through to importing the real module. That transforms the real session-tabs graph inside the test, and those callers get the real modules instead of the mocks.Pre-importing the modules from the test didn't help, because the shared-callstack check runs on every overlapping request. Serializing the creates would stop the test from covering concurrent creates. I didn't raise the timeout or add retries.
Linked Issue
N/A, CI flake. No issue.
Visual Proof
N/A. No UI change; the only behaviour change is shared module loading.
Testing
The staging file passes with all 17 tests: the target test went from 21-28s to 0ms, and its known-page-id sibling also takes 0ms.
I ran all 126 renderer test files that import or mock the changed module or the four lazy modules: 1040 tests pass and 1 fails. The failure is
worktree-activation-empty-remote.test.ts> "creates a host terminal when waking an empty remote workspace". It also fails on main at the same load (twice, at about 1.1s): its drainvi.waitForuses vitest's default 1s timeout while the cold first load of the real session-tabs modules is still running. It's a pre-existing load flake that this PR neither causes nor fixes.The full transitive importer set is about 2.5k renderer tests, so CI covers the rest.
The target test still fails if rehoming breaks: it asserts that the three staged pages map to the three distinct host page ids.
pnpm tc:web, type-aware oxlint andcheck-changed-code-qualitypass.Codex review is clean. An independent review approved with P3 notes only; one of them flags that the
web-agent-session-handoffimport in the same function could hit the same vitest problem, though nothing triggers that today.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Renderer-only and platform-neutral. SSH/remote paths use the same refresh. No wire or compatibility change. The four modules are already statically imported elsewhere in the renderer, so chunking doesn't change.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)