fix: handle concurrent file edits and symlink loops#65
Conversation
Add readFileSafe helper that retries on transient OS errors (EBUSY/EACCES/EPERM) from editors performing non-atomic saves. Replace bare readFileSync calls in builder.js (3 sites) and watcher.js (1 site). Add symlink loop detection to collectFiles via realpathSync tracking of visited directories, preventing infinite recursion from circular symlinks. Update architecture.md sections #7, #15, and summary table to reflect these fixes. Impact: 5 functions changed, 5 affected
|
Claude finished @carlos-alm's task —— View job PR Review CompleteReview Checklist:
Root Cause AnalysisProblem Being Solved: Two legitimate operational issues: (1) Transient OS errors (EBUSY/EACCES/EPERM) when editors perform non-atomic saves causing file reads to fail intermittently, and (2) Infinite recursion when Why This Approach: The solutions address real root causes, not symptoms:
Risk Assessment: Low risk. These are defensive fixes that only activate under error conditions that currently cause failures. Critical ConcernsNone. This is exactly the kind of defensive programming needed for robust file system interaction. Configuration Change DetectionNo configuration changes detected. No linting rules, test thresholds, or build configs modified. Test IntegrityExcellent test hygiene. No tests were modified or weakened. All 463 existing tests pass, demonstrating the changes don't break existing functionality. The fixes are additive defensive measures. Code Quality Assessment
|
Greptile SummaryThis PR introduces two defensive fixes for edge cases in file handling: transient OS error retries and symlink loop detection. Key changes:
The implementation is clean and handles edge cases gracefully (e.g., Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 24f8ab1 |
src/builder.js
Outdated
| return fs.readFileSync(filePath, 'utf-8'); | ||
| } catch (err) { | ||
| if (attempt < retries && TRANSIENT_CODES.has(err.code)) { | ||
| Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, RETRY_DELAY_MS); |
There was a problem hiding this comment.
Atomics.wait cannot be used on the main thread in Node.js — it will throw "Atomics.wait cannot be called in this context". Use a simple synchronous sleep implementation instead:
| Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, RETRY_DELAY_MS); | |
| const end = Date.now() + RETRY_DELAY_MS; | |
| while (Date.now() < end) {} |
There was a problem hiding this comment.
Fixed in 24f8ab1 — replaced with Date.now() busy-wait loop. Good catch.
Atomics.wait throws on Node.js main thread. Replace with Date.now() busy-wait loop for the 50ms retry delay. Also sync package-lock.json with package.json v2.2.1 platform packages to fix CI license scan. Impact: 1 functions changed, 2 affected
|
Claude finished @carlos-alm's task —— View job PR Review CompleteReview Checklist:
Root Cause AnalysisProblem Being Solved: Two legitimate operational issues: (1) Transient OS errors (EBUSY/EACCES/EPERM) when editors perform non-atomic saves causing file reads to fail intermittently, and (2) Infinite recursion when Why This Approach: The solutions address real root causes, not symptoms:
Risk Assessment: Low risk. These are defensive fixes that only activate under error conditions that currently cause failures. Critical ConcernsNone. This is exactly the kind of defensive programming needed for robust file system interaction. Configuration Change DetectionNo configuration changes detected. No linting rules, test thresholds, or build configs modified. Test IntegrityExcellent test hygiene. No tests were modified or weakened. All 463 existing tests pass, demonstrating the changes don't break existing functionality. The fixes are additive defensive measures. Code Quality Assessment
|
Summary
readFileSafehelper inbuilder.jsthat retries on transient OS errors (EBUSY/EACCES/EPERM) caused by editors performing non-atomic saves — replaces barereadFileSyncin 3 builder sites and 1 watcher sitecollectFilesviarealpathSyncvisited-set tracking, preventing infinite recursion from circular symlinksgenerated/architecture.mdsections Bump tree-sitter-python from 0.23.6 to 0.25.0 #7, fix: rewrite v1.4.0 changelog and add license scan allowlist #15, and summary table to reflect these fixesTest plan
npm test)npm run lint)node src/cli.js build .)