Skip to content

fix: prevent session loss when switching workspaces#790

Merged
benjaminshafii merged 2 commits intodifferent-ai:devfrom
caoergou:fix/session-loss-workspace-switch-750
Mar 7, 2026
Merged

fix: prevent session loss when switching workspaces#790
benjaminshafii merged 2 commits intodifferent-ai:devfrom
caoergou:fix/session-loss-workspace-switch-750

Conversation

@caoergou
Copy link
Contributor

@caoergou caoergou commented Mar 7, 2026

Summary

  • Add guard to prevent clearing sidebar sessions when the session store temporarily returns empty during worker restart/reconnect
  • Fixes issue where sessions disappear from the sidebar when switching between workspaces or refreshing the window

Root Cause

In packages/app/src/app/app.tsx, a createEffect syncs the session store to the sidebar. When a worker restarts or the user switches workspaces:

  1. loadSessions() is called
  2. Server may temporarily return an empty list (before sessions are fully loaded)
  3. Session store is updated to empty via reconcile()
  4. Effect triggers and overwrites sidebar with empty array
  5. Sessions disappear from sidebar

Fix

Added a guard that prevents clearing existing sidebar sessions when the session store becomes empty for that workspace. This preserves existing sessions during the reconnection window while still allowing:

  • New sessions to be added to the sidebar
  • Session deletions to be reflected (since sorted would have fewer items, not zero)
  • First-time users to see "No sessions yet" when genuinely empty

Test Plan

  • Sessions persist across workspace switches
  • Sessions persist after window refresh
  • Sessions persist after app restart
  • New sessions appear correctly in sidebar
  • Deleted sessions are removed from sidebar

Fixes #750
Fixes #735

Add guard to prevent clearing sidebar sessions when the session store
temporarily returns empty during worker restart/reconnect. This fixes
the issue where sessions disappear from the sidebar when switching
between workspaces or refreshing the window.

Fixes different-ai#750, different-ai#735
@vercel
Copy link

vercel bot commented Mar 7, 2026

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

Project Deployment Actions Updated (UTC)
openwork-software Ready Ready Preview, Comment Mar 7, 2026 9:53am

@vercel
Copy link

vercel bot commented Mar 7, 2026

@caoergou is attempting to deploy a commit to the 0 Finance Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

The following comment was made by an LLM, it may be inaccurate:

Extract the guard logic from app.tsx into a testable pure function
to prevent session loss during workspace switches.

- Add `shouldUpdateSidebarSessions` to `lib/sidebar-sessions-guard.ts`
- Add test script `scripts/sidebar-sessions-guard.mjs` with 7 test cases
- Update app.tsx to use the extracted function
- Add `test:sidebar-sessions-guard` script to package.json

The guard prevents the sidebar from being cleared when the server
temporarily returns an empty session list during worker restart/reconnect.

Ref: different-ai#750
@caoergou
Copy link
Contributor Author

caoergou commented Mar 7, 2026

This PR also fixes #761 (duplicate of #750).

Copy link
Member

@benjaminshafii benjaminshafii left a comment

Choose a reason for hiding this comment

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

Reviewed locally: no malicious changes found, targeted guard test passes, and diff is scoped to sidebar session update logic.

@benjaminshafii benjaminshafii merged commit ab2a20c into different-ai:dev Mar 7, 2026
3 of 5 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.

[Bug]多个工作区的情况下,切换工作区session丢失 [Bug]: 工作区会话记录会丢失

2 participants