Repository navigation
fix(packaging): include @parcel/watcher native addon in packaged runtime - #4860
Conversation
The main-process filesystem watcher imports @parcel/watcher, whose native .node binary lives in a platform-specific optionalDependency (e.g. @parcel/watcher-linux-x64-glibc). It was in neither asarUnpack nor PACKAGED_RUNTIME_PACKAGE_ROOTS, so packaged builds (incl. the Linux serve AppImage) threw "Cannot find package '@parcel/watcher'" and silently ran with no filesystem watching — file changes never propagated to clients. Add @parcel/watcher to the packaged runtime roots, follow its installed platform optional-subpackages into the closure, and prune non-target platforms in afterPack (mirroring node-pty handling). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…runing Add a regression guard that createPackagedRuntimeNodeModuleResources() includes @parcel/watcher (the missing dep behind stablyai#4851) plus a platform subpackage, and a prunePackagedParcelWatcher test asserting the core package and matching-platform subpackages survive while other platforms are dropped. Mirrors the existing node-pty prune coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds ChangesParcel Watcher Platform-Specific Packaging
Possibly related issues
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
✅ No new issues found.
Reviewed changes — adds @parcel/watcher and its platform-specific native subpackages to the packaged runtime closure, plus a matching prune step, mirroring the existing node-pty pattern.
- Add
@parcel/watchertoPACKAGED_RUNTIME_PACKAGE_ROOTS— ensures the main watcher package is collected into theResources/node_modulesclosure. - Walk
@parcel/watcher'soptionalDependenciesduring closure collection — the dependency graph alone never reaches platform-specific subpackages (e.g.@parcel/watcher-linux-x64-glibc), so they are explicitly visited by name. Missing subpackages (not installed for this build) are silently skipped. - Add
prunePackagedParcelWatcher— after the closure is assembled, drops non-target platform subpackage directories so a Linux serve doesn't ship macOS/Windows.nodebinaries. - Wire prune into
prunePackagedRuntimeNodeModules— theafterPackhook already calls this, so no config change needed. - Add tests — a closure-inclusion guard that
@parcel/watcher+ at least one platform subpackage land in the packaged set, and a prune test that verifies only core + matching-platform subpackage directories survive.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
🧹 Nitpick comments (1)
config/packaged-runtime-node-modules.cjs (1)
224-231: ⚡ Quick winNarrow pruning to
watcher-*entries only.Line 231 currently deletes any non-
watcherdirectory undernode_modules/@parcel. If unrelated@parcel/*packages are later included in runtime roots, this will remove valid runtime deps.Suggested hardening
for (const entry of readdirSync(parcelDir, { withFileTypes: true })) { - if (!entry.isDirectory() || entry.name === 'watcher') { + if (!entry.isDirectory()) { + continue + } + if (entry.name === 'watcher') { + continue + } + if (!entry.name.startsWith('watcher-')) { continue } if (keepPrefix && entry.name.startsWith(keepPrefix)) { continue }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@config/packaged-runtime-node-modules.cjs` around lines 224 - 231, The loop currently deletes every directory under parcelDir except the literal 'watcher', which is too broad; change the filter so only directories whose names match the watcher pattern are removed. In the readdirSync loop, replace the current name check (entry.name === 'watcher') with a startsWith check for the watcher prefix (e.g., entry.name.startsWith('watcher-')), and keep the existing keepPrefix check (keepPrefix && entry.name.startsWith(keepPrefix)) so protected entries are skipped; then call rmSync(join(parcelDir, entry.name), { recursive: true, force: true }) only for entries that pass the watcher-* test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@config/packaged-runtime-node-modules.cjs`:
- Around line 224-231: The loop currently deletes every directory under
parcelDir except the literal 'watcher', which is too broad; change the filter so
only directories whose names match the watcher pattern are removed. In the
readdirSync loop, replace the current name check (entry.name === 'watcher') with
a startsWith check for the watcher prefix (e.g.,
entry.name.startsWith('watcher-')), and keep the existing keepPrefix check
(keepPrefix && entry.name.startsWith(keepPrefix)) so protected entries are
skipped; then call rmSync(join(parcelDir, entry.name), { recursive: true, force:
true }) only for entries that pass the watcher-* test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 95f81475-8210-465f-81d1-c4ea3d9b6582
📒 Files selected for processing (2)
config/packaged-runtime-node-modules.cjsconfig/scripts/electron-builder-config.test.mjs
… test The existing filesystem-watcher tests all mock '@parcel/watcher', so they stay green even when the native addon is absent from the packaged runtime — the exact failure behind the directory tree not auto-refreshing (stablyai#4684; root cause stablyai#4851). A mocked subscribe() always exists, so those tests cannot see a missing-from-bundle watcher. This loads the real watcher, subscribes to a temp dir, writes a file, and asserts 'fs:changed' fires end-to-end. Verified to have teeth via a negative control: hiding @parcel/watcher-linux-x64-glibc reproduces both the stablyai#4684 root cause (native addon load error) and its symptom (no fs:changed event). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/ipc/filesystem-watcher-real.test.ts`:
- Line 113: The test calls handlers['fs:unwatchWorktree'](...) but doesn't await
its return, risking async cleanup races; change the invocation in the test to
await the Promise returned by handlers['fs:unwatchWorktree'] (i.e., use await
handlers['fs:unwatchWorktree']({ sender: { id: 1 } }, { worktreePath: tempDir
})) so any rejections are surfaced and cleanup runs deterministically.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9b17e934-9d3d-44e4-9c59-d43312e6e193
📒 Files selected for processing (1)
src/main/ipc/filesystem-watcher-real.test.ts
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — adds a real (unmocked) @parcel/watcher integration test so the suite catches the exact "missing from bundle" failure behind #4851.
- Add real
@parcel/watcherintegration test infilesystem-watcher-real.test.ts— loads the real watcher, subscribes to a temp directory, creates a file, and assertsfs:changedfires end-to-end. Onlyelectronis mocked; the native@parcel/watcherruns real. Skips on Windows.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Added a real (unmocked) The existing Verified to have teeth via a negative control — hiding
This PR also resolves the user-facing report #4684 (directory tree not auto-refreshing), which is the same bug from the renderer's perspective. |
- prunePackagedParcelWatcher: only prune `watcher-*` subpackages, so an unrelated @parcel/* runtime dep added to the roots later is never deleted (+ regression test asserting the unrelated dep survives). - filesystem-watcher-real.test.ts: await the fs:unwatchWorktree handler (it can return a Promise) to keep cleanup deterministic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks @coderabbitai — both addressed in
|
|
Tip For best results, initiate chat on the files or code changes.
(ᓀ ᓀ) 🐇 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — addresses two CodeRabbit review nits: narrows prunePackagedParcelWatcher to only target watcher-* entries, and awaits an async handler in the real watcher integration test.
- Narrowed
prunePackagedParcelWatcherto only prunewatcher-*directories — adds astartsWith('watcher-')guard so hypothetical future@parcel/*runtime deps undernode_modules/@parcelare never removed by the watcher prune step. - Added guard test for unrelated
@parcel/*deps — creates atransformer-jsdirectory under@parceland asserts it survives pruning, confirming the guard works. - Awaited
handlers['fs:unwatchWorktree']— the handler returns a promise; awaiting it ensures cleanup runs deterministically and any rejections are surfaced.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
importFromSshConfig only inserted unknown hosts and never updated an
existing target, so a rotated port (or any changed config field) was
silently ignored on re-import. Make it an upsert: config-sourced targets
are refreshed in place, genuinely new hosts are inserted, and the SSH
Manage pane auto-syncs when it opens so changes appear without a manual
Import click.
A new optional SshTarget.source ('ssh-config' | 'manual') protects
user-created and user-edited targets from being overwritten by sync —
editing a target in the UI detaches it from config-sync. Unchanged
targets are skipped so a repeat sync performs no disk write. Editing a
target now also carries cleared optional fields (identity file, proxy
command, jump host) so removing a config-derived value actually deletes
it instead of silently keeping the stale value through the partial merge.
Resolves item #1 of stablyai#4684 (item #2 was fixed in stablyai#4860).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(ssh): sync ~/.ssh/config on import and Manage open
importFromSshConfig only inserted unknown hosts and never updated an
existing target, so a rotated port (or any changed config field) was
silently ignored on re-import. Make it an upsert: config-sourced targets
are refreshed in place, genuinely new hosts are inserted, and the SSH
Manage pane auto-syncs when it opens so changes appear without a manual
Import click.
A new optional SshTarget.source ('ssh-config' | 'manual') protects
user-created and user-edited targets from being overwritten by sync —
editing a target in the UI detaches it from config-sync. Unchanged
targets are skipped so a repeat sync performs no disk write. Editing a
target now also carries cleared optional fields (identity file, proxy
command, jump host) so removing a config-derived value actually deletes
it instead of silently keeping the stale value through the partial merge.
Resolves item #1 of #4684 (item #2 was fixed in #4860).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(ssh): preserve legacy manual targets during config sync
Co-authored-by: Orca <help@stably.ai>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
* fix(ssh): sync ~/.ssh/config on import and Manage open
importFromSshConfig only inserted unknown hosts and never updated an
existing target, so a rotated port (or any changed config field) was
silently ignored on re-import. Make it an upsert: config-sourced targets
are refreshed in place, genuinely new hosts are inserted, and the SSH
Manage pane auto-syncs when it opens so changes appear without a manual
Import click.
A new optional SshTarget.source ('ssh-config' | 'manual') protects
user-created and user-edited targets from being overwritten by sync —
editing a target in the UI detaches it from config-sync. Unchanged
targets are skipped so a repeat sync performs no disk write. Editing a
target now also carries cleared optional fields (identity file, proxy
command, jump host) so removing a config-derived value actually deletes
it instead of silently keeping the stale value through the partial merge.
Resolves item stablyai#1 of stablyai#4684 (item stablyai#2 was fixed in stablyai#4860).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(ssh): preserve legacy manual targets during config sync
Co-authored-by: Orca <help@stably.ai>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>

Summary
Packaged Orca builds shipped without the
@parcel/watchernative module, so the main process could not start its filesystem watcher. On a Linuxorca servehost this silently broke filesystem-change propagation to paired clients — file edits/creates on the serve never reached connected clients, while terminal/PTY output (a separate path) kept working, making it easy to misdiagnose as a partially "frozen" client.@parcel/watcherloads its.nodebinary from a platform-specific optional dependency (e.g.@parcel/watcher-linux-x64-glibc). It was included by neither packaging path — notasarUnpack(native addons can't load from inside asar) and notPACKAGED_RUNTIME_PACKAGE_ROOTS(the closure copied toResources/node_modules) — so the runtimeimport('@parcel/watcher')threwCannot find package '@parcel/watcher'.This fix mirrors the existing
node-ptyhandling:@parcel/watchertoPACKAGED_RUNTIME_PACKAGE_ROOTS.@parcel/watcher's installed platform optional-subpackages into the packaged closure (the dependency graph alone never reaches them), tolerant of subpackages not installed for a given build.prunePackagedParcelWatcherinafterPackto keep the corewatcherpackage plus the matching platform's subpackages and drop the rest, so a Linux serve doesn't ship macOS/Windows.nodebinaries.Fixes #4851.
Screenshots
No visual change.
Testing
pnpm lint— passes (only pre-existing unrelatedreact-hooks/exhaustive-depswarnings in files this PR does not touch)pnpm typecheck— passes (exit 0)pnpm test— 13994 passed / 54 skipped. One unrelated failure (src/main/runtime/runtime-metadata.test.ts, a credential-store file-mode hardening test) stems from a separate in-progress local change tosrc/shared/secure-file.ts; it is not part of this PR's diff (this PR changes onlyconfig/packaged-runtime-node-modules.cjs+ its test) and is unaffected by it.pnpm build—build:unpack(electron-builder --dir) verified@parcel/watcher+@parcel/watcher-linux-x64-glibc/watcher.nodeland indist/linux-unpacked/resources/node_modules/@parcel/, and non-Linux platform subpackages are pruned.createPackagedRuntimeNodeModuleResourcesincludes@parcel/watcher+ a platform subpackage) and aprunePackagedParcelWatcherprune test (keeps core + matching platform, drops others).AI Review Report
Reviewed with Claude (Opus). Risks checked:
PARCEL_WATCHER_PLATFORM_PREFIX_BY_PLATFORM(watcher-darwin/watcher-linux/watcher-win32), keyed onelectronPlatformName.prunePackagedParcelWatcherkeeps the corewatcherdir plus the matching platform prefix and removes the others, symmetric to the existingprunePackagedNodePty. Linux verified by build; darwin/win32 covered by the same code path and the prune unit test. No hardcoded path separators — usesnode:pathjoin. No keyboard-shortcut or UI surface touched.Resources/node_modules), which fixes the local andorca servehost case. It is intentionally scoped to that artifact and does not alter the SSH relay native-deps path (src/main/ssh/ssh-relay-deploy.ts/config/scripts/build-relay.mjs), which is a separate artifact tracked by SSH relay: pre-bundle node-pty per platform (VS Code-style) to eliminate npm install on remote #1693. Called out so reviewers don't conflate the two.afterPackprune run once at package time, not on any runtime hot path. Net packaged size change is one platform'swatcher.node(~0.5 MB) after pruning. No runtime cost.Security Audit
optionalDependencieskeys read from itspackage.json.node:pathjoin.prunePackagedParcelWatcher'srmSync(..., { recursive: true, force: true })operates only within the build'sresources/node_modules/@parceloutput directory, on entries enumerated from that directory — no traversal from external/user-controlled input.@parcel/watcheris already a declareddependenciesentry; this only ensures its already-installed native binary is actually packaged.verifyPackagedMainRuntimeDepsto also scan ESMimportstatements and all bundled main chunks, so this class of missing-runtime-dep is caught at build time rather than at runtime.Notes
main(1.4.51-rc.6) before this change.Summary by CodeRabbit
Chores
Tests
Also resolves #4684 (directory tree not auto-refreshing — same bug from the renderer's perspective).