Repository navigation
Add APPLICATION_SHARED storage scope for cross-app state sharing - #311317
Conversation
Screenshot ChangesBase: Changed (5) |
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
Co-authored-by: Copilot <[email protected]>
APPLICATION_SHARED storage scope for cross-app state sharing
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Robo (@deepak1556)Matched files:
|
Co-authored-by: Copilot <[email protected]>
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]>
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]>
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
|
Sandeep Somavarapu (@sandy081) Please stop hard coding |
I concur with this. The issues and comments asking VS Code to stop creating directories directly under 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 |
This may break stuff. I don't care right now. See: microsoft/vscode#311317
This may break stuff. I don't care right now. See: microsoft/vscode#311317
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.
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.
|
lol, more 💩 in the user's $HOME |
microsoft/vscode#311317 why this is in the home dir is beyond me
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