{"record":{"id":"060f037abf096738","repo":"github/copilot-sdk","slug":"failed-to-stat-binary-w","errorCode":null,"errorMessage":"failed to stat binary: %w","messagePattern":"failed to stat binary: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"go/cmd/bundler/main.go","lineNumber":1066,"sourceCode":"\t); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to extract runtime wrapper compatibility entrypoint: %w\", err)\n\t}\n\n\t// Verify binary exists\n\tif _, err := os.Stat(binaryPath); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"binary not found after extraction: %w\", err)\n\t}\n\n\t// Make executable on Unix\n\tif !strings.HasSuffix(binaryName, \".exe\") {\n\t\tif err := os.Chmod(binaryPath, 0755); err != nil {\n\t\t\treturn \"\", \"\", fmt.Errorf(\"failed to chmod binary: %w\", err)\n\t\t}\n\t}\n\n\tstat, err := os.Stat(binaryPath)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to stat binary: %w\", err)\n\t}\n\tsizeMB := float64(stat.Size()) / 1024 / 1024\n\tfmt.Printf(\"Downloaded %s (%.1f MB)\\n\", binaryName, sizeMB)\n\n\treturn binaryPath, tarballPath, nil\n}\n\n// extractCLILicense writes the license from the verified release package next to outputPath.\nfunc extractCLILicense(tarballPath, outputPath string) error {\n\toutputDir := filepath.Dir(outputPath)\n\tif outputDir == \"\" {\n\t\toutputDir = \".\"\n\t}\n\tlicensePath := licensePathForOutput(outputPath)\n\tif _, err := os.Stat(licensePath); err == nil {\n\t\treturn nil\n\t}\n","sourceCodeStart":1048,"sourceCodeEnd":1084,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L1048-L1084","documentation":"After making the binary executable, the bundler stats it again to report its size in MB before returning. If this second os.Stat fails, this error wraps it. The binary is in place, but its final metadata could not be read.","triggerScenarios":"os.Stat(binaryPath) fails immediately after the chmod step — file removed by an external process (AV scan, cleanup job) between chmod and stat, or handle/permission anomaly on the destination.","commonSituations":"Aggressive cleanup daemons purging temp dirs mid-build; race with another build removing the same directory; unusual filesystems that fail stat on just-chmodded files.","solutions":["Re-run the build; this is nearly always a race with an external process.","Disable or configure temp-dir cleanup/AV services that touch destDir during builds.","Use a private per-build destination directory to avoid interference.","Check filesystem health if the error reproduces consistently."],"exampleFix":"// before: shared temp dir prone to cleanup\ndestDir := filepath.Join(\"/tmp\", \"shared-cli\")\n\n// after: per-process dir\n destDir := filepath.Join(os.TempDir(), fmt.Sprintf(\"cli-%d\", os.Getpid()))","handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(binaryPath)\nif err == nil && info.Mode()&0o111 == 0 {\n    return fmt.Errorf(\"binary at %s is not executable\", binaryPath)\n}","typeGuard":null,"tryCatchPattern":"if err := buildBundle(...); err != nil {\n    if strings.Contains(err.Error(), \"failed to stat binary\") {\n        return retryBuildOnce() // transient race most likely\n    }\n    return err\n}","preventionTips":["Keep background cleanup/AV services from scanning build dirs mid-run.","Use isolated per-build temp directories.","Retry transient stat races once before failing the pipeline.","Monitor for external processes touching the build output path."],"tags":["filesystem","stat","race","go"],"backgroundTag":"file-not-found","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}