Skip to content

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

Merged
sandy081 merged 31 commits intomainfrom
sandy081/main-scorpion
Apr 22, 2026
Merged

Add APPLICATION_SHARED storage scope for cross-app state sharing#311317
sandy081 merged 31 commits intomainfrom
sandy081/main-scorpion

Conversation

@sandy081
Copy link
Copy Markdown
Member

@sandy081 sandy081 commented Apr 20, 2026

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 APPLICATIONAPPLICATION_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.tsapplicationShared flag, ApplicationSharedStorageDatabaseClient
IPC (server) electron-main/storageIpc.ts — routing via applicationShared flag
Main process storage storageMain.tsApplicationSharedStorageMain, SharedSQLiteStorageDatabase
Main service storageMainService.tsapplicationSharedStorage lifecycle
Renderer storage storageService.ts (common), storageService.ts (browser)
Environment environment.ts, environmentService.tsappSharedDataHome
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

Copilot AI review requested due to automatic review settings April 20, 2026 06:58
@sandy081 sandy081 self-assigned this Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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

Comment thread src/vs/platform/storage/test/electron-main/storageMainService.test.ts Outdated
Comment thread src/vs/platform/userDataSync/common/globalStateSync.ts Outdated
Comment thread src/vs/platform/storage/electron-main/storageMain.ts
sandy081 and others added 2 commits April 20, 2026 09:17
Co-authored-by: Copilot <copilot@github.com>
@sandy081 sandy081 changed the title shared application storage Add APPLICATION_SHARED storage scope for cross-app state sharing Apr 20, 2026
@sandy081 sandy081 requested a review from bpasero April 20, 2026 09:20
@sandy081 sandy081 added this to the 1.118.0 milestone Apr 20, 2026
@sandy081 sandy081 marked this pull request as ready for review April 20, 2026 09:28
@sandy081 sandy081 enabled auto-merge (squash) April 20, 2026 09:28
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented Apr 20, 2026

📬 CODENOTIFY

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

@deepak1556

Matched files:

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

sandy081 and others added 14 commits April 20, 2026 13:26
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>
Comment thread src/vs/base/parts/storage/node/storage.ts Outdated
Comment thread src/vs/code/node/cli.ts
Comment thread src/vs/platform/environment/common/environmentService.ts
Comment thread src/vs/platform/storage/electron-main/storageMain.ts
Comment thread src/vs/base/parts/storage/node/storage.ts Outdated
sandy081 and others added 2 commits April 21, 2026 17:00
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>
@sandy081 sandy081 disabled auto-merge April 21, 2026 15:12
Co-authored-by: Copilot <copilot@github.com>
dmitrivMS
dmitrivMS previously approved these changes Apr 21, 2026
bpasero
bpasero previously approved these changes Apr 21, 2026
@sandy081 sandy081 dismissed stale reviews from bpasero and dmitrivMS via 9aa6815 April 21, 2026 21:30
roblourens
roblourens previously approved these changes Apr 21, 2026
roblourens
roblourens previously approved these changes Apr 21, 2026
sandy081 and others added 3 commits April 22, 2026 08:02
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>
@sandy081 sandy081 merged commit 717e853 into main Apr 22, 2026
40 of 41 checks passed
@sandy081 sandy081 deleted the sandy081/main-scorpion branch April 22, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants