You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Add serialized installation with retry logic to prevent cache race conditions
Fixes#72 - The root cause was race conditions when multiple provider packages
are installed in parallel, causing Bun cache corruption ("FileNotFound: failed
copying files from cache").
Changes:
- Add write lock to serialize package installations
- Add retry logic (up to 3 attempts) for cache-related errors
- Improve error detection for ENOENT, EACCES, EBUSY errors
- Add 500ms delay between retry attempts
- Remove fallback behavior - opencode/grok-code remains the default
This ensures the first run after installation works reliably.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: .changeset/graceful-provider-fallback.md
+14-9Lines changed: 14 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,24 @@
2
2
'@link-assistant/agent': patch
3
3
---
4
4
5
-
fix: Add graceful fallback when provider initialization fails
5
+
fix: Add retry logic and serialized installation for reliable provider initialization
6
6
7
-
Fixes issue #72 where version 0.3.0 appeared "completely broken" due to Bun package cache corruption preventing opencode provider initialization. The agent now gracefully falls back to alternative providers when initialization fails, improving resilience and user experience.
7
+
Fixes issue #72 where version 0.3.0 appeared "completely broken" due to race conditions in parallel package installations causing Bun cache corruption.
8
+
9
+
Root Cause:
10
+
11
+
- When multiple provider packages (e.g., @ai-sdk/openai-compatible, @ai-sdk/openai) are installed concurrently, they can cause race conditions in Bun's package cache
12
+
- This leads to "FileNotFound: failed copying files from cache" errors on first run after update
8
13
9
14
Changes:
10
15
11
-
-Test provider initialization before selecting it as default
12
-
-Fall back to alternative providers if opencode provider fails to initialize
13
-
-Add helpful error messages when Bun cache corruption is detected
14
-
-Log warnings with detailed error information for troubleshooting
16
+
-Add write lock to serialize package installations (prevents concurrent bun add commands)
17
+
-Add retry logic with up to 3 attempts for cache-related errors
18
+
-Improve error detection to catch ENOENT, EACCES, EBUSY errors
19
+
-Add delay between retries to allow filesystem operations to complete
15
20
16
21
Impact:
17
22
18
-
-Agent no longer crashes when provider initialization fails
19
-
-Better error messages guide users to recovery steps
20
-
-Improved stability in production environments
23
+
-opencode/grok-code remains the default provider and works reliably
24
+
-Agent handles transient cache issues gracefully with automatic retries
25
+
-Better stability during first run after installation/update
@@ -348,8 +339,12 @@ bun install -g @link-assistant/agent@0.2.1
348
339
349
340
## Conclusion
350
341
351
-
Version 0.3.0 is NOT fundamentally broken in code, but **fails due to Bun runtime cache corruption** when trying to initialize the new default opencode provider. The issue is **environmental** rather than a code defect.
342
+
Version 0.3.0 is NOT fundamentally broken in code, but **fails due to race conditions in parallel package installations** causing Bun cache corruption when trying to initialize the new default opencode provider. The issue is **environmental** rather than a code defect.
343
+
344
+
**Implemented Fix:**
352
345
353
-
**Implemented Fix:** Added graceful fallback in `Provider.defaultModel()` to try opencode provider first, and if it fails, skip it and fall back to other available providers. This makes the agent resilient to provider initialization failures.
346
+
1.**Serialized package installations** - Added a write lock to ensure only one `bun add` command runs at a time, preventing race conditions
347
+
2.**Retry logic for cache errors** - Added automatic retry (up to 3 attempts) for cache-related errors with a 500ms delay between attempts
0 commit comments