← Back to PRs

#18694: fix(ui): reset session key to main after /new in webchat

by Phineas1500 open 2026-02-17 00:03 View on GitHub →
app: web-ui stale size: S
## Summary Fixes #18078 When a user sends `/new` in the webchat Control UI, the server creates a new session and the chat run completes. The UI refreshes the sessions sidebar via `loadSessions()`, but **never resets `host.sessionKey`** back to the main session. This means subsequent messages are still routed to whichever sidebar session was previously selected — not the newly created main session. - After `/new` completes (state `"final"` + `refreshSessionsAfterChat` flag), reset `host.sessionKey` to the main session key from `hello.snapshot.sessionDefaults` - Also call `setLastActiveSessionKey()` so the setting persists across page reloads - Falls back to `"agent:main:main"` if no session defaults are available ## Test plan - [x] Added unit test in `app-gateway.node.test.ts` verifying `sessionKey` resets to `mainSessionKey` after a `/new` chat run completes - [x] All 4 existing + new gateway tests pass (`pnpm vitest run --config vitest.node.config.ts src/ui/app-gateway.node.test.ts`) - [ ] Manual: Open Control UI → select a sidebar session → send `/new` → verify the session key resets and next message goes to the main session <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes webchat Control UI bug where `sessionKey` wasn't reset after `/new` command, causing subsequent messages to route to previously-selected sidebar sessions instead of the main session. **Key changes:** - Added logic in `app-gateway.ts:227-237` to reset `host.sessionKey` and persist via `setLastActiveSessionKey()` when a `/new` chat completes (when `refreshSessionsAfterChat` flag is set) - Falls back to `"agent:main:main"` if `sessionDefaults.mainSessionKey` is unavailable - Added unit test verifying `sessionKey` resets to main after `/new` completes <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - Clean, focused bug fix that addresses a specific routing issue. The implementation properly integrates with existing session management patterns, includes a test verifying the core behavior, and has a sensible fallback value. The change is isolated to the `/new` command flow and doesn't affect other chat functionality. - No files require special attention <sub>Last reviewed commit: e45ff4f</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs