Repository navigation
fix(desktop): ship runtime-external deps in the packaged app + cross-platform packaging oracle - #780
Conversation
…platform oracle Desktop releases crashed on launch with "Cannot find module" — 0.0.3 on @grida/desktop-bridge, then 0.0.4 on @anthropic-ai/sandbox-runtime — while every CI check stayed green. Root cause: the electron-forge Vite plugin sets packagerConfig.ignore to drop everything except `.vite`, so the packaged app.asar ships NO node_modules. Anything the bundles leave `external` (see the `external` arrays in vite.*.config.ts) is then absent at runtime. This is a known forge bug (electron/forge#3738, #3917, #4045); the missing modules surface one per release as each prior one is fixed. Idiomatic fix — package.json is the spec: - `dependencies` are EXACTLY the modules left external in the vite configs (the ships-on-disk set): @anthropic-ai/sandbox-runtime, hono, @hono/node-server, undici. Everything bundled moved to devDependencies. - electron-packager's default `prune` then ships exactly the production dependency closure. forge.config only overrides `ignore` (8 lines) to undo the Vite plugin's node_modules strip, excluding the @grida/* link: symlinks (they point out of the package and break asar) and pnpm internals. - @anthropic-ai/sandbox-runtime is asar.unpack'd because it execs vendored binaries (vendor/seccomp/*/apply-seccomp) that can't run from inside an asar. - Moving @grida/* to devDependencies also keeps their symlinks out of the pruner's path, fixing the pnpm/prune fragility. Won't silently break — bidirectional oracle: - scripts/verify-packaged-bundle.mjs extracts the packaged asar, discovers every external require from the ACTUAL bundles, and asserts the package ships EXACTLY the runtime closure: (a) every external + its full transitive closure is present (else a launch crash), AND (b) nothing outside the closure ships (else prune-bloat). Both directions exit non-zero — verified they BLOCK. - Wired as a postPackage hook, so it gates package/make/publish automatically (local + CI). Also runnable via `pnpm verify:package`. Proof it works on every OS: - .github/workflows/verify-desktop-package.yml packages the app + runs the oracle on ubuntu/windows/macos on every PR (no publish, no secrets). Green on all three proves the closure ships correctly cross-platform; red means the oracle caught a platform gap before a user did. Verified locally on macOS: ships exactly the 9-package closure; the ad-hoc signed, asar-integrity-enforced, fused app boots (renderer + sidecar, zero module/integrity errors). typecheck, lint, and unit tests pass.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 7 Skipped Deployments
|
WalkthroughAdds packaged Electron bundle verification infrastructure: a new ChangesDesktop Package Verification
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a84d29029
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (file === "/package.json") return false; | ||
| if (file.startsWith("/.vite")) return false; |
There was a problem hiding this comment.
Normalize packager ignore paths before matching
When electron-forge package delegates to @electron/packager, the IgnoreFunction is called with an absolute file path, not "/package.json"/"/.vite..."-style app-relative paths (the packager docs define it as receiving an absolute file path). With absolute inputs like /workspace/grida/desktop/.vite/build/main.js, none of these keep rules match, so packageIgnore falls through to return true and drops .vite, package.json, and node_modules; packaging/CI will produce an empty or unusable app instead of the intended runtime-closure check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.github/workflows/verify-desktop-package.yml (1)
23-45: 💤 Low valueConsider setting
persist-credentials: falseon checkout for defense-in-depth.While the workflow has
permissions: contents: readat the top level, which mitigates credential misuse, settingpersist-credentials: falseon the checkout step is a good security practice to prevent the git credentials from being available to subsequent steps.Note: The static analysis warnings about unpinned action references are intentionally ignored per org policy (mutable version tags like
@v4are preferred over SHA pins).🔒 Optional: Add persist-credentials: false
- name: Checkout Repository uses: actions/checkout@v4 + with: + persist-credentials: false🤖 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 @.github/workflows/verify-desktop-package.yml around lines 23 - 45, The checkout step "Checkout Repository" using actions/checkout@v4 should explicitly set persist-credentials: false to avoid exposing git credentials to later steps; locate the step that currently reads "uses: actions/checkout@v4" and add the persist-credentials: false property under that step's configuration so the action does not persist GITHUB_TOKEN credentials to the workspace.
🤖 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 @.github/workflows/verify-desktop-package.yml:
- Around line 23-45: The checkout step "Checkout Repository" using
actions/checkout@v4 should explicitly set persist-credentials: false to avoid
exposing git credentials to later steps; locate the step that currently reads
"uses: actions/checkout@v4" and add the persist-credentials: false property
under that step's configuration so the action does not persist GITHUB_TOKEN
credentials to the workspace.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2bbe543e-3adb-483f-aba9-0221a6d7acbd
⛔ Files ignored due to path filters (1)
desktop/pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
.github/workflows/verify-desktop-package.ymldesktop/forge.config.tsdesktop/package.jsondesktop/scripts/verify-packaged-bundle.mjs
What
Desktop releases crash on launch with
Cannot find module— 0.0.3 on@grida/desktop-bridge, 0.0.4 on@anthropic-ai/sandbox-runtime— while every CI check stays green. This ships the runtime-external dependencies correctly and adds a cross-platform oracle so this class of bug can never silently ship again.(Follow-up to #776, which fixed the first missing module by bundling
@grida/*. This fixes the systemic cause behind all of them.)Root cause
The electron-forge Vite plugin sets
packagerConfig.ignoreto drop everything except/.vite, so the packagedapp.asarships nonode_modules. Anything the bundles leaveexternal(theexternalarrays invite.*.config.ts) is then absent at runtime. Known forge bug — electron/forge#3738, #3917, #4045. The missing modules surfaced one per release as each prior one got fixed.The fix —
package.jsonis the specThe idiomatic Electron pattern (what
electron-viteenforces automatically):dependencies= what ships on disk;devDependencies= what's bundled.dependenciesis now exactly the 4 Vite externals (@anthropic-ai/sandbox-runtime,hono,@hono/node-server,undici); everything bundled moved todevDependencies.prunethen ships exactly the production-dependency closure.forge.config.tsonly overridesignore(8 lines) to undo the Vite plugin'snode_modulesstrip — excluding the@grida/*link:symlinks (they point out of the package and break asar) and pnpm internals.@anthropic-ai/sandbox-runtimeisasar.unpack'd because it execs vendored binaries (vendor/seccomp/*/apply-seccomp) that can't run from inside an asar.@grida/*to devDependencies also keeps their symlinks out of the pruner's path, fixing the pnpm/prune fragility for free.Won't silently break — bidirectional oracle
scripts/verify-packaged-bundle.mjsextracts the packaged asar, discovers every externalrequirefrom the actual bundles, and asserts the package ships exactly the runtime closure:Both directions exit non-zero — verified they block: dropping
undiciand shippingclsxeach fail the build with the offender named. Wired as apostPackagehook (gates package/make/publish, local + CI; chainpublish→make→package→postPackageverified). Alsopnpm verify:package.Proof it works on every OS
.github/workflows/verify-desktop-package.ymlpackages the app + runs the oracle on ubuntu / windows / macos on every PR (no publish, no secrets). Green on all three = proof the closure ships correctly cross-platform; red = the oracle caught a platform gap before a user did. It stays as a permanent gate.Verified locally (macOS)
pnpm package→ "ships EXACTLY the runtime closure (9 packages)".Reviewer notes
pruneleaves empty devDep dirs in the asar (harmless; the oracle ignores dirs without apackage.json).electron-vite— intentionally out of scope for this fix.Summary by CodeRabbit
Release Notes