Skip to content

fix(desktop): hard-fail builds that externalize @grida/* workspace packages - #776

Merged
softmarshmallow merged 1 commit into
mainfrom
fix/desktop-build-guard-workspace-externals
Jun 4, 2026
Merged

softmarshmallow merged 1 commit into
mainfrom
fix/desktop-build-guard-workspace-externals

Conversation

@softmarshmallow

@softmarshmallow softmarshmallow commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

What

Desktop 0.0.3 shipped a main.js containing a bare require("@grida/desktop-bridge") that resolved to nothing at runtime — the app crashed on launch with Cannot find module '@grida/desktop-bridge', while every CI check was green.

This adds a build-time guard that makes that class of failure a hard, visible error, plus the CI step that fixes the happy path.

Why it happened (etiology)

The desktop link:s several @grida/* workspace packages whose dist/ is gitignored. The isolated ./desktop release CI runs pnpm install (which only symlinks link deps) and never builds them. So at package time Rollup couldn't resolve the import and silently downgraded it to an external require, and electron-forge runs the Vite build with logLevel:"silent" so even the UNRESOLVED_IMPORT warning vanished.

It's uniquely dangerous because every gate stays green: the symlink resolves, types exist, and local dev has dist/ built — so it only breaks in a clean packaging run.

The fix (two parts)

  1. CI builds the link-dep closure before packaging (realease-desktop-app.yml) — @grida/desktop-bridge, @grida/agent, @grida/ai-models, @grida/home — so the green path actually produces a working binary.
  2. A Vite plugin guard (desktop/vite.guards.ts), wired into all three entries (main, preload, agent-sidecar). It inspects the emitted bundle and, if any @grida/* import was left external, prints to stderr and process.exit(1).

Why a plugin-that-exits, not onwarn

onwarn was the obvious first attempt — and it's a trap. Verified against the real packager: Rollup does emit UNRESOLVED_IMPORT and forge does forward it to a user onwarn, but a throw inside onwarn is swallowed and the build still succeeds. Even this.error() only surfaces as a cryptic downstream "main entry point not found" because forge's logger is silent. Inspecting the emitted bundle + process.exit(1) is the only reliable, visible hard-fail. Scoped apply:"build" so dev (electron-forge start) is unaffected.

Verification

  • Original crash reproduced locally on the pre-fix tree (hide dist/, build, load main.js via electron-as-node → MODULE_NOT_FOUND through the same electron node_init → _load → _resolveFilename path as the report).
  • Guard hard-fails in the real pnpm package with dist/ missing — exit 1, clear message, offender named, actionable pnpm build:packages fix.
  • No false positive with dist/ present — packages cleanly, bridge inlined; intentional externals (sandbox-runtime, hono, undici) untouched.
  • Unit tests, tsc, oxlint all green.

Reviewer notes

  • ⚠️ 0.0.3 is published broken — this needs a follow-up 0.0.4 (or re-cut) once merged; current installs keep crashing.
  • A post-package boot smoke test (launch the packaged binary, assert it survives module init) is the deeper net beyond this guard — recommended follow-up, intentionally not included here.

Summary by CodeRabbit

Release Notes

  • Chores

    • Enhanced the desktop build pipeline with additional dependency preparation and validation steps
    • Added build-time safety mechanisms to verify workspace package bundling and prevent runtime issues
    • Improved the overall build workflow reliability
  • Tests

    • Added new validation tests for build configuration and dependency bundling

…ckages

Desktop 0.0.3 shipped a main.js containing a bare
`require("@grida/desktop-bridge")` that resolved to nothing at runtime,
crashing the app on launch with "Cannot find module" — while every CI
check was green.

Root cause: the desktop `link:`s several @grida/* workspace packages
whose dist/ is gitignored. The isolated ./desktop release CI runs
`pnpm install` (which only symlinks link deps) and never builds them, so
Rollup couldn't resolve the import and silently downgraded it to an
external `require`. The symlink resolves, types exist, and local dev has
dist/ built — so nothing catches it until a clean packaging run.

Two-part fix:

1. CI builds the desktop's @grida/* link-dep closure before packaging, so
   the green path actually produces a working binary.

2. A Vite plugin guard (wired into all three entries: main, preload,
   agent-sidecar) inspects the EMITTED bundle and, if any @grida/* import
   was left external, prints to stderr and process.exit(1). This is a
   plugin-that-exits rather than an onwarn handler because forge runs the
   Vite build with logLevel:"silent", which swallows Rollup's
   UNRESOLVED_IMPORT warning AND a throw inside onwarn (verified — that
   approach builds green and ships the broken bundle). Scoped
   apply:"build" so dev (`electron-forge start`) is unaffected.

Verified against the real `pnpm package`: with dist/ hidden the build now
hard-fails with a clear, actionable message; with dist/ present it
packages cleanly with the bridge inlined. The original runtime crash was
reproduced locally on the pre-fix tree.
@vercel

vercel Bot commented Jun 4, 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 4, 2026 6:00pm
blog Ignored Ignored Preview Jun 4, 2026 6:00pm
code Ignored Ignored Jun 4, 2026 6:00pm
docs Ignored Ignored Jun 4, 2026 6:00pm
grida Ignored Ignored Preview Jun 4, 2026 6:00pm
legacy Ignored Ignored Jun 4, 2026 6:00pm
viewer Ignored Ignored Preview Jun 4, 2026 6:00pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds a Vite bundle guard plugin to detect when workspace-scoped packages remain external instead of bundled, applies the plugin to three desktop Vite configurations, and updates the CI workflow to pre-build workspace packages before desktop publishing, preventing runtime "Cannot find module" errors.

Changes

Desktop bundle guard and workspace package preparation

Layer / File(s) Summary
Bundle guard implementation and validation
desktop/vite.guards.ts, desktop/vite.guards.test.ts
externalizedWorkspaceImports helper filters imports for @grida/* workspace scope; gridaBundleGuard plugin scans bundle chunks and fails the build with a stderr error if any workspace imports remain external. Tests validate detection of unbuilt dependencies, filtering of built-ins and intentional externals, and deduplication of repeated offenders.
Vite config integration
desktop/vite.main.config.ts, desktop/vite.preload.config.ts, desktop/vite.agent-sidecar.config.ts
Plugin is imported and registered via plugins: [gridaBundleGuard()] in all three desktop Vite configurations, applying the bundle validation guard uniformly across main process, preload, and agent-sidecar builds.
CI workflow workspace package preparation
.github/workflows/realease-desktop-app.yml
Desktop publish pipeline now includes a "Build linked workspace packages" step that runs pnpm install --frozen-lockfile --ignore-scripts and pnpm turbo run build (filtered to key @grida/* packages) before platform-specific publish steps, ensuring workspace package dist/ outputs exist for desktop build consumption.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

org

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a hard-fail build guard for externalized @grida/* workspace packages, which is the core fix addressing the shipping bug detailed in the PR objectives.
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-build-guard-workspace-externals

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.

@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/realease-desktop-app.yml (1)

99-121: Add a lightweight packaged-app boot smoke test after publish steps.

This workflow now prevents unresolved @grida/* externals at build-time; adding one post-package launch check would catch any remaining runtime startup regressions before release consumers do.

🤖 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/realease-desktop-app.yml around lines 99 - 121, Add a
lightweight packaged-app boot smoke test step that runs immediately after each
"Publish App (Windows)", "Publish App (Linux)", and "Publish App (MacOS)"
publish step: for each OS matrix variant add a new step named e.g. "Smoke Test
Packaged App" which locates the produced package/installer from the workspace or
artifacts and performs a non-interactive startup check (invoke the packaged
binary or executable with a stable flag such as --version or --help, or run the
AppImage/.exe/.app binary briefly) and fails the job on non-zero exit; ensure
the step is conditional on the same if-expressions used for the publish steps
and reuses the same env vars (GITHUB_TOKEN, PRERELEASE, signing envs) so it runs
in CI after publishing to catch runtime startup regressions.
🤖 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/realease-desktop-app.yml:
- Around line 99-121: Add a lightweight packaged-app boot smoke test step that
runs immediately after each "Publish App (Windows)", "Publish App (Linux)", and
"Publish App (MacOS)" publish step: for each OS matrix variant add a new step
named e.g. "Smoke Test Packaged App" which locates the produced
package/installer from the workspace or artifacts and performs a non-interactive
startup check (invoke the packaged binary or executable with a stable flag such
as --version or --help, or run the AppImage/.exe/.app binary briefly) and fails
the job on non-zero exit; ensure the step is conditional on the same
if-expressions used for the publish steps and reuses the same env vars
(GITHUB_TOKEN, PRERELEASE, signing envs) so it runs in CI after publishing to
catch runtime startup regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: db807154-2564-46d6-9ae0-cfa5f5a310c5

📥 Commits

Reviewing files that changed from the base of the PR and between 6e39a58 and 712f3ab.

📒 Files selected for processing (6)
  • .github/workflows/realease-desktop-app.yml
  • desktop/vite.agent-sidecar.config.ts
  • desktop/vite.guards.test.ts
  • desktop/vite.guards.ts
  • desktop/vite.main.config.ts
  • desktop/vite.preload.config.ts

@softmarshmallow
softmarshmallow merged commit d6ce321 into main Jun 4, 2026
10 checks passed
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