Skip to content

fix(desktop): auto-switch to new session after deleting active session#2127

Merged
esengine merged 2 commits into
esengine:mainfrom
AtmoOmen:fix/desktop-session-delete-navigation
May 29, 2026
Merged

fix(desktop): auto-switch to new session after deleting active session#2127
esengine merged 2 commits into
esengine:mainfrom
AtmoOmen:fix/desktop-session-delete-navigation

Conversation

@AtmoOmen

Copy link
Copy Markdown
Contributor

Summary

When a user deletes the currently-active session via the sidebar, the UI remained stuck on the now-deleted session instead of navigating to a fresh session. This PR fixes the backend `session_delete` RPC handler to detect when the deleted session is the active one and automatically switch to a new session.

Closes #2126.

Changes

`src/cli/commands/desktop.ts` — `session_delete` handler:

Before After
Delete file, emit `$sessions` If deleted session is active: abort turn, mint new session via `startNewChatInTab`, emit `$session_loaded` + `$sessions`. Otherwise: emit `$sessions` only

Root Cause

The `session_delete` handler only did two things:

  1. `deleteSession(msg.name)` — remove the file from disk
  2. `emitSessions(tab)` — refresh the sidebar list

It never checked whether `tab.currentSession === msg.name`, so when the active session was deleted the frontend's `currentSession` state remained pointing to the now-deleted session. The `$sessions` event only updates the sidebar list — it does not change which session is displayed.

Fix

When the deleted session matches `tab.currentSession`:

  1. `startNewChatInTab(tab)` — aborts any in-flight turn, mints a fresh session for the workspace, rebuilds the runtime, and calls `emitSessions(tab)`
  2. Emit `$session_loaded` with empty messages — this is what tells the frontend reducer to set `currentSession` and clear the message list

When the deleted session is not the active one, behavior is unchanged (`emitSessions` only).

Verification

  • `npm run verify` passes — 295 test files pass, 4 pre-existing failures (web-tools Exa API key / desktop Ink rendering tests) unrelated to this change
  • Desktop debug build (`tauri build --debug`) compiles and produces installers successfully

When the user deletes the currently-active session via the sidebar,
the UI remained stuck on the now-deleted session. Now the backend
detects when the deleted session is the active one and:

1. Aborts any in-flight turn
2. Mints a fresh session for the workspace (reusing startNewChatInTab)
3. Emits \$session_loaded to the frontend so it navigates to the new session

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The core fix is correct and the approach is right — minting a new session and pushing it to the frontend via $session_loaded is exactly how session state should be propagated (the frontend reducer keys off $session_loaded to set currentSession + clear messages), and startNewChatInTab already calls emitSessions, so the sidebar refresh is covered without the else branch's emitSessions double-firing. Zero carryover for a fresh session is correct.

One small consistency gap to close before merge: the canonical session_load path emits $session_loaded and then emitCtxBreakdown(tab) (src/cli/commands/desktop.ts:871). This branch only emits $session_loaded. On the frontend, the $session_loaded reducer resets usage via { ...zeroUsage(), ... }, which zeroes reservedTokens (desktop/src/App.tsx:1051) — so after deleting the active session the context-usage bar reads 0 until the next turn fires a fresh $ctx_breakdown, instead of showing the new session's system+tools baseline.

Please add emitCtxBreakdown(tab); right after the emit({ type: "$session_loaded", ... }) in the active-session branch to match session_load. Otherwise this is good to go.

Add emitCtxBreakdown(tab) call after $session_loaded in the
session_delete active-session branch, matching the canonical
session_load path. Without it, the frontend context-usage bar
reads 0 until the next turn fires a fresh $ctx_breakdown.
@AtmoOmen

Copy link
Copy Markdown
Contributor Author

thanks for review. done now

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Re-reviewed — emitCtxBreakdown(tab) is now emitted right after the $session_loaded in the active-session branch, matching the canonical session_load path, so the context bar no longer reads 0 after deleting the active session. CI green. Thanks for the quick fix — merging.

@esengine esengine merged commit 00ae400 into esengine:main May 29, 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.

桌面端:删除会话后界面仍停留在已删除会话,应自动切换到新会话

2 participants