Skip to content

agentHost: keep a promoted session's read state in sync with its chat - #344129

Merged
Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
agents/vscode-insiders-session-unread-issue
Oct 26, 2026
Merged

Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
agents/vscode-insiders-session-unread-issue

Conversation

@alexdima

@alexdima Alexandru Dima (alexdima) commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #344128

Problem

A session created with Promote to Session goes back to unread constantly: every listSessions refresh marks it unread again, even right after the user opened it. The issue has the wire-level evidence from an Insiders AHP log: the session is announced with status: 1 while its only chat has status: 33, and all 18 refreshes between 09:42Z and 12:22Z report the same.

There are two causes:

  1. Promotion creates the new session with status: SessionStatus.Idle (no IsRead), but the promoted chat keeps its own IsRead bit. Every other path keeps a single-chat session's read state equal to its chat's: the catalog resolver, SessionIsReadChanged, and restore.
  2. Since agentHost: Synchronize session read state from chats #339732, clients mark a session read only through its main chat (chat/isReadChanged), and the host updates the session only when that chat goes from unread to read. The promoted chat is already read, so the read is a no-op and the session stays unread.

Changes

  • AgentHostStateManager.promoteChats: the new session is read if all the chats it takes are read. Tool and hidden chats don't count, same as everywhere else. As a result, root/sessionAdded carries the right status from the start.
  • Repair for sessions already stuck: reading a session's only counted chat now marks the session read even when the chat was already read. It's applied to both host paths that handle chat reads: the loaded path (AgentHostStateManager) and the unloaded path (AgentService). This repairs sessions already in the bad state the next time the user opens them. With a single chat, the "explicitly marked unread" state that the guard protects can't exist: SessionIsReadChanged(false) and markUnreadContribution also mark the sole chat unread. Multi-chat sessions keep the guard. The existing test only the last unread aggregate chat promotes its session to read still checks that.

Not changed, on purpose

  • No read flag written to the database at promotion. The persisted read state is already correct; only the host's in-memory summary from the promotion is wrong, and listSessions overlays it. The new service test shows this: after a restart the session is listed read even without the fix.
  • No client changes. The Agents window's chat-level read path is correct once the host keeps its read state consistent.
  • Moving chats into an existing session (transferChats / transferSession) doesn't recalculate either session's read flag. That's a related but separate path; I'm happy to follow up.

How to test

Manual (Insiders build with "chat.agentHost.moveChats.enabled": true):

  1. In the Agents window, open a Copilot CLI session, add a second chat, send a prompt there and let the turn finish while viewing it.
  2. Right-click the nested chat in the sessions list and choose Promote to Session.
  3. Wait for the next sessions-list refresh, or reload the window. Before: the promoted session shows as unread again. After: it stays read.

Automated: four new tests, each one fails without the fix and passes with it.

Test Without the fix
AgentHostStateManager › a promoted session is read exactly when the chats it takes are announced['copilot:/promoted']: false, expected true
AgentHostStateManager › a redundant read of a sole chat repairs a session left unread no session/isReadChanged; sessionIsRead: false
AgentService › a redundant read of the sole chat of an unloaded session repairs a session left unread sessionRead: false
AgentService › a promoted session is listed read exactly when its chat is, also after a restart (real moveChat → newSession; asserts the listSessions reply that clients apply, after promotion, after a host restart and after restore) promoted[0]: { chat: true, session: false }, expected session: true. That's the exact state in the issue's logs. Restart and restore already pass.

Validation

  • npm run typecheck-client: passed
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentHostStateManager.test.ts --grep "read|promot": 16 passing, 0 failing
  • ./scripts/test.sh --run src/vs/platform/agentHost/test/node/agentService.test.ts --grep "a promoted session|promotes and persists the session when the last unread chat becomes read|a chat read toggle|passive chat read|a redundant read of the sole chat|read toggle|promot" --timeout 30000: 60 passing, 0 failing
  • npm run eslint -- <the 4 changed files>: passed, no warnings
  • Pre-commit hygiene hook: passed
  • The four new tests also ran against the unfixed host code (4f383697191): 4 failing (as expected), with the diffs in the table above.
  • I also ran a throwaway probe (not committed) against the unfixed host code to check the issue's workarounds. Opening the session or Mark as Read leaves it listed unread. Mark All as Read (session-level), with the session loaded or unloaded, and a host restart both list it read.

Commits: 40a0d6d71d7 is the fix plus tests. 665322c5df7 makes the promotion regression test assert the listSessions reply rather than only in-memory state.

Promoting a chat created its new session unread while the chat kept its own read flag. Clients mark a session read through its main chat, and the host only synchronized the session on an unread-to-read chat transition, so the session stayed unread and every session list refresh showed it unread again.

A promoted session now takes the read state of the chats it takes, and a read of a session's sole aggregate chat repairs a session left unread, for loaded and unloaded sessions alike. Multi-chat sessions keep an explicitly unread session on redundant chat reads.

Fixes #344128

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.

🟢 Approval recommended

The focused fixes preserve multi-chat behavior and include regression coverage for both repair paths, promotion, and restart persistence.

No open issues 🎉

What changed in this PR

Fixes #344128 by keeping promoted Agent Host sessions’ read state consistent with their participating chats, preventing unread indicators from returning after refresh.

Changes:

  • Derive a promoted session’s initial read state from its chats, excluding hidden and tool chats.
  • Repair inconsistent single-chat sessions on redundant read actions in both loaded and unloaded paths, while preserving multi-chat behavior.
  • Add four regression tests covering promotion, repair, and restart persistence.

No actionable issues were identified.

File Description
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests unloaded-session repair and promotion across restart.
src/​vs/​platform/​agentHost/​test/​node/​agentHostStateManager.test.ts Tests loaded-session repair and promoted read-state aggregation.
src/​vs/​platform/​agentHost/​node/​agentService.ts Allows redundant reads to repair unloaded single-chat sessions.
src/​vs/​platform/​agentHost/​node/​agentHostStateManager.ts Initializes promoted read state and repairs loaded single-chat sessions.

Review effort: Balanced

The stuck unread state shows in the listSessions reply, which every client applies over its own read state, so the promotion regression test asserts that reply after the promotion, after a restart and after a restore, rather than the in-memory session state only.

Refs #344128

Co-authored-by: Copilot <[email protected]>
Alexandru Dima (alexdima) added a commit that referenced this pull request Oct 25, 2026
…`ripple why` (#344148)

ripple: depend on the content of files that root paths name

A string such as `'src/main.ts'` in a test's fake GitHub tree names an
existing module from the repository root, and ripple linked it like a
dynamic import: to the node standing for the whole module, which depends
on all of it and on everything it loads. So that test depended on all
that the Electron main process starts, the agent host included, and
#344129, which only changes agent host code, ran it alone in WebKit on
macOS. Of the 670 commits of the last week, 175 selected that test this
way, and 31 selected `fuzzyScorer.test.ts`, whose `URI.file(...)`
fixtures name workbench modules.

No module specifier is a path from the repository root, so code reads
the file that such a string names, or the string only looks like a
path. It now reads the file, like the folders that tests read by path:
the code depends on the file's content, also for a module, but not on
what the module loads. Relative and path alias strings, such as entry
points, still reach what the module loads. On the same 670 commits, 190
select fewer tests and none select more; on 63 of them, the browser test
runners have nothing left to run. The README's replay table had drifted
since earlier changes; it now shows the current numbers.

`ripple why --test PATH --base REV [--head REV]` prints how a change
reaches a test that it selects: the path from the test's code to what
the change changed, through declarations, whole modules, packages and
globals, and the code whose use of a name opened each instance method on
the way. It shares the search of `reaches_from`, so it follows the same
rules as selection.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) merged commit 2a83b52 into main Oct 26, 2026
44 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the agents/vscode-insiders-session-unread-issue branch October 26, 2026 11:09
@vs-code-engineering vs-code-engineering Bot added this to the 1.145.0 milestone Oct 26, 2026
Sandeep Somavarapu (sandy081) added a commit that referenced this pull request Oct 26, 2026
* agentHost: keep session read state consistent when chats move

Moving chats into another session (transferChats), promoting chats (promoteChats, source side) or moving a session under another (transferSession) recomputed only the activity bits of the affected sessions. The session-owned IsRead flag stayed as it was, so a source left with only read chats stayed unread (and the multi-chat redundant-read guard kept it so), and a destination that received an unread chat stayed read for listSessions consumers.

After each of these moves the host now marks every affected session read exactly when all its chats counting toward its read state are, through session/isReadChanged, which is persisted like any other host read change. Reorders are unchanged.

Follow-up to #344129 (#344128).

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

* agentHost: keep an explicit Mark as Unread when only read chats move

A move now changes a session's read flag only when it takes an unread chat counting toward read state along: the destination (transferChats, transferSession) becomes unread, and the source (transferChats, promoteChats) read once all its remaining counted chats are. Moving only read chats leaves both flags alone, so a session the user marked unread as a whole stays unread instead of being recomputed as read.

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

* agentHost: test that promoting a read chat keeps an explicit Mark as Unread

A session marked unread as a whole stays unread when only read chats are promoted out of it.

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

---------

Co-authored-by: Copilot <[email protected]>
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.

Session promoted from a nested chat keeps reappearing as unread

4 participants