Skip to content

agentHost: keep session read state consistent when chats move - #344244

Merged
Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
agents/move-keeps-read-state
Oct 26, 2026
Merged

Sandeep Somavarapu (sandy081) merged 3 commits into
mainfrom
agents/move-keeps-read-state

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #344129 (#344128).

Problem

#344129 makes Promote to Session keep the new session's read state right. Its description lists what it leaves alone: moving chats into an existing session doesn't recalculate either session's read flag. Promotion has the same problem on the source side.

A session's read flag (IsRead) belongs to the session. transferChats, promoteChats and transferSession (Move Chats Block 4, #341788) recompute only the activity bits from the chats (_applySessionAggregate → _mergeSessionStatus). Since #339732 nothing else recalculates the flag after a move:

  1. Moving or promoting the only unread chat out of a multi-chat session leaves the source unread, although all its remaining chats are read. Opening those chats doesn't fix it: a redundant read of a multi-chat session's chat is guarded and doesn't mark the session read. It stays unread after a host restart and after restore too.
  2. Moving an unread chat into a read session leaves the destination read in the host's listSessions reply while it's loaded.
  3. Moving an unread session under a read session (vscode/moveSession → transferSession) leaves the destination read.

Changes

  • AgentHostStateManager: a move now updates read flags only when it takes an unread chat along. Tool and hidden chats don't count (isChatInSessionReadAggregate).
    • Destination (transferChats, transferSession): becomes unread.
    • Source (transferChats, promoteChats): becomes read once all its remaining chats are read.
    • Only read chats moving: both flags stay as they are, so a session the user marked unread as a whole (Mark as Unread on a multi-chat session) stays unread.
    • When a flag changes, the host dispatches session/isReadChanged. Clients see it in the same synchronous step as the move.
  • Persistence: like every other host read change (SessionFlagsContribution), not in the move's database transaction.
    • If the host crashes between the move's commit and that write, a source that should have become read stays unread; Mark as Read fixes it.
    • A destination with an unread chat is listed unread after a restart anyway.
  • Unchanged:
  • No changes to: the protocol or clients. Moves need both sessions loaded, so there's no unloaded path.
  • Docs: the agentHost AGENTS.md Moves section now says this.

How to test

Agents window with "chat.agentHost.moveChats.enabled": true, Copilot CLI sessions:

  1. In session A, add two nested sessions. Mark one of them (A3) unread from its context menu.
  2. Drag A3 onto another, read session B. Reload the window and open the session picker (Show Sessions Picker).
    • Before: A is in the "unread" group, and stays there after opening its remaining chats.
    • After: A is read and B is unread.
  3. Mark a single-chat session C unread and drag it onto a read session D, then reload.
    • After: D is unread. The host log shows host-sent session/isReadChanged right after session/chatsReordered.

The Agents window's own sessions list already treats a session with an unread chat as unread, so it shows bugs 2 and 4 correctly even before the fix. They're wrong in the host's listSessions reply, which the service tests check.

Validation

  • 9 new tests, each with one assert.deepStrictEqual. All fail without the fix except three that check behaviour which must not change: the reorder test and the two marked-unread tests. The marked-unread tests failed against this PR's first version, which made such sessions read.
    • State manager: an unread chat moving (source read, destination unread), an unread or read session moving, promotion, and a session marked unread as a whole that stays unread when a read chat moves in, moves out or is promoted out. Each checks the state before and after and the session/isReadChanged envelopes.
    • Service (real moveChat / moveSession): what listSessions reports after the move, after a host restart and after restore, for a chat move, a promotion, a session move and a reorder.
  • ./scripts/test.sh --runGlob "vs/platform/agentHost/test/node/**/*.test.js": passed, 13534 passing, 0 failing, 75 pending.
  • Mutation checks: each one makes the expected tests fail. They remove the call in transferChats / transferSession / promoteChats, count tool or hidden chats (moved or staying), drop the source or destination update, dispatch when nothing changed, or drop the "an unread chat moved" condition.
  • npm run eslint -- <changed .ts files>: passed.
  • npm run typecheck-client: passed.
  • Pre-commit hygiene hook: passed.
  • Live: Code - OSS Agents window, isolated profile and COPILOT_HOME, Claude/Codex disabled; the scenario above before and after the fix, including a window reload.
  • Independent code review: approved, including a re-review of the rule change in the second commit. It found that promotion's source had the same problem; that's fixed here.

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]>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 10:24
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.145.0 milestone Oct 26, 2026
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]>

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 narrowly scoped changes reuse existing read-state mechanisms and include regression coverage for each affected operation.

No open issues 🎉

What changed in this PR

This PR extends the earlier promotion read-state fix to other chat moves, keeping Agent Host session read flags consistent with their participating chats.

Changes:

  • Recalculates affected sessions’ read flags after transfers and promotions, using existing read-change actions for notification and persistence.
  • Adds eight regression tests covering move behavior, restart and restore persistence, and unchanged read state after reordering.
  • Documents the read-state rules for moves.

No actionable findings remain.

File Description
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Tests listed read state after moves, restarts, restores, and reorders.
src/​vs/​platform/​agentHost/​test/​node/​agentHostStateManager.test.ts Tests aggregate read flags and emitted read-change actions.
src/​vs/​platform/​agentHost/​node/​agentHostStateManager.ts Synchronizes affected sessions’ read flags after moves.
src/​vs/​platform/​agentHost/​AGENTS.md Documents move-related read-state behavior.

Review effort: Balanced

…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]>
@sandy081
Sandeep Somavarapu (sandy081) merged commit 9dc0872 into main Oct 26, 2026
44 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the agents/move-keeps-read-state branch October 26, 2026 12:08
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.

3 participants