Route PEP 723 scripts to inline environments (PEP 723 PR 9/16) - #7
Route PEP 723 scripts to inline environments (PEP 723 PR 9/16)#7StellaHuang95 wants to merge 7 commits into
Conversation
|
🔒 Automated review in progress — @StellaHuang95 is auto-reviewing this PR. |
|
GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for src/features/inlineScript/lazyDetector.ts:L162.
URI-level coalescing can let an in-flight open read absorb a concurrent save. If the saved contents change before the open read completes, the stale open result can be published as routing metadata. Add a controlled regression test and replay or separate the save read when this race occurs. [verified] |
|
Addressed the open/save coalescing feedback from #7 (comment) in 50555f3. Routing-enabled detection now tracks per-URI generations: a save arriving during an older open read schedules a fresh post-save read, and stale results cannot publish routing metadata. The telemetry-only/default-off path retains its previous coalescing behavior. The same commit also adds document-compatible source offsets so CRLF metadata edits invalidate routing correctly. |
| ): void { | ||
| if (!this.inlineScriptRouting) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
_inlineRoutingOverrides is not cleared when a script is deleted or renamed, so an override from the old file can win after a new script is created at the same path. Clear old-path overrides from delete/rename handling and cover delete–recreate behavior.
| public readonly log: LogOutputChannel, | ||
| ) {} | ||
| private readonly routingRegistry: InlineScriptRoutingRegistry = new InlineScriptRoutingRegistry(), | ||
| ) { |
There was a problem hiding this comment.
Info · Optional note
The default registry creates a disconnected routing registry despite production activation requiring one shared instance. Require constructor injection so every caller explicitly provides the activation-scoped registry.
|
GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for src/managers/builtin/inlineScript/envManager.ts:L168.
The per-script environment, persisted association, validation, provenance, revision, and pending-work state is coordinated through parallel maps. Consolidate the durable lifecycle fields into one keyed record so invalidation and publication cannot update only part of the state. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cb82ae9-7424-40a4-9156-8c54ac6e0895
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cb82ae9-7424-40a4-9156-8c54ac6e0895
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3cb82ae9-7424-40a4-9156-8c54ac6e0895
Preserve sidecars across replacement failures, replay saves after in-flight reads, and use document-compatible metadata offsets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b12d843-8011-4bfc-9ba9-f75761eadee2
Restore compatible sidecars after replacement failures without reviving invalid cache artifacts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b12d843-8011-4bfc-9ba9-f75761eadee2
Adapt versioned associations, telemetry coalescing, discovery, and cache clearing after rebase. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b12d843-8011-4bfc-9ba9-f75761eadee2
3245bb0 to
021a198
Compare
Retain up to 128 distinct metadata identity proofs per shared cache entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b12d843-8011-4bfc-9ba9-f75761eadee2
| await this.refreshEnvironment(uri); | ||
| } | ||
| return; | ||
| } |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
_inlineRoutingOverrides is not cleared for deleted or renamed scripts, so an override for the old file can still win if a new script is later created at the same path. Clear old-path overrides on delete/rename and add a delete-recreate regression test.
|
Upstream review continues in microsoft#1729. Closing this fork-only review PR as superseded. |
| export async function writeMetaJson(envDir: Uri, meta: InlineScriptEnvMeta): Promise<void> { | ||
| await fsapi.ensureDir(envDir.fsPath); | ||
| export function writeMetaJson(envDir: Uri, meta: InlineScriptEnvMeta): Promise<void> { | ||
| const finalPath = getMetaJsonPath(envDir).fsPath; |
There was a problem hiding this comment.
Issue · Please address or respond
queued is assigned once. Declare it as const queued = operation.finally(...); the deferred callback can safely reference that binding.
[verified]
| await this.refreshEnvironment(uri); | ||
| } | ||
| return; | ||
| } |
There was a problem hiding this comment.
Issue · Please address or respond
Delete and rename handling never clears _inlineRoutingOverrides, so a newly created script at the old path inherits the deleted file's override. Clear old-path overrides from filesystem lifecycle events and add delete-recreate and rename-recreate coverage.
[verified]
|
GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for src/managers/builtin/inlineScript/envManager.ts:L214.
Per-script lifecycle state is coordinated manually across numerous parallel maps. Consolidate the persisted association, resolved environment, validation proof, revisions, and pending operations into a per-script state record before adding further transitions. [verified] |
| const next = updater(previous); | ||
|
|
||
| if (!next.metadata && !next.validatedAssociation) { | ||
| this.states.delete(scriptPath); |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
Deleting an empty state also discards its revision, allowing a later metadata update to reuse revision 1. Preserve a monotonic revision independently of routeability state and add a deferred-refresh test that deletes and recreates the same path.
[verified]
| start: sourceOffsetForNormalizedOffset(sourceText, matchStart), | ||
| end: sourceOffsetForNormalizedOffset(sourceText, end), | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
sourceRange is computed after removing the BOM, while VS Code change offsets include it. Editing the final metadata character can therefore fail the < metadataEnd invalidation check. Return offsets relative to the original document and add a BOM-at-EOF edit test.
[verified]
| } | ||
| this.routingRegistry.clearMetadata(uri); | ||
| this.routingRegistry.setValidatedAssociation(uri, false); | ||
| } |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
Delete and rename clear routeability without advancing the routing-read generation, so an older disk read can republish metadata for the removed path. Invalidate the generation in clearRouteability and test deletion while an open read is deferred.
[verified]
Part of microsoft#1602. Complete roadmap PR9 automatic routing implementation.
Summary
.pyfile to the inline-script manager only when saved PEP 723 metadata and a validated cached/persisted association agreePersistence and provenance
Default-off guarantee
python-envs.inlineScripts.enabledis latched once at activation and is authoritative for that extension-host lifetime.When absent/false:
bde7cf8telemetry-only mode: workspace.pyopen/save/change listeners onlyinlineScript.detected/editedtelemetry semantics remain baseline-equivalentA window reload is required for flag changes, preventing mixed activation states.
Scope
No activation-time environment listing,
pythonProjects[]registration, setup UI, cache cleanup, lifecycle telemetry, or status treatment.Validation