Merge pull request #80 from bnema/fix/ci-flaky-tests
fix(subagents): skip directory sync on Windows
3 files · +29 -11
M packages/agent/subagents/persist.go +3 -11
| @@ -226,19 +226,11 @@ func writeAgentMeta(stateDir string, a *Agent) error { | |||
| 226 | 226 | return fmt.Errorf("subagent meta rename: %w", err) | |
| 227 | 227 | } | |
| 228 | 228 | removeTemp = false | |
| 229 | - | // Sync the containing directory so the rename itself survives a host | |
| 230 | - | // crash, not just the bytes in the temporary file. | |
| 231 | - | dir, err := os.Open(stateDir) | |
| 232 | - | if err != nil { | |
| 233 | - | return fmt.Errorf("subagents meta directory open: %w", err) | |
| 234 | - | } | |
| 235 | - | if err := dir.Sync(); err != nil { | |
| 236 | - | _ = dir.Close() | |
| 229 | + | // Sync the containing directory where the platform supports it so the | |
| 230 | + | // rename itself survives a host crash, not just the temporary file bytes. | |
| 231 | + | if err := syncDirectory(stateDir); err != nil { | |
| 237 | 232 | return fmt.Errorf("subagents meta directory sync: %w", err) | |
| 238 | 233 | } | |
| 239 | - | if err := dir.Close(); err != nil { | |
| 240 | - | return fmt.Errorf("subagents meta directory close: %w", err) | |
| 241 | - | } | |
| 242 | 234 | return nil | |
| 243 | 235 | } | |
| 244 | 236 | ||
| @@ -226,19 +226,11 @@ func writeAgentMeta(stateDir string, a *Agent) error { | |||||
| 226 | return fmt.Errorf("subagent meta rename: %w", err) | 226 | return fmt.Errorf("subagent meta rename: %w", err) | ||
| 227 | } | 227 | } | ||
| 228 | removeTemp = false | 228 | removeTemp = false | ||
| 229 | - | // Sync the containing directory so the rename itself survives a host | 229 | + | // Sync the containing directory where the platform supports it so the |
| 230 | - | // crash, not just the bytes in the temporary file. | 230 | + | // rename itself survives a host crash, not just the temporary file bytes. |
| 231 | - | dir, err := os.Open(stateDir) | 231 | + | if err := syncDirectory(stateDir); err != nil { |
| 232 | - | if err != nil { | |||
| 233 | - | return fmt.Errorf("subagents meta directory open: %w", err) | |||
| 234 | - | } | |||
| 235 | - | if err := dir.Sync(); err != nil { | |||
| 236 | - | _ = dir.Close() | |||
| 237 | return fmt.Errorf("subagents meta directory sync: %w", err) | 232 | return fmt.Errorf("subagents meta directory sync: %w", err) | ||
| 238 | } | 233 | } | ||
| 239 | - | if err := dir.Close(); err != nil { | |||
| 240 | - | return fmt.Errorf("subagents meta directory close: %w", err) | |||
| 241 | - | } | |||
| 242 | return nil | 234 | return nil | ||
| 243 | } | 235 | } | ||
| 244 | 236 | ||||
A packages/agent/subagents/syncdir_unix.go +17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | + | //go:build !windows | |
| 2 | + | ||
| 3 | + | package subagents | |
| 4 | + | ||
| 5 | + | import "os" | |
| 6 | + | ||
| 7 | + | func syncDirectory(path string) error { | |
| 8 | + | dir, err := os.Open(path) | |
| 9 | + | if err != nil { | |
| 10 | + | return err | |
| 11 | + | } | |
| 12 | + | if err := dir.Sync(); err != nil { | |
| 13 | + | _ = dir.Close() | |
| 14 | + | return err | |
| 15 | + | } | |
| 16 | + | return dir.Close() | |
| 17 | + | } | |
| @@ -0,0 +1,17 @@ | |||||
| 1 | + | //go:build !windows | |||
| 2 | + | ||||
| 3 | + | package subagents | |||
| 4 | + | ||||
| 5 | + | import "os" | |||
| 6 | + | ||||
| 7 | + | func syncDirectory(path string) error { | |||
| 8 | + | dir, err := os.Open(path) | |||
| 9 | + | if err != nil { | |||
| 10 | + | return err | |||
| 11 | + | } | |||
| 12 | + | if err := dir.Sync(); err != nil { | |||
| 13 | + | _ = dir.Close() | |||
| 14 | + | return err | |||
| 15 | + | } | |||
| 16 | + | return dir.Close() | |||
| 17 | + | } | |||
A packages/agent/subagents/syncdir_windows.go +9 -0
| @@ -0,0 +1,9 @@ | |||
| 1 | + | //go:build windows | |
| 2 | + | ||
| 3 | + | package subagents | |
| 4 | + | ||
| 5 | + | // Windows does not support syncing a directory handle through os.File.Sync. | |
| 6 | + | // The metadata file itself is synced before the atomic rename. | |
| 7 | + | func syncDirectory(string) error { | |
| 8 | + | return nil | |
| 9 | + | } | |
| @@ -0,0 +1,9 @@ | |||||
| 1 | + | //go:build windows | |||
| 2 | + | ||||
| 3 | + | package subagents | |||
| 4 | + | ||||
| 5 | + | // Windows does not support syncing a directory handle through os.File.Sync. | |||
| 6 | + | // The metadata file itself is synced before the atomic rename. | |||
| 7 | + | func syncDirectory(string) error { | |||
| 8 | + | return nil | |||
| 9 | + | } | |||