Archived local agent sessions revert to unarchived after restart (archive state is stored in a per-launch workspace storage)
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Does this issue occur when all extensions are disabled?: Not applicable — the Sessions/Agents view and the archive action are VS Code core (`vs/workbench/contrib/chat/browser/agentSessions`). The affected sessions are the built-in local chat sessions (`vscode-chat-session://local/...`), reproduced with no third-party extensions involved.
- VS Code Version: 1.136.2 (`88e44fa0e00b08f7758b4f6d05632e4fd5e4df6f`, 2026-09-04)
- OS Version: Windows 11 24H2 (build 26100.7840), x64
- GitHub Copilot Chat (built-in): 0.64.1
- Feature surface: Agents / Sessions view
## Steps to Reproduce
1. Use a VS Code window with **no folder/workspace open** (its `workspaceStorage//` folder contains no `workspace.json`; the affected chat sessions are then stored under `globalStorage/emptyWindowChatSessions/`).
2. Create a few local Copilot chat sessions.
3. Archive several of them from the Sessions view (they leave the active list).
4. Fully quit VS Code.
5. Start VS Code again and open the Sessions view.
**Expected:** previously archived sessions are still archived.
**Actual:** every previously archived session is listed as active again, as if it had never been archived. Session content is fully intact — only the archive flag is gone. Re-archiving works until the next restart, after which it is lost again.
## Why this happens (evidence from this machine)
The archive flag for `local` sessions is persisted **only** in workspace-scoped storage, and the storage identifier of a folder-less window changes on every launch, so the saved state is never read back.
### 1. The archive flag lives in workspace-scoped storage
`%APPDATA%\Code\User\workspaceStorage\1789616876269\state.vscdb` → `ItemTable` → key `agentSessions.state.cache`:
```json
[
{"resource":"vscode-chat-session://local/ZjU4Y2ZjNmItMjIzMS00M2FhLTljNjMtMzZkNTUyM2VlZTU5","archived":true,"read":1789617197138},
{"resource":"vscode-chat-session://local/ZmQyNmFhYjAtYzMxYy00MTUyLWFjMjAtZTg5ZTQ4Zjc0Yjlm","archived":true,"read":1789617121650},
... 9 entries with "archived":true in total ...
]
```
The session bodies are meanwhile stored **application-wide**:
```
%APPDATA%\Code\User\globalStorage\emptyWindowChatSessions\.jsonl
```
So the content survives restart, while the archive flag does not.
### 2. The storage folder is per-launch
- Folder name `1789616876269` is a millisecond timestamp = `2026-09-17 11:47:56.269`, and the folder's `CreationTime` is `2026-09-17 11:47:56` — it was created by that launch.
- That folder contains **no** `workspace.json` (a folder-less window).
- It is the **only** numerically named folder in `workspaceStorage/`; the other 51 folders are stable 32-char hashes and all have a `workspace.json`.
- For contrast, the stable agents-workspace folder (`6d97c0b5` → `agent-sessions.code-workspace`) has `agentSessions.state.cache` = `[]`, i.e. no archive state at all.
### 3. Code path
`vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts` (as shipped in `workbench.desktop.main.js`):
```js
static { this.SESSIONS_STORAGE_KEY = "agentSessions.model.cache" }
static { this.STATE_STORAGE_KEY = "agentSessions.state.cache" }
// third argument 1 = StorageScope.WORKSPACE
saveSessionStates(o){ this.storageService.store($4.STATE_STORAGE_KEY, JSON.stringify(e), 1, 1) }
// only flushed when the window saves its state (i.e. on shutdown)
this._register(this.storageService.onWillSaveState(() => {
this.cache.saveCachedSessions(Array.from(this._sessions.values()));
this.cache.saveSessionStates(this.sessionStates);
}));
// archive ownership: provider-owned if the provider supports it, otherwise this workspace-local cache
isArchived(e){
return this.chatSessionsService.canSetChatSessionItemArchived(e.resource)
? !!e.archived
: this.resolveStateEntry(e)?.archived ?? !!e.archived;
}
```
For the local chat provider there is no `setChatSessionItemArchived`, so `canSetChatSessionItemArchived()` is `false` and this workspace-scoped entry is the **only** owner of the archive state. Because the window's storage id is new on each launch, `resolveStateEntry()` finds nothing and `archived` falls back to `false`/`undefined` → the session reverts to active.
By comparison, agent-host sessions (`copilotcli:`) keep their archive state next to the session itself:
```
~/.copilot/session-state//vscode.metadata.json → { "archived": true }
~/.copilot/vscode.session.metadata.cache.json
```
…which is why those sessions keep their archived state across restarts while `local` sessions do not.
### 4. Contributing factor
`saveSessionStates` runs only from `storageService.onWillSaveState`. Any non-graceful exit (update-restart, crash, process kill, OS shutdown) also loses the archive state even without the storage-id change.
### 5. Settings Sync does not compensate
`sync/agents/globalState/*.json` (the agents profile's synced global state) contains only non-workspace-scoped keys (`sessionsListControl.groups`, `sessionsListControl.sortOverrides`, `chatModelPinned`, container visibility, …). `agentSessions.state.cache` is workspace-scoped and therefore never synced, so restoring from another machine/profile does not help either. This matches the observed behaviour that layout/sort/model selections survive while archive state does not.
## Impact
The archive action is not durable for local sessions created in a folder-less window, i.e. the sessions that users of the Agents surface are most likely to accumulate. The archive flag is also the only thing protecting these sessions from cluttering the active list. Users cannot rely on "Archive" as a persistent state, and there is no UI indication that it was dropped.
## Not a duplicate of
- #289199 — umbrella investigation "Agent sessions papercuts". Its checklist contains the exact underlying design item *"Session read/archive state is per-workspace and not per-profile"*, but that issue is an investigation that is now closed, and it does not track this user-visible symptom (archive silently reverting after restart). Filing this as a focused bug so it is actionable/verifiable.
- #317643 — the agents-workspace storage folder being *deleted* by `UnusedWorkspaceStorageDataCleaner`; fixed and released. Here nothing is deleted; a *different* folder is created on each launch.
- #335221, #328188 — the opposite symptom (an existing session missing from the list while its JSONL/index remain intact).
- #334228 — feature request for global (cross-workspace) chat history. Related in direction, but it does not cover archive-state durability.
## Suggested fix direction
1. Persist archive/read/pin state for `local` sessions in **application-scoped** storage (e.g. keyed by session resource in a global memento), mirroring what agent-host sessions already do per session; or
2. Give the folder-less/agents window a **stable** workspace identifier across launches, so the existing workspace-scoped `agentSessions.state.cache` is read back; or
3. At minimum, flush archive state immediately on change instead of only via `onWillSaveState`, and add a migration/adoption step so state recorded under an older id for the same window type is picked up.
## Verification notes
- Reproduced on VS Code 1.136.2 stable / Windows x64. All steps are deterministic here: archive → quit → relaunch → sessions are active again.
- I only inspected my own user data read-only (SQLite `state.vscdb` opened read-only); nothing was modified.
- Happy to attach the relevant `state.vscdb` excerpts, the `workspaceStorage` folder listing, or a screen recording if useful.
Contributor guide
Assessment
This issue has not been assessed yet.