Skip to content

fix: clean up inline-script environments after activation - #1794

Merged
Stella Huang (StellaHuang95) merged 1 commit into
microsoft:mainfrom
StellaHuang95:stellahuang/inline-script-ttl-eviction-on-activation
Sep 16, 2026
Merged

Stella Huang (StellaHuang95) merged 1 commit into
microsoft:mainfrom
StellaHuang95:stellahuang/inline-script-ttl-eviction-on-activation

Conversation

@StellaHuang95

Copy link
Copy Markdown
Contributor

Summary

Inline-script cache cleanup previously ran before the first environment creation in a window. Users who did not create another environment could keep old cached environments indefinitely, and cleanup could delay unrelated interpreter lookups.

  • Run one delayed activation sweep instead of triggering cleanup from create(). Keep the existing 14-day expiration policy, reclaim incomplete setups after a one-day grace period, and remove at most three entries per sweep. There is no daily sweep.
  • Keep candidate scans and cleanup-result publication outside the interpreter-lookup barrier. Retain per-entry locks, physical-path ownership checks, reference checks, and an under-lock age recheck before deletion.
  • Refresh cached environments' last-used timestamps on lookup. Keep optional bookkeeping off the critical path, use fail-fast read-path metadata writes, and withhold an old entry when its protection cannot be established rather than return an unsafe last-known descriptor.
  • Preserve the selected interpreter through temporary unavailability, expose setup for an explicit retry, and publish recovery events after bounded background revalidation.
  • Preserve retry deadlines and budgets across saves that leave the inline requirements unchanged. Cancel stale recovery when requirements or the stored association change, and recheck selection after asynchronous timestamp work.
  • Recover dead-owner cache locks and reconcile the environment catalog after deletion without discarding a replacement rebuilt at the same path.
  • Add regression coverage and document the cleanup and recovery behavior.

The feature remains behind the existing python-envs.inlineScripts.enabled flag. This does not add a worker process, recurring cleanup, dependencies, or a new cache format.

Validation

Lint, type checking, the full unit suite, and the production bundle were repeated after integrating the latest main API-facade refactor and resolving the import in the relocated src/extensionApi.ts. Obsolete compiled files from the renamed modules were removed before recompilation. Cache-deletion, save/recovery, and ordinary-API scenarios were also rerun against the integrated implementation.

  • npm run lint
  • npm run compile-tests
  • npm run unittest -- --reporter=dot --no-colors: 2,409 passing, 6 pending.
  • Production webpack bundle.
  • Independent Windows walkthroughs using real Python virtual environments, cache metadata, and entry locks:
    • The actual 96-126 second activation timer removed an old orphan without calling the manager's create() and did not schedule another sweep.
    • Exactly three old orphaned entries were removed; referenced, recent, live-locked, newer-schema, and redirected entries were preserved.
    • A normal project .venv and the base Python installation remained usable.
    • Another window's use after eviction planning prevented deletion.
    • Temporary write failures and locks recovered with and without an intervening same-requirements save.
    • A pending timestamp write did not return a subsequently unset interpreter.
    • A healthy lookup completed while an unrelated cache inspection was deliberately paused.
  • HEAD/current shared-API comparisons retained ordinary-manager routing, venv/conda timeout fallbacks, explicit non-inline overrides, and neighboring-file isolation.

The walkthroughs adapt the editor/discovery-service boundaries; they are not full live VS Code/Pylance GUI or macOS/Linux validation. Usage timestamps are not process-lifetime leases.

@bschnurr

Copy link
Copy Markdown
Member

🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR.

@StellaHuang95 Stella Huang (StellaHuang95) added the feature-request Request for new features or functionality label Sep 16, 2026
} else {
await this.reviewRoutingForMissingEnvironment(scope);
}
return undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · Non-blocking recommendation

If association lookup returns undefined because the sidecar is temporarily unreadable but no entry lock exists, this path only calls reviewRoutingForMissingEnvironment. That preserves the route for an unproven sidecar, but does not mark it unavailable or schedule recovery, leaving the selected environment unavailable without the explicit retry UI. Can this propagate the transient-unavailable state and schedule the bounded retry independently of lock presence?

@bschnurr

Copy link
Copy Markdown
Member

Result: 🔴 could-not-verify

Verification details

Verification: Isolated verification observed failures that were not classified as caused by this PR: Dependency and test discovery preflight. The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Summary: Verification could not proceed because the offline dependency cache lacked `update-browserslist-db`, so `npm ci --offline` failed. Consequently `npm run compile-tests` could not find `tsc`, and no unit tests could run. The PR adds extensive targeted regression coverage across seven test files, including cleanup scheduling, timestamp refreshes, concurrency, and recovery. Confidence is limited because none of that coverage was executable in the sandbox.

Test runs: 1 failed, 5 not run

  • Failed | unrelated to this PR | Dependency and test discovery preflight | printf 'profile=%s\n' "${AUTOMATION_SANDBOX_PROFILE:-}"; test -d node_modules && echo node_modules=present || echo node_modules=missing; node --version; npm --version; sed -n '1,160p' build/.mocha.unittests.json; git diff --name-status HEAD^ -- 'src/test/**/*.test.ts'
  • ⚠️ Not run | Offline dependency bootstrap | npm ci --offline
  • ⚠️ Not run | Compile unit tests | npm run compile-tests
  • ⚠️ Not run | Inline-script environment manager unit tests | node ./node_modules/mocha/bin/mocha.js --require source-map-support/register --require out/test/unittests.js --ui tdd --timeout 180000 out/test/managers/builtin/inlineScript/envManager.unit.test.js
  • ⚠️ Not run | Inline-script cache and routing unit tests | node ./node_modules/mocha/bin/mocha.js --require source-map-support/register --require out/test/unittests.js --ui tdd --timeout 180000 out/test/common/inlineScript/cacheLayout.unit.test.js out/test/common/inlineScript/routingRegistry.unit.test.js
  • ⚠️ Not run | API and inline-script UI unit tests | node ./node_modules/mocha/bin/mocha.js --require source-map-support/register --require out/test/unittests.js --ui tdd --timeout 180000 out/test/extensionApi.unit.test.js out/test/features/envManagers.lastKnown.unit.test.js out/test/features/inlineScript/codeLens.unit.test.js out/test/features/inlineScript/setupCodeAction.unit.test.js
Dependency and test discovery preflight diagnostic output
profile=typescript
node_modules=missing
v22.21.1
10.9.4
Mocha targets ./out/test/**/*.unit.test.js.
error: Could not access 'HEAD^'
⚠️ Offline dependency bootstrap diagnostic output
npm error code ENOTCACHED
npm error request to https://packagefeedproxy.microsoft.io/npm/update-browserslist-db/-/update-browserslist-db-1.3.2.tgz failed: cache mode is 'only-if-cached' but no cached response is available.
⚠️ Compile unit tests diagnostic output
> tsc -p . --outDir out
sh: 1: tsc: not found
⚠️ Inline-script environment manager unit tests diagnostic output
Not run because offline dependency preparation and test compilation failed.
⚠️ Inline-script cache and routing unit tests diagnostic output
Not run because offline dependency preparation and test compilation failed.
⚠️ API and inline-script UI unit tests diagnostic output
Not run because offline dependency preparation and test compilation failed.

@bschnurr Bill Schnurr (bschnurr) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@bschnurr Bill Schnurr (bschnurr) added the review-auto:approved Automated review: no blocking findings (approval posted). label Sep 16, 2026
Run one bounded activation-time sweep without blocking unrelated interpreter lookups. Preserve cache ownership and usage protection, recover temporary unavailability, and keep recovery across unchanged-metadata saves.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@StellaHuang95
Stella Huang (StellaHuang95) force-pushed the stellahuang/inline-script-ttl-eviction-on-activation branch from d830480 to d0f7469 Compare September 16, 2026 22:03
@bschnurr

Copy link
Copy Markdown
Member

Result: 🔴 could-not-verify

Verification details

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Summary: I could not execute meaningful tests because the verification container was unavailable or no executable verification environment was provided. The PR adds extensive unit coverage for delayed cache eviction, last-used timestamp protection, temporary association recovery, stale-lock reclamation, API fallback behavior, routing availability, CodeLens/code-action retry UI, and cache reconciliation. Since none of those tests could be run, the implementation remains unverified here despite the broad added coverage.

Test runs: 1 not run

  • ⚠️ Not run | Dependency and targeted-test discovery | printf 'profile=%s\n' "$AUTOMATION_SANDBOX_PROFILE"; test -d node_modules && echo node_modules=present || echo node_modules=missing; node -p "require('./package.json').scripts['compile-tests']"; node -p "require('./package.json').scripts['unittest']"; find src/test -type f ( -path 'inlineScript' -o -name 'extensionApi.unit.test.ts' -o -name 'envManagers.lastKnown.unit.test.ts' ) | sort
⚠️ Dependency and targeted-test discovery diagnostic output
Verification execution was unavailable; no command output was produced.

@StellaHuang95
Stella Huang (StellaHuang95) merged commit 20c1381 into microsoft:main Sep 16, 2026
44 checks passed
@StellaHuang95
Stella Huang (StellaHuang95) deleted the stellahuang/inline-script-ttl-eviction-on-activation branch September 16, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request Request for new features or functionality review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants