@@ -339,11 +339,8 @@ export class PythonSetupEnvironmentSetup implements Disposable {
339339 * "ready" line for it.
340340 */
341341 private readonly readyRoots = new Set < string > ( ) ;
342- /**
343- * Setup runs started this session. Any later run can rewrite a shared uv
344- * workspace root pyproject.toml, so it makes an older member retry stale.
345- */
346- private runCount = 0 ;
342+ /** The project folder of each setup run this session, in start order. */
343+ private readonly runFolders : string [ ] = [ ] ;
347344 /**
348345 * True when the currently active project has been set up successfully this
349346 * session. Reads the live `projectRoot` so it tracks the active project the
@@ -491,7 +488,7 @@ export class PythonSetupEnvironmentSetup implements Disposable {
491488 trigger ?: PythonSetupRunTrigger
492489 ) : Promise < void > {
493490 const { cli, withProgress} = this . deps ;
494- this . runCount ++ ;
491+ this . runFolders . push ( cwd ) ;
495492
496493 const flags = presetToFlags ( preset ) ;
497494 const invocation : SetupLocalInvocation = {
@@ -580,14 +577,15 @@ export class PythonSetupEnvironmentSetup implements Disposable {
580577 // back to. Without either, fall through to the ordinary doc-link
581578 // handling rather than offer a "retry as DB Connect" that can't work
582579 // (nothing to restore) or would loop (a run that already skipped pins).
583- const cwdForms = result . uvWorkspaceRoot
580+ const isPinConflict =
581+ result . error ?. code === "E_PROVISION_CONFLICT" &&
582+ ! invocation . skipConstraints ;
583+ const cwdForms = isPinConflict
584584 ? [ cwd , await this . realPathForConflict ( cwd ) ]
585585 : [ cwd ] ;
586- const conflictBackups =
587- result . error ?. code === "E_PROVISION_CONFLICT" &&
588- ! invocation . skipConstraints
589- ? conflictBackupsOf ( result , cwdForms )
590- : [ ] ;
586+ const conflictBackups = isPinConflict
587+ ? conflictBackupsOf ( result , cwdForms )
588+ : [ ] ;
591589 const recoverableConflict = conflictBackups . length > 0 ;
592590 const actions = recoverableConflict
593591 ? this . buildConflictRecoveryActions (
@@ -780,11 +778,10 @@ export class PythonSetupEnvironmentSetup implements Disposable {
780778 * (`--no-constraints`). The restore is load-bearing: the conflict fails
781779 * *after* the pins were merged to disk, so `--no-constraints` alone would
782780 * leave the conflicting pins in place and only skip re-adding them. It runs
783- * through {@link runGuarded} — so a click can't race an in-flight run, and
784- * the restore only fires when the retry actually runs — and no-ops once the
785- * project is ready, or once another member synced the same uv workspace, so
786- * a stale toast's Retry can't undo what a later run provisioned. A failed
787- * restore throws before the CLI spawns, leaving showError to log it.
781+ * through {@link runGuarded}, so a click can't race an in-flight run. It
782+ * does nothing once the project is ready, and it asks for a new setup once
783+ * a later run touched the same files, so a stale toast can't undo that run.
784+ * A failed restore throws before the CLI spawns, leaving showError to log it.
788785 * - "Open pyproject.toml" opens the merged file so the user can adjust the
789786 * dependencies that clashed.
790787 */
@@ -794,7 +791,11 @@ export class PythonSetupEnvironmentSetup implements Disposable {
794791 uvWorkspaceRoot : string | undefined ,
795792 backups : ProjectFileBackup [ ]
796793 ) : PythonSetupErrorAction [ ] {
797- const runsAtConflict = this . runCount ;
794+ const runsAtConflict = this . runFolders . length ;
795+ // The files the retry restores: the uv workspace root for a member, else
796+ // the project. A later run inside this folder can have rewritten them;
797+ // a run of the root project is inside it too.
798+ const scope = uvWorkspaceRoot ?? cwd ;
798799 return [
799800 {
800801 label : "Retry DB Connect setup" ,
@@ -804,9 +805,11 @@ export class PythonSetupEnvironmentSetup implements Disposable {
804805 if ( this . readyRoots . has ( cwd ) ) {
805806 return ;
806807 }
807- // Any later run can rewrite a shared uv workspace root file,
808- // also for the root project, whose result names no root.
809- if ( this . runCount !== runsAtConflict ) {
808+ if (
809+ this . runFolders
810+ . slice ( runsAtConflict )
811+ . some ( ( folder ) => containsPath ( scope , folder ) )
812+ ) {
810813 return this . deps . notify (
811814 "Another Python environment setup ran after this " +
812815 "conflict. Run the setup again."
@@ -974,7 +977,6 @@ function conflictBackupsOf(
974977 result : PythonSetupResult ,
975978 cwdForms : string [ ]
976979) : ProjectFileBackup [ ] {
977- const cwd = cwdForms [ 0 ] ;
978980 if ( result . uvWorkspaceRoot ) {
979981 // A member's pins live in the root file, and --no-constraints leaves
980982 // them. Without a root backup, a retry would conflict again.
@@ -987,14 +989,26 @@ function conflictBackupsOf(
987989 ] ;
988990 const { backupPath} = result ;
989991 if ( backupPath ) {
990- // The CLI names the backup from its form of the project folder.
991- const folder =
992- cwdForms . find ( ( form ) => containsPath ( form , backupPath ) ) ?? cwd ;
993- backups . unshift ( { folder , backupPath } ) ;
992+ backups . unshift ( {
993+ folder : backupFolder ( backupPath , cwdForms ) ,
994+ backupPath,
995+ } ) ;
994996 }
995997 return backups ;
996998 }
997999 return result . backupPath
998- ? [ { folder : cwd , backupPath : result . backupPath } ]
1000+ ? [
1001+ {
1002+ folder : backupFolder ( result . backupPath , cwdForms ) ,
1003+ backupPath : result . backupPath ,
1004+ } ,
1005+ ]
9991006 : [ ] ;
10001007}
1008+
1009+ /** The form of the project folder that the CLI named `backupPath` from. */
1010+ function backupFolder ( backupPath : string , cwdForms : string [ ] ) : string {
1011+ return (
1012+ cwdForms . find ( ( form ) => containsPath ( form , backupPath ) ) ?? cwdForms [ 0 ]
1013+ ) ;
1014+ }
0 commit comments