{"record":{"id":"fc3002e464b29fbb","repo":"gastownhall/beads","slug":"failed-to-sync-temp-file-w","errorCode":null,"errorMessage":"failed to sync temp file: %w","messagePattern":"failed to sync temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/backup_export.go","lineNumber":112,"sourceCode":"//     that must preserve a symlink's target should resolve path with\n//     filepath.EvalSymlinks first (see cmd/bd/proxied_server.go).\nfunc atomicWriteFile(path string, data []byte) error {\n\tdir := filepath.Dir(path)\n\ttmp, err := os.CreateTemp(dir, \".backup-tmp-*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\ttmpPath := tmp.Name()\n\n\tif _, err := tmp.Write(data); err != nil {\n\t\t_ = tmp.Close()\n\t\t_ = os.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to write temp file: %w\", err)\n\t}\n\tif err := tmp.Sync(); err != nil {\n\t\t_ = tmp.Close()\n\t\t_ = os.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to sync temp file: %w\", err)\n\t}\n\tif err := tmp.Close(); err != nil {\n\t\t_ = os.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to close temp file: %w\", err)\n\t}\n\tif err := os.Rename(tmpPath, path); err != nil {\n\t\t_ = os.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to rename temp file: %w\", err)\n\t}\n\treturn nil\n}\n\n// runBackupExport performs a Dolt-native backup to .beads/backup/.\n// Returns the updated state.\nfunc runBackupExport(ctx context.Context, force bool) (*backupState, error) {\n\tdir, err := backupDir()\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/backup_export.go#L94-L130","documentation":"atomicWriteFile calls tmp.Sync() to fsync the temp file's contents to disk before renaming, guaranteeing durability. This wraps a Sync failure; the temp file is cleaned up and the destination is left unchanged.","triggerScenarios":"tmp.Sync() returns an error: underlying storage I/O error, failing disk, network filesystem (NFS/CIFS) that doesn't support fsync reliably, or device errors surfaced at flush time.","commonSituations":"Running .beads on flaky NFS mounts; failing SSD/HDD reporting errors under load; virtualized storage backends with fsync issues.","solutions":["Check kernel logs for I/O errors: dmesg | grep -i 'i/o error'.","If the workspace is on NFS/network storage, move it to local disk or a more reliable mount.","Run filesystem health checks (fsck) on the affected volume.","Retry after the storage issue is resolved; no corrupt state file will have been written."],"exampleFix":"// shell\ndmesg | tail   # look for I/O errors on the device holding .beads\n# then move workspace to healthy local storage and retry","handlingStrategy":"retry","validationCode":"// fsync failures surface only at write time; validate storage health beforehand:\n// dmesg | grep -i 'i/o error'  and ensure .beads is not on a flaky NFS mount","typeGuard":null,"tryCatchPattern":"if err := saveBackupState(dir, state); err != nil {\n    if strings.Contains(err.Error(), \"sync temp file\") {\n        log.Printf(\"storage fsync failed; check disk/NFS health: %v\", err)\n        return err\n    }\n    return err\n}","preventionTips":["Keep .beads on local or reliable storage, not flaky network mounts","Watch kernel logs for device I/O errors","Run periodic filesystem checks on the hosting volume"],"tags":["go","filesystem","fsync","io"],"backgroundTag":"io-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}