Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Fix snapshotRepairFile to distinguish missing files from unreadable files

Cursor Agent1549b059dce6
diff --git a/cli/beacon/cmd/endpoint_diagnostics.go b/cli/beacon/cmd/endpoint_diagnostics.go
index 8dbcb5ff..6c77128d 100644
--- a/cli/beacon/cmd/endpoint_diagnostics.go
+++ b/cli/beacon/cmd/endpoint_diagnostics.go
@@ -87,6 +87,7 @@ type repairFileSnapshot struct {
existed bool
data []byte
mode os.FileMode
+ readErr error
}
type repairRollback struct {
@@ -978,7 +979,10 @@ func rollbackRepairError(err error, rollback *repairRollback) error {
func snapshotRepairFile(path string) repairFileSnapshot {
data, err := os.ReadFile(path)
if err != nil {
- return repairFileSnapshot{}
+ if errors.Is(err, os.ErrNotExist) {
+ return repairFileSnapshot{}
+ }
+ return repairFileSnapshot{existed: true, readErr: err}
}
snapshot := repairFileSnapshot{existed: true, data: data}
if info, statErr := os.Stat(path); statErr == nil {
@@ -994,6 +998,9 @@ func restoreRepairFile(path string, snapshot repairFileSnapshot) error {
}
return nil
}
+ if snapshot.readErr != nil {
+ return fmt.Errorf("cannot restore %s: pre-repair snapshot failed: %w", path, snapshot.readErr)
+ }
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return err
}