#4567: Webchat: canonicalize main session key for /new (fix #4446)
Fixes Web UI `/new` not starting a fresh session (#4446).
Root cause: webchat often sends `SessionKey` as the `main` alias, but server-side session init didn’t canonicalize it to the real main session key. This caused resets to write to the alias while history reads from the canonical key, so the UI appeared unchanged.
## Changes
- Canonicalize explicit `SessionKey` to the real main session key during session init
- Propagate the canonical key into the template context to keep all paths consistent
- Add a test to cover explicit `main` alias canonicalization
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes Web UI `/new` not starting a fresh session by canonicalizing the “main” session alias during session initialization. In `src/auto-reply/reply/session.ts`, the resolved session key is passed through `canonicalizeMainSessionAlias(...)`, and the canonical `SessionKey` is also propagated into the template context so subsequent code paths consistently read/write the same store key. A Vitest regression test was added in `src/auto-reply/reply/session.test.ts` to assert that an explicit `SessionKey: "main"` is canonicalized to the configured main session key (including agent scoping).
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minimal risk; changes are narrowly scoped to session-key normalization and are covered by a regression test.
- The core change (canonicalizing the main session alias) follows an existing utility used elsewhere in the codebase and is applied immediately after `resolveSessionKey`, minimizing behavioral surface area. The additional `SessionKey` propagation into the template context aligns the in-memory/session-store key with what templates/commands see. Only minor test-harness concerns remain (environment assumptions around pnpm in CI/local), but no clear functional regression is apparent from the code changes.
- src/auto-reply/reply/session.test.ts (test environment assumptions)
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#18694: fix(ui): reset session key to main after /new in webchat
by Phineas1500 · 2026-02-17
84.6%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
83.9%
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
81.0%
#19343: Refactor chat state management: reset chat messages and queue on se...
by saurav470 · 2026-02-17
79.0%
#22798: feat(webchat): ChatGPT-style multi-chat threads with generated titles
by opnsec · 2026-02-21
78.9%
#8774: Fix/frontend session key normalization
by zhaodageng · 2026-02-04
78.8%
#6653: fix: persist archived session entry on /new or /reset
by leicao-me · 2026-02-01
77.8%
#22808: test(ui): split baseline browser-test fixes from webchat feature
by opnsec · 2026-02-21
76.9%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
76.9%
#17527: fix(gateway): allow WebChat to attach to main session regardless of...
by Glucksberg · 2026-02-15
76.8%