BitFun icon indicating copy to clipboard operation
BitFun copied to clipboard

fix(startup): harden identity listener and rapid-switch guard

Open limityan opened this issue 5 months ago • 0 comments

Summary

  • Fix the non-blocking workspace identity listener path so both async registration rejection and synchronous listen() throw restore listener state, keep startup usable, and do not leave an unhandled promise.
  • Fix the rapid-switch performance guard so it always measures the configured target session. If the target is already active, the spec first switches to another requested session outside the measured target click instead of silently changing the target.
  • Keep this PR scoped as a follow-up to #1221. It does not claim additional end-to-end performance gain beyond the already-merged startup/session optimization; it prevents a real edge-case startup failure and a misleading rapid-switch measurement path.

Refs #949

Impact And Data

This PR is a quality/measurement fix on top of #1221, which has already merged. The normal startup/session hot path is not intentionally changed except for failure handling around listener registration.

Latest release-fast guard data from the same content before the final rebase showed the optimized scenarios remain within the accepted range:

Scenario Latest Guard Result Notes
Cold startup to shell ready 534.8 ms Still below the issue-created baseline; #1232 does not claim a new startup gain
First open long session, latest text usable 255.7 ms loading/blank/scroll jump = 0/0/0
First open long session, full hydrate end 562.3 ms clickToFullHydrateEndMs, excludes 3000 ms observation window
Warm reopen long session, latest text usable 245.3 ms loading/blank/scroll jump = 0/0/0
Rapid switch target click to latest text usable 195.1 ms target session remained perf-long-session-000; loading/blank/scroll jump = 0/0/0
Rapid switch click action completed to latest text usable 164.3 ms target produced fresh restore timings

The main correctness issue found during review was that the rapid-switch guard could previously switch the measured target away from the configured long session when that target was already active. That made the guard capable of testing a short session while reporting a rapid-switch long-session path. This PR fixes that before relying on the metric.

Risk And Compatibility

  • Workspace identity listener failure handling is now more defensive; successful listener registration behavior is unchanged.
  • Rapid-switch E2E setup may perform one pre-measurement click when the configured target is already active. That setup is intentionally outside the measured target click and is recorded through activeSessionIdAtStart / requested session ids.
  • No desktop close/minimize-to-tray behavior, remote workspace protocol, ACP behavior, session storage format, or product UI behavior is intentionally changed.

Verification

Current post-rebase checks:

  • pnpm --dir src/web-ui run test:run src/infrastructure/services/business/workspaceManager.test.ts (7 tests)
  • pnpm --dir src/web-ui run test:run src/app/startup/startupPerformanceContract.test.ts (39 tests)
  • pnpm run type-check:web
  • git diff --check gcwing/main...HEAD

Release-fast guard run used for the table above:

  • pnpm run desktop:build:release-fast
  • pnpm --dir tests/e2e run fixture:long-session -- --workspace D:\workspace\BitFun\.tmp\e2e-perf-workspace-reload-20260616215729 --session-count 80 --long-turns 80 --last-active-at-base 1800000000000 --last-active-step-ms 1000
  • pnpm run e2e:test:perf:release-fast with BITFUN_E2E_PERF_SESSION_ID=perf-long-session-000 and rapid switch ids perf-long-session-001,perf-long-session-002,perf-long-session-000 (4 passing)

Known local limitation: pnpm --dir tests/e2e exec tsc --noEmit --pretty false still fails on existing project-wide WDIO type and /src/... dynamic import resolution issues, including files outside this PR.

limityan avatar Jun 16 '26 16:06 limityan