Add APPLICATION_SHARED storage scope for cross-app state sharing#311317
Merged
Add APPLICATION_SHARED storage scope for cross-app state sharing#311317
APPLICATION_SHARED storage scope for cross-app state sharing#311317Conversation
Contributor
Screenshot ChangesBase: Changed (5) |
Contributor
There was a problem hiding this comment.
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_SHAREDand plumb it throughIStorageService, 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
APPLICATION_SHARED storage scope for cross-app state sharing
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @deepak1556Matched files:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
bpasero
requested changes
Apr 21, 2026
bpasero
requested changes
Apr 21, 2026
Add key to migratedKeys immediately before checking fallback to prevent redundant lookups. Only persist the MIGRATED_KEY marker when a value was actually found and migrated, avoiding unnecessary writes when the key doesn't exist in the fallback. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dmitrivMS
previously approved these changes
Apr 21, 2026
bpasero
previously approved these changes
Apr 21, 2026
roblourens
previously approved these changes
Apr 21, 2026
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 <223556219+Copilot@users.noreply.github.com>
alexr00
approved these changes
Apr 22, 2026
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.
Implements #311337
Summary
Introduces a new
StorageScope.APPLICATION_SHAREDthat 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 alongsideAPPLICATION,PROFILE, andWORKSPACE. Callers use it like any other scope and can independently chooseStorageTarget.USER(synced) orStorageTarget.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-dirCLI argument.IEnvironmentService.appSharedDataHome— URI pointing to the shared data rootCross-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 asharedStorage:changedIPC message with the changed/deleted keys. The sibling app receives it and firesonDidChangeItemsExternalevents.Messages received before storage initialization are ignored to avoid processing stale queued messages on startup.
Settings Sync Integration
APPLICATION_SHAREDkeys are included in the global state sync payload with ascopefield for correct round-tripping:readStorageData()includesAPPLICATION_SHAREDkeys for the default profile onlyscopefieldAPPLICATION_SHAREDkeys are skipped entirely (not downgraded)IStorageValue.scopeis optional and defaults toPROFILEfor backward compatibilityMigration Example
Workspace trust storage key migrated from
APPLICATION→APPLICATION_SHAREDwith explicit data migration (reads from old scope, writes to new, removes from old).Key Files Changed
storage.ts— enum, events, key targets, flush/logstorageIpc.ts—applicationSharedflag,ApplicationSharedStorageDatabaseClientelectron-main/storageIpc.ts— routing viaapplicationSharedflagstorageMain.ts—ApplicationSharedStorageMain,SharedSQLiteStorageDatabasestorageMainService.ts—applicationSharedStoragelifecyclestorageService.ts(common),storageService.ts(browser)environment.ts,environmentService.ts—appSharedDataHomenode/storage.ts— WAL mode support,getDataVersion()globalStateSync.ts,userDataSync.ts,userDataProfileStorageService.tsworkspaceTrust.ts— migrated toAPPLICATION_SHAREDargv.ts,cli.ts—--shared-data-dir,--transientsupportlayout.ts,memento.ts— new scope handling