Skip to content

agentHost: keep the default chat title in sync with a session rename - #337308

Merged
Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
sandy081/agents/fix-stale-default-chat-title-after-session-rename
Sep 22, 2026
Merged

Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
sandy081/agents/fix-stale-default-chat-title-after-session-rename

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #336995
Fixes #326054

Renaming a session from the sessions list left the session header showing the old title. Worse, clicking into that header and pressing Enter renamed the default chat, which mirrors back onto the session and overwrote the rename — silent data loss.

Why it happened

A session whose only chat is its default chat has no independently titled chat: the header renders the session title. But the default chat still owns persisted title metadata, written whenever something renamed it directly — the rename_chat tool, the chat header, or an automatic title.

A session-scoped rename (the sessions list path) updated only the session, so that chat metadata went stale. On restore it was seeded back as the chat's own title, making the divergence sticky: the list showed the new name, the header showed the old one, and committing the header handed the stale title back to the session.

This regressed in #331509 (commit 771cd9d), which removed the isDefaultChat && _isOnlySessionChat(session) guard from _renameChatFromTool — after that, a single-chat session could get an independent title stamped onto its default chat.

What changed

SessionTitleContribution._retitleSoleDefaultChat mirrors a session rename down onto the sole default chat, updating both live state (so the open header updates immediately) and persisted metadata (so it survives restore).

Restoring the old guard alone would not have been sufficient: it only covers the rename_chat tool path, while the UI header rename flows through onDidApplyClientAction. Handling it in onDidApplyClientAction covers every session-channel rename — sessions list, tool, or header — and repairs sessions already broken on disk the next time they are renamed.

Sessions that own peer chats are skipped: their default chat is independently titled by design.

Notes for reviewers

  • The four metadata writes are two pairs — the title plus a companion …SOURCE key marking it user-set — written to both the chat's own database and the session's database keyed by chat. onHydrateChat reads them in that order on restore, so writing only one would leave the other as a stale fallback.
  • state.defaultChat ?? buildDefaultChatUri(session) covers state where defaultChat is not yet populated.

Validation

  • New test a session rename retitles the sole default chat in the live session and across restore covers live state, persisted metadata, and restore.
  • Confirmed falsifiable: removing only the _retitleSoleDefaultChat call makes the new test fail with exactly the bug signature (defaultChatTitle: 'Agent title' instead of 'User title').
  • agentHost/test/node: 5678 passing, 0 failing.
  • agentHostChatContribution: 439 passing, 0 failing.
  • eslint, hygiene and typecheck-client all clean.

Renaming a session from the sessions list left the session header showing
the old title, and committing that header handed the stale title back to
the session, silently overwriting the rename.

A session whose only chat is its default chat has no independently titled
chat - the header shows the session title - but the chat still owns
persisted title metadata written whenever something renamed it directly
(the rename tool, the chat header, an automatic title). A session-scoped
rename updated only the session, so that metadata went stale and restore
seeded it back as the chat's own title.

Mirror a session rename down onto the sole default chat in both live state
and persisted metadata. Handling this in onDidApplyClientAction covers
every session-channel rename rather than just the rename-tool path, and
repairs already-affected sessions the next time they are renamed. Sessions
that own peer chats are skipped: their default chat is independently
titled by design.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The regression test aliases distinct production databases, leaving the critical cross-store persistence behavior inadequately covered.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Synchronizes sole default-chat titles with session renames to prevent stale titles and accidental overwrite.

Changes:

  • Mirrors session renames into live and persisted default-chat state.
  • Adds restore-focused regression coverage.
File Description
sessionTitleContribution.ts Synchronizes sole default-chat titles and metadata.
agentService.test.ts Tests rename behavior across restore.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…tract

Two follow-ups to the sole-default-chat rename fix.

The new test passed one TestSessionDatabase to createSessionDataService,
which returns that same database for every channel. That aliased the
session and chat stores, so onHydrateChat could read the session's
customTitle and the test still passed with the chat-local writes removed.
Use createPerSessionDataService() and assert both databases, including the
companion source keys, so all four writes are independently covered.

Retitling the default chat also dispatches SessionChatUpdated on the
session channel - that is how a live header updates - so a session rename
now replays one more action than the protocol contract expected.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) merged commit 6c86dd3 into main Sep 22, 2026
33 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the sandy081/agents/fix-stale-default-chat-title-after-session-rename branch September 22, 2026 19:18
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch label Sep 22, 2026
@vs-code-engineering vs-code-engineering Bot added release-cherry-pick Automated cherry-pick between release and main branches and removed ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch labels Sep 22, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-cherry-pick Automated cherry-pick between release and main branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent session titles are unexpectedly lost Renaming session should rename default chat

4 participants