{"record":{"id":"10c3c191eab801a4","repo":"github/copilot-sdk","slug":"hashing-existing-s-w","errorCode":null,"errorMessage":"hashing existing %s: %w","messagePattern":"hashing existing (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/internal/embeddedcli/embeddedcli.go","lineNumber":448,"sourceCode":"}\n\nfunc installRuntimePair(installDir string) (string, error) {\n\tnodePath := filepath.Join(installDir, \"runtime.node\")\n\tif err := installVerifiedFile(nodePath, config.RuntimeNode, config.RuntimeNodeHash, 0644, \"runtime.node\"); err != nil {\n\t\treturn \"\", err\n\t}\n\twrapperPath := filepath.Join(installDir, runtimeExecutableName())\n\tif err := installVerifiedFile(wrapperPath, config.RuntimeExecutable, config.RuntimeExecutableHash, 0755, \"runtime wrapper\"); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn wrapperPath, nil\n}\n\nfunc installVerifiedFile(path string, reader io.Reader, expectedHash []byte, mode os.FileMode, label string) error {\n\tif _, err := os.Stat(path); err == nil {\n\t\texistingHash, err := hashFile(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"hashing existing %s: %w\", label, err)\n\t\t}\n\t\tif !bytes.Equal(existingHash, expectedHash) {\n\t\t\treturn fmt.Errorf(\"existing %s hash mismatch\", label)\n\t\t}\n\t\tif runtime.GOOS != \"windows\" && mode.Perm()&0111 != 0 {\n\t\t\tinfo, err := os.Stat(path)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"checking existing %s permissions: %w\", label, err)\n\t\t\t}\n\t\t\tif info.Mode().Perm()&0111 == 0 {\n\t\t\t\tif err := os.Chmod(path, info.Mode().Perm()|mode.Perm()&0111); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"restoring existing %s permissions: %w\", label, err)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/internal/embeddedcli/embeddedcli.go#L430-L466","documentation":"installVerifiedFile first hashes an already-existing file at the target path with hashFile to decide whether it can be reused or must be rewritten. This error wraps a failure of that hashing (the file could not be opened/read), not a hash comparison failure.","triggerScenarios":"The destination path exists (os.Stat succeeds) but hashFile(path) fails — e.g. the file exists but cannot be opened for reading due to permissions, or it disappears between Stat and read.","commonSituations":"A previous install left a root-owned or read-only binary at the target path; a race where another process removes the file between Stat and hashing; antivirus/EDR locking the file on Windows.","solutions":["Fix read permissions on the existing file at the target path (chmod/chown so the current user can read it).","Delete the existing file manually and re-run the install.","Close/whitelist security software that may lock the file, then retry."],"exampleFix":"// before\n$ ls -l ~/.local/bin/cli  # -rw------- root root\n// after\n$ sudo rm ~/.local/bin/cli && client.InstallAt(installDir)","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(target); err == nil {\n    if f, err := os.Open(target); err != nil {\n        // cannot read existing file: fix perms or remove before install\n    } else {\n        f.Close()\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := client.InstallAt(dir); err != nil {\n    if strings.Contains(err.Error(), \"hashing existing\") {\n        // remove the unreadable file and retry the install\n    }\n}","preventionTips":["Install all assets as the same user","Don't mix sudo installs with user runs","Exclude install dirs from AV/EDR locking"],"tags":["hashing","filesystem","permissions"],"backgroundTag":"file-read-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}