Repository navigation
Isolate macOS file watchers in child processes - #5527
AmethystLiang wants to merge 1 commit into
Conversation
@parcel/watcher/FSEvents can produce a SIGTRAP after macOS sleep-wake that previously killed Electron's main process. Both filesystem-watcher and runtime-file-explorer now fork a disposable child process on macOS, so a native addon crash tears down only the child and the host can auto-restart it with an overflow event rather than going down entirely. Co-authored-by: Orca <[email protected]>
|
Ready to review this PR? Stage has broken it down into 5 individual chapters for you: Chapters generated by Stage for commit 2afa3a5 on Jun 16, 2026 9:18pm UTC. |
📝 WalkthroughWalkthroughThis pull request introduces an out-of-process filesystem watcher for macOS. A new 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8e912e23-4e57-44c1-acf1-445c9665b11c
📒 Files selected for processing (19)
config/electron-builder.config.cjsconfig/packaged-runtime-node-modules.cjsconfig/scripts/electron-builder-config.test.mjselectron.vite.config.tssrc/main/ipc/filesystem-watcher-child.tssrc/main/ipc/filesystem-watcher-event-normalization.test.tssrc/main/ipc/filesystem-watcher-event-normalization.tssrc/main/ipc/filesystem-watcher-large-batch.test.tssrc/main/ipc/filesystem-watcher-local-unsubscribe.test.tssrc/main/ipc/filesystem-watcher-process-host.test.tssrc/main/ipc/filesystem-watcher-process-host.tssrc/main/ipc/filesystem-watcher-real.test.tssrc/main/ipc/filesystem-watcher.tssrc/main/runtime/file-watcher-host.test.tssrc/main/runtime/file-watcher-host.tssrc/main/runtime/file-watcher-worker.tssrc/main/runtime/orca-runtime-files-watch.test.tssrc/main/runtime/orca-runtime-files.test.tssrc/main/runtime/orca-runtime-files.ts
| if (!existsSync(filePath)) { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Fail fast if required unpacked runtime files are missing.
On Line 240, silently continue-ing lets packaging regressions ship undetected. If out/main/filesystem-watcher-child.js is absent, packaged macOS watcher forking will fail at runtime instead of failing the build.
Suggested fix
const unpackedRoot = join(resourcesDir, 'app.asar.unpacked')
for (const file of PACKAGED_UNPACKED_MAIN_RUNTIME_FILES) {
const filePath = join(unpackedRoot, ...file.split('/'))
if (!existsSync(filePath)) {
- continue
+ throw new Error(`Packaged main file ${file} was not found in ${unpackedRoot}`)
}
addMissingPackagedRuntimeDeps(resourcesDir, readFileSync(filePath, 'utf8'), missing)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!existsSync(filePath)) { | |
| continue | |
| } | |
| const unpackedRoot = join(resourcesDir, 'app.asar.unpacked') | |
| for (const file of PACKAGED_UNPACKED_MAIN_RUNTIME_FILES) { | |
| const filePath = join(unpackedRoot, ...file.split('/')) | |
| if (!existsSync(filePath)) { | |
| throw new Error(`Packaged main file ${file} was not found in ${unpackedRoot}`) | |
| } | |
| addMissingPackagedRuntimeDeps(resourcesDir, readFileSync(filePath, 'utf8'), missing) | |
| } |
| function reportWatchError(err: unknown): void { | ||
| postToHost({ | ||
| type: 'error', | ||
| message: err instanceof Error ? err.message : String(err) | ||
| }) | ||
| reportOverflow() | ||
| } |
There was a problem hiding this comment.
Add a short “why” comment for dual error+overflow emission.
Lines 113-119 intentionally emit both an IPC error and an overflow event, which is a non-obvious recovery contract. Please add a 1–2 line rationale inline so this behavior isn’t removed inadvertently.
As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”
Source: Coding guidelines
| if (prev.type === 'create' && evt.type === 'delete') { | ||
| lastByPath.delete(p) | ||
| deleteBeforeCreate.delete(p) | ||
| continue |
There was a problem hiding this comment.
Preserve terminal deletes for delete → create → delete sequences.
This branch currently drops the path entirely, which can erase an earlier delete marker and coalesce a terminal delete to nothing. That can leave stale entries visible until a later refresh.
Proposed fix
- if (prev.type === 'create' && evt.type === 'delete') {
- lastByPath.delete(p)
- deleteBeforeCreate.delete(p)
- continue
- }
+ if (prev.type === 'create' && evt.type === 'delete') {
+ if (deleteBeforeCreate.has(p)) {
+ // Collapse delete->create->delete to a final delete.
+ deleteBeforeCreate.delete(p)
+ lastByPath.set(p, { type: 'delete', path: p, index: i })
+ } else {
+ // Plain create->delete cancels out.
+ lastByPath.delete(p)
+ }
+ continue
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (prev.type === 'create' && evt.type === 'delete') { | |
| lastByPath.delete(p) | |
| deleteBeforeCreate.delete(p) | |
| continue | |
| if (prev.type === 'create' && evt.type === 'delete') { | |
| if (deleteBeforeCreate.has(p)) { | |
| // Collapse delete->create->delete to a final delete. | |
| deleteBeforeCreate.delete(p) | |
| lastByPath.set(p, { type: 'delete', path: p, index: i }) | |
| } else { | |
| // Plain create->delete cancels out. | |
| lastByPath.delete(p) | |
| } | |
| continue | |
| } |
|
Closing as superseded by the process-isolated Parcel watcher implementation already on I checked both paths this PR addresses: desktop That implements the core crash-isolation and recovery goal here across the desktop and runtime paths. Adding the two separate macOS-only child hosts from this PR would duplicate and bypass the current shared supervisor/pool lifecycle. This closure is based on the implemented replacement, not the age or rebase conflicts. Current implementation evidence: |
Summary
Testing
Made with Orca 🐋