Skip to content

fix(runtime): share one lazy load of the session-tabs apply modules across refreshes - #33939

Merged
nwparker merged 2 commits into
mainfrom
nwparker/flake-session-refresh-import-oct26
Oct 26, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/flake-session-refresh-import-oct26

Conversation

@nwparker

@nwparker nwparker commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 0 0 0 0
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13

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

  • refreshWebRuntimeSessionTabsSnapshot lazy-loads snapshot-api, store-patch, tracking-decisions and tracking-lifecycle through 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.
  • The second dynamic import('./web-session-tabs-sync/tracking-lifecycle') for acceptReplayedWebSessionTabsSnapshot is gone; that export is now read from the module already loaded.
  • The import specifiers are unchanged. The production effect is one fewer microtask yield before the accept, plus no repeated import resolution per refresh.

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 first refresh's four imports resolved in about 1ms.
  • The two concurrent refreshes waited 0.6-19s per import.

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 drain vi.waitFor uses 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 and check-changed-code-quality pass.

  • Codex review is clean. An independent review approved with P3 notes only; one of them flags that the web-agent-session-handoff import 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab228971-4b20-47fb-9910-5e4a0672713a
Commits

Reviewing files that changed from the base of the PR and between 77c9cef and d4b1ee1.

Files selected for processing: 1
  • src/renderer/src/runtime/web-runtime-session-snapshot.ts

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a3fde90c-083d-4722-bc11-c7b562d577e9
Commits

Reviewing files that changed from the base of the PR and between 1187abd and 77c9cef.

Files selected for processing: 1
  • src/renderer/src/runtime/web-runtime-session-snapshot.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

A shared promise loader now loads the four session-tab apply modules. Concurrent calls reuse the promise, and a failed load clears the cache so a later call can retry. The snapshot refresh uses the loaded tracking lifecycle module for tracking-generation lookup and replay acceptance.

Priority: Low

Merge Risk: Minimal · up to 77c9c

The session-tab loading change has no identified merge-blocking issue; it is ready for normal merge checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: sharing one lazy load of the session-tab apply modules across refreshes.
Description check Passed The description is complete and relevant. It covers the change, motivation, testing, known failure, scope, and checklist. It does not provide a linked issue, but it explains that the change addresses …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and relevant. It covers the change, motivation, testing, known failure, scope, and checklist. It does not provide a linked issue, but it explains that the change addresses a CI flake and marks the issue as not applicable.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 9185d10 into main Oct 26, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant