Repository navigation
agentHost: apply chat read toggles without restoring the session - #341869
Merged
Sandeep Somavarapu (sandy081) merged 5 commits intoOct 15, 2026
Merged
Conversation
A chat/isReadChanged for a chat of an unloaded session restored the whole session first, and one for an unmaterialized peer resolved its history. Both routed through the per-client dispatch queue, so every later action from that client waited behind a restore that takes minutes for a large session, leaving chats "stuck unread". - A registered chat without materialized state takes the read flag on its summary; the session read aggregate is synchronized as before. - A chat of an unloaded session (owner from recorded ownership) has its read state persisted, published on the surfaced summary and folded into the session read aggregate through the passive catalog path, which now also carries the chat's read state so a legacy central payload cannot restore the previous value. A restore racing the write is joined and re-applied; a session being deleted rejects the toggle without writing. - Passive session metadata re-reads the surfaced summary after persisting so a concurrent passive update is not overwritten. - The listSessions summary projection is extracted unchanged into toListedSessionSummary so tests drive the real cold listing path. - Unknown chats are still rejected; per-client ordering is unchanged. Co-authored-by: Copilot <[email protected]>
Contributor
|
Base:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Concurrent passive updates and mid-write restoration can leave session read aggregates inconsistent with chat state.
2 open findings
What changed in this PR
Makes chat read toggles metadata-only operations, avoiding session restoration and delays to later client actions.
Changes:
- Adds passive persistence and aggregate updates for unloaded sessions.
- Applies read flags to registered chat summaries without loading history.
- Adds regression coverage and extracts the existing listing projection for testing.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/agentService.test.ts |
Adds passive-toggle, persistence, fallback, and race tests. |
src/vs/platform/agentHost/node/protocolServerHandler.ts |
Extracts the unchanged session-listing projection. |
src/vs/platform/agentHost/node/agentService.ts |
Adds passive chat-read dispatch and catalog synchronization. |
src/vs/platform/agentHost/node/agentHostStateManager.ts |
Supports read toggles without materialized chat history. |
src/vs/platform/agentHost/AGENTS.md |
Documents metadata-only read handling. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Restore projected an archived catalog chat as IsArchived only, dropping its read state, so the restore clamp saw an unread chat and forced the session unread. Sessions with archived peers came back unread on every restore. - The cached chat catalog now carries each chat's recorded read state, and restore projects an archived chat with it (unrecorded counts as read, as elsewhere in restore). A genuinely unread archived chat still restores the session unread. - Cached peer imports (no local database, legacy migration) keep an explicitly unread chat unread instead of forcing it read. Co-authored-by: Copilot <[email protected]>
roblourens
previously approved these changes
Oct 15, 2026
Co-authored-by: sandy081 <[email protected]>
Vritant Bhardwaj (vritant24)
previously approved these changes
Oct 15, 2026
…tores Two races in the restore-free read path could leave a session's read aggregate wrong: - Concurrent clients: client A read the last unread peer and paused while persisting the session aggregate; client B marked another chat unread, saw the still-unread session and skipped the aggregate; A then published its stale read state. Passive read/archive updates for an unloaded session (chat- and session-level) now run one at a time per session. - Restore: a restore starting during a passive write could read the old session flag, pause on default-chat history, then register the peer with its new flag; replaying the chat toggle saw it already read and skipped the unread-to-read aggregate transition. A restore now waits for the queued passive update before reading, and an update queued behind a restore that is already reading waits for it and applies through the live path, where the aggregate is computed from the restored chats. Tests that read passive archive results after a fixed sleep now await the dispatch instead. Co-authored-by: Copilot <[email protected]>
This reverts commit 459a482.
roblourens
approved these changes
Oct 15, 2026
Sandeep Somavarapu (sandy081)
deleted the
agents/fix-chat-read-toggle-stall-issue
branch
October 15, 2026 23:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
In the Agents window, marking a chat read could take seconds to minutes to apply after a restart, and chats looked stuck unread. A real wire log showed
chat/isReadChangedactions sent between 19:04:46 and 19:07:44 all applied at 19:08:27; later ones took 4–5 s, and one took 78 s.Cause:
AgentService.dispatchActionrouted aChatIsReadChangedfor a chat of an unloaded session, or for a peer whose history isn't loaded yet, through a full session restore and peer materialization. Because client actions run through a per-client queue, every later action from that client waited behind the restore (head-of-line blocking), including actions for unrelated, already-loaded sessions. This predates the Move Chats work: per-chat read toggles (#339500) combined with lazy peer restore (#329071).Change
Read state is metadata, so it no longer needs a restore:
_applyPassiveChatReadresolves the owner from recorded ownership (never the chat URI), then:chatReadpassive update, applied to the chats before the aggregate;AgentHostStateManagerapplies the read flag to the registered chat summary without resolving its history. Loading the history later keeps the flag._applyPassiveSessionMetadatare-reads the surfaced summary after persisting, so a concurrent passive update isn't overwritten.listSessions' per-session mapping moved into the exported puretoListedSessionSummary(unchanged code) so tests can drive the real cold-listing path.Also fixes
Restoring a session forced it unread whenever it had an archived chat. The restore projection gave an archived catalog chat a status of
IsArchivedonly, dropping its read state, so the restore clamp saw an unread chat. Sessions with many archived peers came back unread on every restore: the same "stuck unread" symptom.Validation
Repro with a 500 ms restore barrier (a cold peer toggle, then an unrelated toggle on a loaded session, then an unknown chat, all from one client):
The same holds for a session that has only been listed on a fresh host (legacy and normalized catalogs).
All on this head, at load < 20:
./scripts/test.sh --runGlob "**/agentHost/test/node/**/*.test.js": passed, 11226 passing / 76 pending / 0 failing.agentService.test.ts: passed. Coverage:npm run typecheck-client: passed.npm run eslint -- <changed files>: passed. Hygiene: passed.npm run valid-layers-check: passed.