Skip to content

Mirror global system-Python cache into workspaceState to survive cold globalState on remotes#1611

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cross-session-cache-misses
Draft

Mirror global system-Python cache into workspaceState to survive cold globalState on remotes#1611
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cross-session-cache-misses

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

context.globalState is scoped per-remote, so the cross-session cache for the discovered global system Python (PR #1455) starts cold on every fresh SSH host, WSL distro, dev container, or codespace — and on local profile resets. Every cold start falls through to a full PET refresh on the foreground env-selection path, which is the dominant remaining Linux hang.

Changes

src/managers/builtin/cache.ts — promote workspaceState to a primary layer for SYSTEM_GLOBAL_KEY, keep globalState as fallback:

  • getSystemEnvForGlobal() — read workspaceState[SYSTEM_GLOBAL_KEY] first, fall back to globalState[SYSTEM_GLOBAL_KEY].
  • setSystemEnvForGlobal() — write (and undefined-invalidate) to both layers in parallel.
  • clearSystemEnvCache() — also clear the mirrored SYSTEM_GLOBAL_KEY from workspaceState.
export async function getSystemEnvForGlobal(): Promise<string | undefined> {
    const workspaceState = await getWorkspacePersistentState();
    const workspaceValue = await workspaceState.get<string>(SYSTEM_GLOBAL_KEY);
    if (workspaceValue) {
        return workspaceValue;
    }
    const globalState = await getGlobalPersistentState();
    return await globalState.get<string>(SYSTEM_GLOBAL_KEY);
}

No call-site changes. The fastPath contract is preserved (single string | undefined), so global_env.cache telemetry (hit / miss / stale) and the workspace-scoped path (SYSTEM_WORKSPACE_KEY) are unaffected.

Tests

New src/test/managers/builtin/cache.systemEnvGlobal.unit.test.ts (10 cases): workspaceState-primary lookup, globalState fallback (incl. empty-string), dual-write of values and undefined, set→get round-trip, and full invalidation through both layers via clearSystemEnvCache.

Acceptance criteria mapping

  • Same remote, same workspace, fresh session → cache hit, no PET refresh ✅ (workspaceState mirror).
  • Same remote, brand-new workspace folder → unchanged (cache miss → PET) ✅ (workspaceState mirror is per-folder; globalState fallback only primes after first-time global resolution on that remote).
  • Brand-new remote + brand-new workspace → unchanged ✅ (out of scope for this option).
  • Telemetry hit / miss / stale unchanged ✅.
  • Workspace-scoped fast path unchanged ✅.

Copilot AI changed the title [WIP] Fix cross-session cache misses on fresh remote Mirror global system-Python cache into workspaceState to survive cold globalState on remotes Jun 25, 2026
Copilot AI requested a review from eleanorjboyd June 25, 2026 02:41
@eleanorjboyd eleanorjboyd requested a review from Copilot June 25, 2026 20:12

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 improves startup/performance for global system Python discovery on remote scenarios by mirroring the cross-session system-Python cache into workspaceState, using globalState as a fallback. This helps avoid foreground PET refreshes when context.globalState is effectively “cold” per-remote.

Changes:

  • Update system-Python global cache read/write logic to be workspaceState-primary with globalState fallback, and clear both layers during cache clears.
  • Add a new unit test suite covering the two-tier lookup behavior, dual writes, and full invalidation.
  • Regenerate package-lock.json metadata (removing several "peer": true entries).
Show a summary per file
File Description
src/managers/builtin/cache.ts Mirrors SYSTEM_GLOBAL_KEY into workspaceState, adds fallback read, and clears both layers.
src/test/managers/builtin/cache.systemEnvGlobal.unit.test.ts Adds unit tests validating workspaceState-primary + globalState fallback behavior and clearing semantics.
package-lock.json Lockfile metadata normalization (no functional code impact).

Copilot's findings

  • Files reviewed: 2/3 changed files
  • Comments generated: 1

Comment on lines +86 to +93
const [workspaceState, globalState] = await Promise.all([
getWorkspacePersistentState(),
getGlobalPersistentState(),
]);
await Promise.all([
workspaceState.set(SYSTEM_GLOBAL_KEY, envPath),
globalState.set(SYSTEM_GLOBAL_KEY, envPath),
]);
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.

3 participants