Skip to content

fix(flow-chat): preserve explicit session selection during restore#1129

Merged
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/fix-session-open-bottom-anchor
Jun 10, 2026
Merged

fix(flow-chat): preserve explicit session selection during restore#1129
limityan merged 1 commit into
GCWing:mainfrom
limityan:yanzhn/fix-session-open-bottom-anchor

Conversation

@limityan

@limityan limityan commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix session restore races where async historical initialization could overwrite a user-selected session or an active workspace after the user had already moved on.

Root cause

FlowChatManager.initializeWorkspace() auto-selected the latest historical session and awaited loadSessionHistory() before calling switchSession(). If the user clicked another session during that await, the stale initialization could still switch back to the auto-selected session. A stricter review also found the same class of issue at workspace scope: an older workspace initialization could continue after a newer workspace became active and then write old workspace/session side effects.

Changes

  • Re-read the active session after historical restore completes and skip the stale auto-switch when the user selected another session during restore.
  • Gate workspace initialization writes with a latest-request key so older workspace initialization cannot overwrite the newer active workspace path.
  • Add AppLayout effect cleanup guards so stale initialization effects do not create sessions, send pending project descriptions, open pending settings, or show stale errors after workspace changes.
  • Add unit coverage for same-workspace user selection and cross-workspace stale initialization.
  • Add a user-only-latest E2E fixture scenario so historical sessions whose latest turn has no model response are validated against the latest visible content.

Validation

Check Result
pnpm --dir src/web-ui run test:run src/flow_chat/services/FlowChatManager.test.ts 4 tests passed
pnpm run type-check:web Passed
pnpm run check:repo-hygiene Passed
pnpm run desktop:build:release-fast Passed
release-fast controlled rapid switch E2E 4 tests passed; target latest visible 2772.0 ms, usable 2982.4 ms; blank/loading/scroll-jump/non-target hold counts all 0
release-fast user-only latest E2E 4 tests passed; first open latest visible 286.5 ms, usable 424.8 ms, full hydrate 1116.0 ms; blank/loading/scroll-jump/non-target hold counts all 0

Risk

  • Normal initialization without user interaction still auto-selects the latest historical session.
  • This does not change remote session loading, history hydration policy, startup gating, or rendering strategy.
  • The E2E timing values above are validation observations for this correctness fix, not a claimed performance improvement.

@limityan limityan force-pushed the yanzhn/fix-session-open-bottom-anchor branch from 4462b6e to 0e54cc4 Compare June 10, 2026 02:44
@limityan limityan merged commit 650d778 into GCWing:main Jun 10, 2026
4 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