{"record":{"id":"b9209ee264a4689c","repo":"multica-ai/multica","slug":"create-s-copy-s-w","errorCode":null,"errorMessage":"create %s copy %s: %w","messagePattern":"create (.+?) copy (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/internal/daemon/execenv/codex_home.go","lineNumber":1038,"sourceCode":"\t\t}\n\t}\n\tif _, err := root.Lstat(relPath); err == nil {\n\t\tif err := root.Remove(relPath); err != nil {\n\t\t\treturn fmt.Errorf(\"remove stale %s copy %s: %w\", key, relPath, err)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"stat %s copy %s: %w\", key, relPath, err)\n\t}\n\n\tin, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open %s %s: %w\", key, src, err)\n\t}\n\tdefer in.Close()\n\n\tout, err := root.OpenFile(relPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create %s copy %s: %w\", key, relPath, err)\n\t}\n\tdefer out.Close()\n\n\tif _, err := io.Copy(out, in); err != nil {\n\t\treturn fmt.Errorf(\"copy %s %s to %s: %w\", key, src, relPath, err)\n\t}\n\t// Close explicitly so a deferred write-back failure cannot be swallowed; the\n\t// deferred Close then no-ops.\n\tif err := out.Close(); err != nil {\n\t\treturn fmt.Errorf(\"close %s copy %s: %w\", key, relPath, err)\n\t}\n\treturn nil\n}\n\n// syncCodexModelsCache seeds models_cache.json once for a fresh task home and\n// binds it to the shared provider/catalog configuration. Codex can replace the\n// task-local cache after startup, so an unchanged binding preserves whatever\n// the task last wrote rather than restoring a potentially stale shared copy.","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/daemon/execenv/codex_home.go#L1020-L1056","documentation":"The destination file inside the verified task home is created with root.OpenFile using O_EXCL, so creation fails if the entry already exists after the stale-removal step, if permissions deny, or if an intermediate symlink escapes the root. This is the exclusive-create safeguard that prevents overwriting anything unexpectedly.","triggerScenarios":"relPath was recreated between the Remove and the OpenFile; the containing directory is not writable; an escaping symlink sits in the path.","commonSituations":"Concurrent process writing the same config path; directory permissions changed by prior task.","solutions":["Re-run prepare — the stale-removal step will clear a pre-existing entry","Ensure the task home directory is writable by the daemon","Remove any escaping symlink on the destination path"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := materialiseInCodexHome(...); err != nil && strings.Contains(err.Error(), \"create \"+key+\" copy\") {\n\terr = materialiseInCodexHome(...) // stale-removal step clears the entry\n}","preventionTips":["Avoid concurrent writers to the same config paths in the task home","Ensure the home directory is writable before prepare"],"tags":["filesystem","codex-home","race-condition"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}