Skip to content

fix(desktop): ship runtime-external deps in the packaged app + cross-platform packaging oracle - #780

Merged
softmarshmallow merged 1 commit into
mainfrom
fix/desktop-package-externals-shipping
Jun 5, 2026
Merged

softmarshmallow merged 1 commit into
mainfrom
fix/desktop-package-externals-shipping

Conversation

@softmarshmallow

@softmarshmallow softmarshmallow commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

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.ignore to drop everything except /.vite, so the packaged app.asar ships no node_modules. Anything the bundles leave external (the external arrays in vite.*.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.json is the spec

The idiomatic Electron pattern (what electron-vite enforces automatically): dependencies = what ships on disk; devDependencies = what's bundled.

  • dependencies is now exactly the 4 Vite externals (@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.ts 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 for free.

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, #4045).

Both directions exit non-zero — verified they block: dropping undici and shipping clsx each fail the build with the offender named. Wired as a postPackage hook (gates package/make/publish, local + CI; chain publish→make→package→postPackage verified). Also 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 = 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)".
  • Ad-hoc-signed, asar-integrity-enforced, fused app boots — renderer + GPU helpers spawn, agent sidecar runs, 0 module/integrity errors.
  • typecheck, lint, 17 unit tests pass.

Reviewer notes

  • ⚠️ 0.0.4 is published broken → this needs a 0.0.5 (or re-cut) once merged + CI green on all 3 OSes.
  • Cosmetic: prune leaves empty devDep dirs in the asar (harmless; the oracle ignores dirs without a package.json).
  • Fully-native alternative is migrating to electron-vite — intentionally out of scope for this fix.

Summary by CodeRabbit

Release Notes

  • Chores
    • Added continuous integration workflow for automated desktop package verification across Windows, macOS, and Linux platforms
    • Enhanced build configuration to ensure proper runtime dependency management and bundling
    • Implemented strict validation checks to prevent missing or incorrectly included dependencies in desktop releases

…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.
@vercel

vercel Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

7 Skipped Deployments
Project Deployment Actions Updated (UTC)
backgrounds Ignored Ignored Preview Jun 5, 2026 5:25am
blog Ignored Ignored Preview Jun 5, 2026 5:25am
code Ignored Ignored Jun 5, 2026 5:25am
docs Ignored Ignored Jun 5, 2026 5:25am
grida Ignored Ignored Preview Jun 5, 2026 5:25am
legacy Ignored Ignored Jun 5, 2026 5:25am
viewer Ignored Ignored Preview Jun 5, 2026 5:25am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds packaged Electron bundle verification infrastructure: a new verify-packaged-bundle.mjs script validates that shipped dependencies match runtime requirements, forge.config.ts wires post-package verification and customizes asar behavior, desktop/package.json reorganizes dependencies and documents enforcement, and a GitHub Actions workflow automates verification across Linux, Windows, and macOS.

Changes

Desktop Package Verification

Layer / File(s) Summary
Runtime dependency declaration and documentation
desktop/package.json
scripts section adds typecheck and verify:package commands. Production dependencies are reduced to runtime-only essentials (@anthropic-ai/sandbox-runtime, hono, undici); development packages like electron, React, @grida/* workspace packages, and tooling move to devDependencies. A new comment:dependencies field documents that enforced runtime closure is validated by verify-packaged-bundle.mjs and GRIDA-DESKTOP-BUILD-GUARD.
Package bundle verification script
desktop/scripts/verify-packaged-bundle.mjs
New CLI script validates Electron/Vite packaging by extracting app.asar, scanning bundled JS for external require(...) calls, computing transitive dependency closure from each detected external, and comparing against shipped node_modules packages. Fails on missing runtime-required externals or extra bloat packages; succeeds with closure summary.
Forge packaging configuration and post-package hook
desktop/forge.config.ts
Imports execFileSync for build-time hooks. Adds packageIgnore(file) function to exclude workspace symlinks (@grida/*), pnpm internals, and non-runtime paths from packaging. Updates packagerConfig with custom ignore rules and replaces asar: true with selective unpacking for @anthropic-ai/sandbox-runtime binaries. Replaces empty hooks: {} with postPackage async handler that runs verify-packaged-bundle.mjs on each output and fails the build if verification reports missing externals.
Cross-platform CI verification workflow
.github/workflows/verify-desktop-package.yml
New workflow triggers on PR changes to desktop and packages/** paths (plus manual dispatch), runs on Ubuntu, Windows, and macOS. Checks out repo, sets up pnpm and Node (from .nvmrc), installs with frozen lockfile, builds workspace packages with pnpm turbo run build (filtering @grida/desktop-bridge, @grida/agent, @grida/ai-models, @grida/home), and runs pnpm exec electron-forge package to invoke post-package verification.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • gridaco/grida#776: Both PRs enforce that linked @grida/* workspace packages are actually bundled/available for desktop builds—main PR adds a postPackage packaged-bundle verifier and a CI workflow to run it, while retrieved PR adds gridaBundleGuard (Vite build-time hard-fail) and pre-builds linked @grida/* packages in CI.
  • gridaco/grida#593: Both PRs touch desktop/package.json by adding/updating the typecheck script (tsc --noEmit), though the main PR also adds additional desktop packaging verification logic not present in the retrieved PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: fixing desktop app crashes by shipping runtime-external dependencies in the packaged app and adding cross-platform packaging validation, which matches the PR's core objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/desktop-package-externals-shipping

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread desktop/forge.config.ts
Comment on lines +85 to +86
if (file === "/package.json") return false;
if (file.startsWith("/.vite")) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/verify-desktop-package.yml (1)

23-45: 💤 Low value

Consider setting persist-credentials: false on checkout for defense-in-depth.

While the workflow has permissions: contents: read at the top level, which mitigates credential misuse, setting persist-credentials: false on 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 @v4 are 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

📥 Commits

Reviewing files that changed from the base of the PR and between b6685e0 and 9a84d29.

⛔ Files ignored due to path filters (1)
  • desktop/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • .github/workflows/verify-desktop-package.yml
  • desktop/forge.config.ts
  • desktop/package.json
  • desktop/scripts/verify-packaged-bundle.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant