Repository navigation
Commit 63ae981
Add opportunistic inline-script TTL eviction (PEP 723 PR 14/16) (#1745)
> Part of #1602 (PEP 723 inline script env support). Design doc: #1601.
### Roadmap context
This is **PR 14 of 16** in the PEP 723 inline-script roadmap. PR 13
added explicit, user-confirmed cache cleanup; this PR adds the separate
best-effort TTL path.
| Phase 5: Lifecycle and polish | PR | Status |
|---|---|---|
| | PR 7: persistence (`get` / `set` + Memento) | merged (#1697) |
| | PR 13: Clear Script Environment Cache | merged (#1724) |
| | **PR 14: opportunistic 14-day TTL eviction** | **this PR** |
| | PR 15: lifecycle telemetry | merged (#1723) |
| | PR 16: status-bar decision | resolved; no code PR |
### Why this PR
Inline-script environments are dependency/interpreter-keyed and
intentionally rebuilt instead of synchronized in place. Without
lifecycle cleanup, old cache keys accumulate whenever dependencies or
the selected Python change.
The design calls for a pipx-style 14-day TTL in addition to the explicit
clear command. Because TTL cleanup is silent, it must be more
conservative than user-confirmed cleanup and must never prevent the
requested environment from being created.
### What this PR does
- Attempts one TTL sweep per `InlineScriptEnvManager` session.
- Runs the sweep before the first environment creation/reuse reaches the
cache.
- Reads only valid `.meta.json` sidecars and selects entries whose
`lastUsedAt` is strictly older than 14 days.
- Reuses PR 13's physical-root, normal-directory, direct-child, and
entry-lock safety checks.
- Re-reads `lastUsedAt` under the entry lock before deletion.
- Preserves held, retained, malformed, redirected, unavailable, or
failed-to-delete entries.
- Treats all TTL failures as best-effort warnings and continues the
triggering creation.
- Invalidates persisted and warm script associations only for entries
confirmed deleted or definitively removed by another host.
- Removes evicted environments from the discovered collection and emits
the existing environment-change events.
- Prevents a concurrent discovery refresh from publishing a stale
snapshot after eviction.
### Eviction semantics
| State | Behavior |
|---|---|
| `lastUsedAt` older than 14 days | Lock, revalidate, and delete |
| Age exactly 14 days | Keep |
| Recent or future timestamp | Keep |
| Missing, invalid, unsupported, or unreadable sidecar | Keep |
| Timestamp becomes fresh before lock acquisition | Keep |
| Entry is actively locked | Keep |
| Entry has a retained cancellation lock | Keep; only explicit cleanup
may reclaim it |
| Entry deletion fails | Keep and continue creation |
| Another host already deleted the entry | Confirm with `lstat`, then
invalidate local associations |
| Association persistence fails after deletion | Keep in-memory state
consistent, log, and continue creation |
| Refresh started before deletion | Reject its stale collection snapshot
|
| Refresh starts during maintenance | Wait, then scan the post-eviction
cache |
### Concurrency and safety
- The once-per-session latch is set synchronously, so concurrent creates
share one sweep.
- The sweep uses the existing cache-maintenance then selection-queue
ordering.
- The active-create counter is incremented before the sweep, preserving
PR 13's clear-vs-create behavior.
- Each deletion is protected by the existing cross-host cache-entry
lock.
- Physical root and entry containment are revalidated after lock
acquisition.
- A cache mutation revision prevents stale discovery publication without
waiting on, or deadlocking with, a refresh already blocked by
maintenance.
- Only `ENOENT` counts as confirmed cross-host deletion; permission and
transient access errors preserve associations.
### Performance
- The cache is scanned once per extension-host session, not on every
lookup.
- Entries are inspected and deleted sequentially to avoid I/O spikes.
- Activation remains unchanged and is not blocked by TTL work.
- Environments with missing or uncertain metadata are not repeatedly
modified.
### User impact
The feature remains behind `python-envs.inlineScripts.enabled`. Users
without inline-script environments see no behavior change. Existing
environments are retained unless a valid sidecar proves they have not
been successfully reused for more than 14 days.
### Tests
- `npm run compile-tests`
- `npm run compile`
- `npm run lint`
- Complete unit suite: **1,928 passing**, 6 pending
Focused coverage includes:
- strict 14-day cutoff;
- once-per-session and failed-sweep behavior;
- under-lock freshness revalidation;
- held and retained lock preservation;
- deletion and persistence failure isolation;
- cross-host deletion confirmation;
- association and discovered-collection invalidation;
- refresh-versus-eviction publication races;
- unchanged explicit clear-cache behavior.
### Scope and follow-up
This PR does not add telemetry, activation-time cleanup, a cache-root
lock, project-setting cleanup, UX, or retry loops. Explicit clear-cache
behavior remains unchanged.
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 7d70c65 commit 63ae981
2 files changed
Lines changed: 495 additions & 24 deletions
File tree
- src
- managers/builtin/inlineScript
- test/managers/builtin/inlineScript
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
147 | 156 | | |
148 | 157 | | |
149 | 158 | | |
| |||
200 | 209 | | |
201 | 210 | | |
202 | 211 | | |
| 212 | + | |
| 213 | + | |
203 | 214 | | |
204 | 215 | | |
205 | 216 | | |
| |||
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
| 274 | + | |
263 | 275 | | |
264 | 276 | | |
265 | 277 | | |
| |||
583 | 595 | | |
584 | 596 | | |
585 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
586 | 603 | | |
587 | 604 | | |
588 | 605 | | |
| |||
699 | 716 | | |
700 | 717 | | |
701 | 718 | | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
702 | 722 | | |
703 | 723 | | |
704 | 724 | | |
| |||
2139 | 2159 | | |
2140 | 2160 | | |
2141 | 2161 | | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
2142 | 2173 | | |
2143 | 2174 | | |
2144 | 2175 | | |
| |||
2849 | 2880 | | |
2850 | 2881 | | |
2851 | 2882 | | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
2852 | 3030 | | |
2853 | 3031 | | |
2854 | 3032 | | |
| |||
2861 | 3039 | | |
2862 | 3040 | | |
2863 | 3041 | | |
2864 | | - | |
2865 | | - | |
2866 | | - | |
2867 | | - | |
2868 | | - | |
2869 | | - | |
2870 | | - | |
2871 | | - | |
2872 | | - | |
2873 | | - | |
2874 | | - | |
2875 | | - | |
2876 | | - | |
2877 | | - | |
2878 | | - | |
| 3042 | + | |
| 3043 | + | |
2879 | 3044 | | |
2880 | 3045 | | |
2881 | 3046 | | |
| |||
2953 | 3118 | | |
2954 | 3119 | | |
2955 | 3120 | | |
| 3121 | + | |
2956 | 3122 | | |
2957 | 3123 | | |
2958 | 3124 | | |
2959 | 3125 | | |
2960 | | - | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
2961 | 3130 | | |
2962 | 3131 | | |
2963 | 3132 | | |
| |||
2981 | 3150 | | |
2982 | 3151 | | |
2983 | 3152 | | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
2984 | 3156 | | |
| 3157 | + | |
2985 | 3158 | | |
2986 | 3159 | | |
2987 | 3160 | | |
| |||
2990 | 3163 | | |
2991 | 3164 | | |
2992 | 3165 | | |
2993 | | - | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
2994 | 3170 | | |
2995 | 3171 | | |
2996 | 3172 | | |
| |||
2999 | 3175 | | |
3000 | 3176 | | |
3001 | 3177 | | |
3002 | | - | |
| 3178 | + | |
3003 | 3179 | | |
3004 | 3180 | | |
3005 | 3181 | | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
3006 | 3185 | | |
3007 | 3186 | | |
3008 | 3187 | | |
| |||
3155 | 3334 | | |
3156 | 3335 | | |
3157 | 3336 | | |
| 3337 | + | |
| 3338 | + | |
| 3339 | + | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
| 3348 | + | |
| 3349 | + | |
| 3350 | + | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
3158 | 3357 | | |
3159 | 3358 | | |
3160 | 3359 | | |
| |||
3260 | 3459 | | |
3261 | 3460 | | |
3262 | 3461 | | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
| 3481 | + | |
| 3482 | + | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
3263 | 3486 | | |
3264 | 3487 | | |
3265 | 3488 | | |
| |||
0 commit comments