Skip to content

Add APPLICATION_SHARED storage scope for cross-app state sharing - #311317

Merged
Sandeep Somavarapu (sandy081) merged 31 commits into
mainfrom
sandy081/main-scorpion
Apr 22, 2026
Merged

Sandeep Somavarapu (sandy081) merged 31 commits into
mainfrom
sandy081/main-scorpion

Conversation

@sandy081

@sandy081 Sandeep Somavarapu (sandy081) commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

Implements #311337

Summary

Introduces a new StorageScope.APPLICATION_SHARED that stores state in a separate SQLite database shared between VS Code and the Sessions (Agents) app. This enables both apps to read/write shared state (e.g., workspace trust) with real-time cross-process change notifications.

Architecture

New Storage Scope

StorageScope.APPLICATION_SHARED = -2 — a new scope alongside APPLICATION, PROFILE, and WORKSPACE. Callers use it like any other scope and can independently choose StorageTarget.USER (synced) or StorageTarget.MACHINE (local-only).

Storage Location

The shared database lives at ~/<dataFolderName>-shared/sharedStorage/state.vscdb (e.g., ~/.vscode-insiders-shared/sharedStorage/state.vscdb). This is a dedicated folder outside either app's user data directory, configurable via --shared-data-dir CLI argument.

  • IEnvironmentService.appSharedDataHome — URI pointing to the shared data root
  • WAL mode enabled on the SQLite database for concurrent read/write access across processes

Cross-App Change Notifications

Uses ICrossAppIPCService (Electron's cross-app IPC via Mach ports on macOS) as the primary mechanism for instant change notifications between VS Code and the Sessions app. When one app writes to the shared storage, it sends a sharedStorage:changed IPC message with the changed/deleted keys. The sibling app receives it and fires onDidChangeItemsExternal events.

Messages received before storage initialization are ignored to avoid processing stale queued messages on startup.

Settings Sync Integration

APPLICATION_SHARED keys are included in the global state sync payload with a scope field for correct round-tripping:

  • Read: readStorageData() includes APPLICATION_SHARED keys for the default profile only
  • Write: Keys are routed to the correct scope based on the payload's scope field
  • Non-default profiles: APPLICATION_SHARED keys are skipped entirely (not downgraded)
  • Wire format: IStorageValue.scope is optional and defaults to PROFILE for backward compatibility

Migration Example

Workspace trust storage key migrated from APPLICATION → APPLICATION_SHARED with explicit data migration (reads from old scope, writes to new, removes from old).

Key Files Changed

Area Files
Storage scope & abstract service storage.ts — enum, events, key targets, flush/log
IPC (client) storageIpc.ts — applicationShared flag, ApplicationSharedStorageDatabaseClient
IPC (server) electron-main/storageIpc.ts — routing via applicationShared flag
Main process storage storageMain.ts — ApplicationSharedStorageMain, SharedSQLiteStorageDatabase
Main service storageMainService.ts — applicationSharedStorage lifecycle
Renderer storage storageService.ts (common), storageService.ts (browser)
Environment environment.ts, environmentService.ts — appSharedDataHome
SQLite node/storage.ts — WAL mode support, getDataVersion()
Sync globalStateSync.ts, userDataSync.ts, userDataProfileStorageService.ts
Workspace trust workspaceTrust.ts — migrated to APPLICATION_SHARED
CLI argv.ts, cli.ts — --shared-data-dir, --transient support
Layout/Memento layout.ts, memento.ts — new scope handling

@github-actions

github-actions Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 32ccba70 Current: f1ac4162

Changed (5)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Dark
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after
editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after
agentSessionsViewer/CompletedUnread/Dark
Before After
before after
agentSessionsViewer/CompletedUnread/Light
Before After
before after

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.

Pull request overview

This PR introduces an application-shared storage scope intended to persist state across all profiles/workspaces and share it between VS Code and the Sessions app, wiring it through storage backends (browser/remote/electron-main) and user data sync.

Changes:

  • Add StorageScope.APPLICATION_SHARED and plumb it through IStorageService, mementos, storage IPC clients/channels, and browser/remote storage services.
  • Introduce electron-main “application shared” SQLite storage backed by CrossAppIPC change notifications.
  • Extend global state sync/profile storage reads & writes to preserve storage scope and support syncing application-shared keys.
Show a summary per file
File Description
src/vs/workbench/test/browser/componentFixtures/fixtureUtils.ts Updates test storage fixture typing to include APPLICATION_SHARED change events.
src/vs/workbench/services/workspaces/common/workspaceTrust.ts Moves workspace trust persistence to APPLICATION_SHARED and migrates from APPLICATION scope.
src/vs/workbench/services/storage/browser/storageService.ts Adds IndexedDB-backed application-shared storage in web and includes it in init/clear/logging.
src/vs/workbench/contrib/notebook/test/browser/notebookKernelHistory.test.ts Updates test stubs for new APPLICATION_SHARED change-event overload.
src/vs/workbench/common/memento.ts Adds application-shared mementos alongside application/profile/workspace mementos.
src/vs/workbench/browser/layout.ts Tracks “isNew” state for APPLICATION_SHARED storage scope.
src/vs/platform/userDataSync/common/userDataSync.ts Extends synced storage value model to optionally carry scope.
src/vs/platform/userDataSync/common/globalStateSync.ts Reads/writes global state with scope awareness; adds application-shared updates and initialization handling.
src/vs/platform/userDataProfile/common/userDataProfileStorageService.ts Adds scope-awareness to read/update storage data; includes APPLICATION_SHARED for default profile.
src/vs/platform/storage/test/electron-main/storageMainService.test.ts Adds tests for application-shared storage basics and CrossAppIPC propagation.
src/vs/platform/storage/electron-main/storageMainService.ts Adds applicationSharedStorage to main service and exposes it via IPC + main storage service routing.
src/vs/platform/storage/electron-main/storageMain.ts Implements ApplicationSharedStorageMain + SQLite wrapper that broadcasts external changes via CrossAppIPC.
src/vs/platform/storage/electron-main/storageIpc.ts Extends storage IPC channel to route application-shared requests/events.
src/vs/platform/storage/common/storageService.ts Adds remote window-side application-shared storage via IPC database client.
src/vs/platform/storage/common/storageIpc.ts Adds application-shared IPC request flag and a dedicated database client for shared storage.
src/vs/platform/storage/common/storage.ts Introduces StorageScope.APPLICATION_SHARED, events, flushing/logging support, and key-target caching.
src/vs/platform/environment/node/argv.ts Adds --shared-data-dir CLI option.
src/vs/platform/environment/common/environmentService.ts Adds appSharedDataLocation resolution (CLI override or default).
src/vs/platform/environment/common/environment.ts Extends INativeEnvironmentService with appSharedDataLocation.
src/vs/platform/environment/common/argv.ts Adds shared-data-dir to parsed native args type.
src/vs/code/node/cli.ts Ensures transient mode creates/prints --shared-data-dir alongside user-data/extensions dirs.
src/vs/base/parts/storage/node/storage.ts Adds SQLite option useWAL and exposes getDataVersion(); enables WAL when requested.

Copilot's findings

  • Files reviewed: 22/22 changed files
  • Comments generated: 3

@sandy081 Sandeep Somavarapu (sandy081) changed the title shared application storage Add APPLICATION_SHARED storage scope for cross-app state sharing Apr 20, 2026
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.118.0 milestone Apr 20, 2026
@sandy081
Sandeep Somavarapu (sandy081) marked this pull request as ready for review April 20, 2026 09:28
@vs-code-engineering

vs-code-engineering Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Robo (@deepak1556)

Matched files:

  • src/vs/code/node/cli.ts

VS Code: AbstractStorageService.get() falls back from
APPLICATION_SHARED to APPLICATION scope transparently,
enabling lazy per-key migration without a registry.

Agents App: SharedSQLiteStorageDatabase reads the host
(VS Code) app's application storage DB as a fallback
during getItems(), merging missing keys so shared data
is available even before VS Code runs with new scope code.

Co-authored-by: Copilot <[email protected]>
Move the APPLICATION → APPLICATION_SHARED fallback logic from
AbstractStorageService into the base Storage class via the new
fallbackStorage property on IStorage. When a key is not found,
the fallback is checked and the value is automatically written
through to persist the migration.

This eliminates duplicated fallback code in get/getBoolean/
getNumber and ensures write-through happens for all access
patterns.

Co-authored-by: Copilot <[email protected]>
Remove fallbackStorage from IStorage interface. It is now a
property on the Storage class only, set directly by callers
that have access to the concrete type.

Co-authored-by: Copilot <[email protected]>
Wire up the application storage as fallback during doCreate()
instead of post-init. The ApplicationStorageMain is created
first and passed to ApplicationSharedStorageMain's constructor.
The fallback is set on the Storage instance when the shared
database is created, so it's ready by the time reads happen.

Removes setFallbackStorage() method and post-init wiring.

Co-authored-by: Copilot <[email protected]>
The in-memory fallbackStorage (application storage) makes the
DB-level fallback (reading VS Code's DB from disk) redundant.
Both VS Code and Agents App now use the same mechanism: the
Storage.fallbackStorage property that reads from application
storage and auto-migrates on hit.

Removes getHostUserDataPath, IProductService dependency, and
INativeEnvironmentService from StorageMainService.

Co-authored-by: Copilot <[email protected]>
Introduce MigratingStorage that migrates keys from a fallback
storage on first access. Migrated keys are tracked via a
persisted marker key (__$__migratedStorageMarker) in the DB
so deleted keys are never resurrected from the fallback.

- VS Code windows: MigratingStorage falls back to own
  APPLICATION storage for transparent key migration
- Sessions windows: MigratingStorage falls back to host
  (VS Code) application storage loaded via IPC
- Main process: ApplicationSharedStorageMain uses
  HostApplicationStorageMain for embedded app fallback
- sharedDataFolderName added to product configuration
- Workspace trust migration simplified (handled by
  MigratingStorage automatically)

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
roblourens
roblourens previously approved these changes Apr 21, 2026
roblourens
roblourens previously approved these changes Apr 21, 2026
Log the fallback storage type (host vs local), paths, and item
counts during application shared storage creation to help
diagnose issues when the feature is deployed.

Co-authored-by: Copilot <[email protected]>
@sandy081
Sandeep Somavarapu (sandy081) merged commit 717e853 into main Apr 22, 2026
40 of 41 checks passed
@sandy081
Sandeep Somavarapu (sandy081) deleted the sandy081/main-scorpion branch April 22, 2026 14:17
Kristen McWilliam (Merrit) added a commit to Merrit/vscode-runner that referenced this pull request Apr 30, 2026
VS Code has introduced new locations for the databases, starting with
version 1.118.0. This commit adds support for these new locations, while
still maintaining compatibility with the old paths for users who haven't
updated yet.

Relevant: microsoft/vscode#311317

Resolves: #25
@danielbayley

Copy link
Copy Markdown
Contributor

Sandeep Somavarapu (@sandy081) Please stop hard coding ~/ file paths, and follow the XDG spec.

@lgarron

Lucas Garron (lgarron) commented May 1, 2026 •

Copy link
Copy Markdown

Sandeep Somavarapu (@sandy081) Please stop hard coding ~/ file paths, and follow the XDG spec.

I concur with this. The issues and comments asking VS Code to stop creating directories directly under ~/ continue to receive feedback, and one of them is on the front page of most upvoted issues.

Anecdotally, I have been able to get dozens to programs to follow the XDG spec, and VS Code is literally the only one that continues to violate it without an opt-out. Adding a new path feels almost like a willful disregard for externalities. 😕

It would be nearly trivial to place paths for a new feature like this under something like ~/.local/state/vscode by default instead. This would make a lot of use much happier with VS Code, without causing much trouble for anyone.

Lucas Garron (lgarron) added a commit to lgarron/dotfiles that referenced this pull request May 3, 2026
Lucas Garron (lgarron) added a commit to lgarron/dotfiles that referenced this pull request May 3, 2026
Lucas Garron (lgarron) added a commit to lgarron/dotfiles that referenced this pull request May 3, 2026
microsoft/vscode#311317 causes VS Code to lose workspace trust information when `~/.vscode-shared/` is deleted (which I do in a cron job that runs evfery two minutes). Neither keeping `~/.vscode-shared/` nor having to re-trust workspaces *every single time I open them*  is not acceptable to me over preventing VS Code updates for now. Hopefully the maintainers will be amenable to something that doesn't pollute the home dir.

[VS Code] Prevent updates. 😕

microsoft/vscode#311317 causes VS Code to lose workspace trust information when `~/.vscode-shared/` is deleted (which I do in a cron job that runs evfery two minutes). Neither keeping `~/.vscode-shared/` nor having to re-trust workspaces *every single time I open them*  is not acceptable to me over preventing VS Code updates for now. Hopefully the maintainers will be amenable to something that doesn't pollute the home dir.
Lucas Garron (lgarron) added a commit to lgarron/dotfiles that referenced this pull request May 3, 2026
microsoft/vscode#311317 causes VS Code to lose workspace trust information when `~/.vscode-shared/` is deleted (which I do in a cron job that runs evfery two minutes). Neither keeping `~/.vscode-shared/` nor having to re-trust workspaces *every single time I open them*  is not acceptable to me over preventing VS Code updates for now. Hopefully the maintainers will be amenable to something that doesn't pollute the home dir.
@mikelei8291

Copy link
Copy Markdown

lol, more 💩 in the user's $HOME

Caleb Norton (gigamonster256) added a commit to gigamonster256/nix-config that referenced this pull request May 19, 2026
microsoft/vscode#311317
why this is in the home dir is beyond me
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jun 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants