{"record":{"id":"9e53d5613b88c670","repo":"multica-ai/multica","slug":"rename-temp-to-s-w","errorCode":null,"errorMessage":"rename temp to %s: %w","messagePattern":"rename temp to (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/internal/daemon/execenv/hermes_home.go","lineNumber":933,"sourceCode":"\ttmp, err := os.CreateTemp(dir, \".hermes-tmp-*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create temp for %s: %w\", dst, err)\n\t}\n\ttmpName := tmp.Name()\n\tdefer os.Remove(tmpName) // no-op once renamed\n\tif _, err := tmp.Write(data); err != nil {\n\t\ttmp.Close()\n\t\treturn fmt.Errorf(\"write temp for %s: %w\", dst, err)\n\t}\n\tif err := tmp.Chmod(perm); err != nil {\n\t\ttmp.Close()\n\t\treturn fmt.Errorf(\"chmod temp for %s: %w\", dst, err)\n\t}\n\tif err := tmp.Close(); err != nil {\n\t\treturn fmt.Errorf(\"close temp for %s: %w\", dst, err)\n\t}\n\tif err := os.Rename(tmpName, dst); err != nil {\n\t\treturn fmt.Errorf(\"rename temp to %s: %w\", dst, err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":915,"sourceCodeEnd":937,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/internal/daemon/execenv/hermes_home.go#L915-L937","documentation":"writeFileAtomic wrote, chmod'd, and closed the temp file but os.Rename over the destination failed. The rename-in-same-directory design rules out EXDEV in normal operation, so this is usually a Windows sharing violation (another process holds the open destination) or a permission problem on replacing the destination entry.","triggerScenarios":"On Windows, a reader (Hermes child, AV, indexer) holds dst open at replace time; dst is a directory while the temp is a file; the dir was made read-only or foreign-owned between CreateTemp and Rename;SELinux/AppArmor denying rename.","commonSituations":"A task's Hermes process still reading config.yaml while the next prepare refreshes it; antivirus scanning freshly written temp files on Windows; containers with restrictive MAC policy on the env volume.","solutions":["Stop overlapping processes on the same env (one task per env RootDir; previous child fully exited) and retry.","On Windows, exclude the env root from AV/indexing; retry after handles release.","Check rename permission on the directory for the daemon UID and any MAC denials in audit logs.","Delete the dst file manually if it is stuck; prepare recreates it atomically."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := writeFileAtomic(dst, data, perm)\nif err != nil {\n\tvar le syscall.Errno\n\tif errors.As(err, &le) && le == syscall.Errno(32) { // EACCES/sharing-violation class on Windows\n\t\ttime.Sleep(200 * time.Millisecond)\n\t\terr = writeFileAtomic(dst, data, perm) // holders often release quickly\n\t}\n}\nreturn err","preventionTips":["Ensure the reader of a derived file (Hermes child) has exited before the next prepare replaces it.","Exclude env roots from Windows AV/indexing to avoid rename sharing violations.","One prepare at a time per env RootDir."],"tags":["filesystem","windows","rename","atomic-write","file-locking","hermes"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}