Skip to content

Harden PEP 723 per-script routing against stale asynchronous selections - #1734

Merged
Stella Huang (StellaHuang95) merged 3 commits into
microsoft:mainfrom
StellaHuang95:copilot/pep723-routing-hardening
Aug 26, 2026
Merged

Stella Huang (StellaHuang95) merged 3 commits into
microsoft:mainfrom
StellaHuang95:copilot/pep723-routing-hardening

Conversation

@StellaHuang95

@StellaHuang95 Stella Huang (StellaHuang95) commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR narrows the earlier inline-script hardening to two focused, PEP 723-specific changes. Everything here is scoped to the manually enabled (default-off) inline-script routing feature.

1. Prevent stale asynchronous selections from mutating PEP 723 per-script routing overrides

When environment selections for a script resolve out of order, a superseded (older) operation could still install, clear, or overwrite that script's per-script inline routing override. The central manager now guards inline routing mutations with a per-script revision check (commitInlineRoutingOperation), gated strictly to:

  • inlineScriptRouting being enabled, and
  • a file .py scope recognized by getInlineScriptRoutingKey.

Only a current (non-superseded) operation may change a script's routing override. Each script commits on its own per-file inline key, so two routeable scripts under the same containing project no longer contend on a shared project revision — batch-selecting one non-inline environment for both now correctly routes both scripts.

The ordinary project/global active-selection and settings lanes commit independently, so a stale inline operation can no longer suppress a legitimate containing-project selection.

2. Preserve future-schema inline cache backups

cacheLayout now classifies a backup sidecar written by a newer cache schema as unsupported rather than rebuildable, so a newer-schema cache isn't rebuilt (and clobbered) by an older client.

Explicitly deferred / out of scope

The generic cross-manager batch settings write race is not addressed here. A correct fix requires shared cross-manager settings serialization. This PR intentionally does not claim to make batch settings persistence revision-ordered, and it does not change ordinary (non-inline) project selection behavior. That work is deferred to a follow-up.

Tests

  • Adapted the stale-non-inline-vs-newer-inline regression: it asserts the script still routes to inline (its inline active selection is preserved) and no longer asserts the containing-project selection is suppressed.
  • Kept the older-batch-inline-vs-newer-override regression.
  • Added a same-project batch regression: two routeable scripts under one project, batch-selected to one non-inline environment, both resolve to the non-inline manager.
  • Added a feature-off / no-routing-registry batch regression across distinct projects (manager.set, active-selection/events, and settings unchanged).
  • Kept the cacheLayout future-schema backup tests.

Unit suite: 1838 passing, 6 pending, 0 failing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@StellaHuang95 Stella Huang (StellaHuang95) added the feature-request Request for new features or functionality label Aug 25, 2026
@heejaechang

Heejae Chang (heejaechang) commented Aug 25, 2026

Copy link
Copy Markdown

🔒 Automated review in progress — Heejae Chang (@heejaechang) is auto-reviewing this PR.

Comment thread src/features/envManagers.ts
Comment thread src/managers/builtin/inlineScript/envManager.ts
@heejaechang

Copy link
Copy Markdown

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

@heejaechang Heejae Chang (heejaechang) added the review-auto:changes-requested Automated review: posted blocking findings to address. label Aug 25, 2026
…kup classification

Trim this PR to the minimal set of fixes for the default-off PEP 723 inline-script feature:

- Batch settings persistence now obeys the selection revision-ordering guarantee.
  In the Uri[] branch of setEnvironments, the winning (non-superseded) selections
  are committed via the revision-commit guard BEFORE settings are persisted, and
  settings/routing/events are applied only for those winners. This fixes the
  settings/routing divergence where an out-of-order older batch could persist a
  stale manager to settings.json even though its routing override was rejected.
- Future-schema backup sidecars are classified as `unsupported` (not `missing`)
  so a newer-schema cache is not rebuilt by an older client.

Reverts the association-validation retry/generation subsystem in the inline-script
env manager (AssociationValidationResult, retry generations, nested pending-op maps,
conditional Memento commit guards, required routing-registry injection) — deferred
to a follow-up.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f881304e-3c5f-4144-9f0d-d80c68768d18
@StellaHuang95 Stella Huang (StellaHuang95) changed the title Harden inline script routing validation and retries Order inline-script selection persistence and classify future-schema cache backups Aug 25, 2026
@heejaechang

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved via Review Center.

@heejaechang Heejae Chang (heejaechang) added review-auto:approved Automated review: no blocking findings (approval posted). and removed review-auto:changes-requested Automated review: posted blocking findings to address. labels Aug 25, 2026
Replace the generic cross-manager selection-finalization machinery with a
narrow PEP 723-only routing-mutation guard. Only a current (non-superseded)
inline-routing operation may mutate a script's per-script routing override;
the ordinary project/global active-selection and settings lanes are committed
independently and are no longer suppressed by a stale inline operation.

- Restore the origin/main batch settings construction/write order (no
  committedSelections, no pre-settings revision filter, no post-settings
  recheck) and the one-key commitSelectionOperation.
- Add commitInlineRoutingOperation, gated to inlineScriptRouting + file .py
  scopes via getInlineScriptRoutingKey; feature-off and non-script scopes
  return true immediately and preserve the old flow.
- Guard only the single-URI and batch inline routing blocks. Each script
  commits on its own per-file inline key, so two scripts under the same
  containing project no longer contend on a shared project revision (the
  first script now installs its override instead of skipping it).
- The generic cross-manager settings write race is explicitly deferred.

Tests: adapt the stale-non-inline-vs-newer-inline regression to assert the
script still routes to inline without asserting containing-project
suppression; add a same-project batch non-inline regression and a feature-off
distinct-projects batch regression; remove the batch settings-ordering test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f881304e-3c5f-4144-9f0d-d80c68768d18
@StellaHuang95 Stella Huang (StellaHuang95) changed the title Order inline-script selection persistence and classify future-schema cache backups Harden PEP 723 per-script routing against stale asynchronous selections Aug 25, 2026

if (validBackups.length === 0) {
return { kind: 'missing' };
return { kind: hasUnsupportedBackup ? 'unsupported' : 'missing' };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning · Non-blocking recommendation

When compatible and future-schema backups coexist, validBackups takes precedence over hasUnsupportedBackup, restoring older metadata despite the newer-schema sidecar. Make an unsupported backup dominate restoration and add coverage for the mixed-backup case.

@heejaechang

Copy link
Copy Markdown

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

@StellaHuang95
Stella Huang (StellaHuang95) merged commit c6b1e27 into microsoft:main Aug 26, 2026
44 checks passed
@StellaHuang95
Stella Huang (StellaHuang95) deleted the copilot/pep723-routing-hardening branch August 26, 2026 17:35
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.

3 participants