Skip to content

Commit 16d16b3

Browse files
aledbfclaude
andcommitted
features: each run stages its Features in a folder of its own
The features folder is <cacheFolder>/container-features/<cliVersion>-<ms>, TS createFeaturesTempFolder's name, made with MkdirAll. Two runs started in the same millisecond shared it, and one run's realignFeatureDirs renamed and removed the other's .stage- folders: "stage feature h_0: lstat .../.stage-0: no such file or directory", which failed main's parity job on 2026-11-07 and 2026-11-08. The folder is now created with Mkdir, and a name another run holds moves to the next millisecond. The compose path that made the folder by hand goes through the same function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 80d4637 commit 16d16b3

3 files changed

Lines changed: 38 additions & 6 deletions

File tree

‎internal/cli/compose_up.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ func (r *upRunner) buildAndExtendCompose(ctx context.Context, s composeStart, pe
469469
if opts.omitSyntaxDirective {
470470
syntax = ""
471471
}
472-
dstFolder = filepath.Join(cacheFolder(), "container-features", fmt.Sprintf("%s-%d", cliVersion(), time.Now().UnixMilli()))
473-
if err := os.MkdirAll(dstFolder, 0o755); err != nil {
474-
return nil, fmt.Errorf("create features folder: %w", err)
472+
var err error
473+
if dstFolder, err = createFeaturesFolder(); err != nil {
474+
return nil, err
475475
}
476476
info = imagemeta.GenerateComposeLabelBuild(baseName, labelMetadata, syntax)
477477
default:

‎internal/cli/feature_install.go‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,25 @@ func (r localFeatureRoots) resolve(logger log.Logger, id string) (string, bool,
127127

128128
// createFeaturesFolder creates the folder the Features are staged in, TS
129129
// createFeaturesTempFolder: <cacheFolder>/container-features/<cliVersion>-<ms>.
130+
// The folder is this run's alone: runs started in the same millisecond would
131+
// otherwise share it, and one run's realignFeatureDirs renames and removes the
132+
// other's .stage- folders. A name another run holds moves to the next
133+
// millisecond.
130134
func createFeaturesFolder() (string, error) {
131-
dir := filepath.Join(cacheFolder(), "container-features", fmt.Sprintf("%s-%d", cliVersion(), time.Now().UnixMilli()))
132-
if err := os.MkdirAll(dir, 0o755); err != nil {
135+
parent := filepath.Join(cacheFolder(), "container-features")
136+
if err := os.MkdirAll(parent, 0o755); err != nil {
133137
return "", fmt.Errorf("create features folder: %w", err)
134138
}
135-
return dir, nil
139+
for ms := time.Now().UnixMilli(); ; ms++ {
140+
dir := filepath.Join(parent, fmt.Sprintf("%s-%d", cliVersion(), ms))
141+
err := os.Mkdir(dir, 0o755)
142+
if err == nil {
143+
return dir, nil
144+
}
145+
if !errors.Is(err, os.ErrExist) {
146+
return "", fmt.Errorf("create features folder: %w", err)
147+
}
148+
}
136149
}
137150

138151
// fetchFeatureSetsWithOrder resolves the feature dependency graph through the

‎internal/cli/feature_install_test.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,22 @@ func TestReadConfigurationRefusesALocalFeatureOutsideDevcontainer(t *testing.T)
460460
}
461461
wantExitCode(t, err, 1)
462462
}
463+
464+
// Runs started in the same millisecond each get a features folder of their
465+
// own: a shared one let one run's realignFeatureDirs remove the other's
466+
// .stage- folders ("stage feature h_0: lstat .../.stage-0: no such file or
467+
// directory" in the parity lane).
468+
func TestCreateFeaturesFolderIsTheRunsAlone(t *testing.T) {
469+
t.Setenv("TMPDIR", t.TempDir())
470+
seen := map[string]bool{}
471+
for range 50 {
472+
dir, err := createFeaturesFolder()
473+
if err != nil {
474+
t.Fatal(err)
475+
}
476+
if seen[dir] {
477+
t.Fatalf("%s handed out twice", dir)
478+
}
479+
seen[dir] = true
480+
}
481+
}

0 commit comments

Comments
 (0)