{"record":{"id":"840fb1e1156277d7","repo":"vxcontrol/pentagi","slug":"failed-to-set-temp-file-permissions-w","errorCode":null,"errorMessage":"failed to set temp file permissions: %w","messagePattern":"failed to set temp file permissions: %w","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"backend/pkg/resources/resources.go","lineNumber":294,"sourceCode":"\t}\n\n\ttmp, err := os.CreateTemp(dir, \".resource-upload-*\")\n\tif err != nil {\n\t\treturn \"\", \"\", 0, fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\ttmpPath = tmp.Name()\n\tdefer tmp.Close()\n\n\th := md5.New()\n\tmw := io.MultiWriter(tmp, h)\n\twritten, copyErr := io.Copy(mw, r)\n\tif copyErr != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn \"\", \"\", 0, fmt.Errorf(\"failed to write temp file: %w\", copyErr)\n\t}\n\tif err := tmp.Chmod(0644); err != nil {\n\t\tos.Remove(tmpPath)\n\t\treturn \"\", \"\", 0, fmt.Errorf(\"failed to set temp file permissions: %w\", err)\n\t}\n\n\treturn tmpPath, hex.EncodeToString(h.Sum(nil)), written, nil\n}\n\n// CommitBlob atomically moves tmpPath to the .blob destination for hash.  If\n// the blob already exists (race with concurrent upload of identical file) the\n// tmp file is removed and no error is returned.\nfunc CommitBlob(dataDir, hash, tmpPath string) error {\n\tif err := validateBlobHash(hash); err != nil {\n\t\treturn err\n\t}\n\tif err := EnsureResourcesDir(dataDir); err != nil {\n\t\treturn err\n\t}\n\n\tdest := BlobPath(dataDir, hash)\n\tif _, err := os.Lstat(dest); err == nil {","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/resources/resources.go#L276-L312","documentation":"After copying, SaveToTemp calls tmp.Chmod(0644) to normalize the temp file's permissions; this error wraps a Chmod failure. The temp file is removed before returning, so no partial artifact is left behind.","triggerScenarios":"Chmod fails because the filesystem doesn't support permission changes (some NFS exports, FAT/exFAT mounts, certain FUSE filesystems), or the file was concurrently removed.","commonSituations":"Storing resources on an NFS share with all_squash or on a Windows/SMB mount; Docker volumes backed by a filesystem ignoring chmod; tmpfs quirks in restricted container runtimes.","solutions":["Move the resources/temp directory to a POSIX-permission-capable filesystem (ext4/xfs local volume)","If the mount can't support chmod, patch the workflow to tolerate the failure or use a different storage backend","Check mount options (mount output) and remount without permission-squashing flags","Verify nothing concurrently deletes files from dir during upload"],"exampleFix":"// before\n# docker-compose.yml\n- ./resources:/var/lib/pentagi/resources  # on CIFS/SMB share\n// after\n- pentagi_resources:/var/lib/pentagi/resources  # native docker volume (ext4)","handlingStrategy":"try-catch","validationCode":"func supportsChmod(dir string) error {\n\tf, err := os.CreateTemp(dir, \".chmod-probe-*\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer os.Remove(f.Name())\n\treturn f.Chmod(0644)\n}","typeGuard":null,"tryCatchPattern":"tmpPath, hash, size, err := resources.SaveToTemp(r, dir)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to set temp file permissions\") {\n\t\tlog.Warn(\"filesystem does not support chmod; use a POSIX volume\", \"dir\", dir)\n\t\treturn http.StatusInternalServerError\n\t}\n\treturn err\n}","preventionTips":["Store temp files and blobs on POSIX filesystems (ext4/xfs), not CIFS/exFAT/squashing NFS","Verify volume mount options before deploying (avoid all_squash on the storage share)","Run the chmod probe at startup to fail fast on incompatible mounts","Pin the expected file mode in your deployment checks"],"tags":["filesystem","permissions","chmod"],"backgroundTag":"chmod-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}