Skip to content

ci: package every Electron app, not just the client - #45

Merged
stuffbucket merged 4 commits into
mainfrom
fix/ci-packages-every-electron-app
Sep 6, 2026
Merged

stuffbucket merged 4 commits into
mainfrom
fix/ci-packages-every-electron-app

Conversation

@stuffbucket

Copy link
Copy Markdown
Owner

turbo run package --filter maximal-client meant the electron package job built one of this workspace's two Electron applications.

The two package by different rules. maximal-client bundles its dependencies and ships a compiled sidecar. @stuffbucket/maximal-electron holds node-pty and node-llama-cpp external and materialises their dependency closure into the bundle by hand — 162 placements, 68 of them nested under the package that asked for them.

Every packaging defect found in the second one was found by hand, because nothing in CI built it:

  • a resolver that walked symlinks instead of real paths
  • one that appended node_modules to a directory already named that
  • one that never read optionalDependencies
  • a packager that copied links out of the bundle

Each produced a bundle that could not load, and each passed 1,070 unit tests.

What changed

The filter is gone rather than widened. Naming the second package would leave the same gap for a third. Turbo reports <NONEXISTENT> for the ten workspace packages with no package script and skips them; the two real tasks are maximal-client#package and @stuffbucket/maximal-electron#package.

verify:package runs over the result. It reads the asar listing, the renderer content policy, the fuse wire off the built binary, and every closure placement — the properties the end-to-end suite cannot see, because it deliberately drives the unpackaged tree (the EnableNodeCliInspectArguments: false fuse stops Playwright attaching to a packaged binary). The script has existed for some time; nothing in this repository ran it.

Headroom and cache key. Two Forge builds need more than 30 minutes. The Electron download cache key now hashes both manifests, so a bump to either misses rather than restoring a binary the other package no longer uses.

Verification

Packaged @stuffbucket/maximal-electron locally on darwin-arm64 and ran verify:package against the result: all checks pass, including the external modules reach 162 package(s), 0 of them hoisted and all 162 closure placements are packed. actionlint is clean. The now-corrected claim in tests/hoisted-dependencies.test.ts — that CI packages only the client — was true when written and is what this PR makes false.

CI on this PR is the real check: it is the first run that packages the shell on Linux.

stuffbucket and others added 2 commits September 5, 2026 21:49
`turbo run package --filter maximal-client` meant the `electron package` job
built one of this workspace's two Electron applications. The two package by
different rules: `maximal-client` bundles its dependencies and ships a
compiled sidecar, while `@stuffbucket/maximal-electron` holds `node-pty` and
`node-llama-cpp` external and materialises their dependency closure into the
bundle by hand.

Every packaging defect found in the second one was found by hand, because
nothing in CI built it: a resolver that walked symlinks instead of real paths,
one that appended `node_modules` to a directory already named that, one that
never read `optionalDependencies`, and a packager that copied links out of the
bundle. Each of those produced a bundle that could not load, and each passed
1,070 unit tests.

Dropping the filter rather than naming the second package, so an Electron app
added later is packaged without anyone remembering to widen it. Turbo reports
`<NONEXISTENT>` for the ten workspace packages with no `package` script and
skips them.

`verify:package` then runs over the result. It reads the asar listing, the
renderer content policy, the fuse wire off the built binary, and all 162
closure placements -- the properties the end-to-end suite cannot see, because
it deliberately drives the unpackaged tree. The script has existed for some
time and nothing in this repository ran it.

Two Forge builds need more than 30 minutes of headroom, and the Electron
download cache key now hashes both manifests, so a bump to either one misses
rather than restoring a binary the other package no longer uses.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@stuffbucket

Copy link
Copy Markdown
Owner Author

Updated this branch onto current main (#36, #46 have landed since it was cut). The required check build / typecheck / lint / test passes; electron package still fails, and the failure moved earlier.

Before the update — reached verify:package on the shell and failed its closure check:

FAIL  5 closure placement(s) are missing, first node_modules/@node-llama-cpp/linux-arm64
ok    68 closure placement(s) nest under the package that asked for them
ok    the external modules reach 167 package(s), 0 of them hoisted

After the update — fails earlier, during packaging itself:

✖ Packaging application [FAILED: ENOENT: no such file or directory, open
  '/tmp/electron-packager/tmp-mo2R2V/resources/app/node_modules/simple-git/package.json']

Not a regression on main: CI is green on 8817eb3, 2ba9dfb and 52acfd5, electron package included. On main that job packages only the client, so both failures are specific to what this PR newly does — packaging maximal-electron, whose dependency closure has never been assembled before.

Both symptoms point the same way: the shell's closure is incomplete where the client's is not. simple-git is absent from the staged node_modules, and the five missing placements were optional @node-llama-cpp platform packages. That is the new check doing its job, so it needs a call on what the shell's package should contain rather than a change to make the check pass.

Left open and unmerged — it is your PR and the fix is a packaging decision, not a mechanical one. Nothing else is blocked by it.

stuffbucket and others added 2 commits September 5, 2026 22:58
The first Linux run of `verify:package` -- which is the first run there has
ever been, because this branch is what makes CI package the shell -- failed
against a bundle that was correct:

  FAIL  5 closure placement(s) are missing, first node_modules/@node-llama-cpp/linux-arm64

Two rules drop packages and the check subtracted one of them. A `linux-x64`
install carries six `@node-llama-cpp` packages. `linux-arm64` and
`linux-armv7l` go for the architecture, which the platform plan accounts for.
`linux-x64-cuda`, `linux-x64-cuda-ext` and `linux-x64-vulkan` declare exactly
this platform and architecture and go anyway, because they are GPU runtimes
nobody asked for -- 505 MB of CUDA. Only `llamaPackagePlan` knows that.

Nothing could see it before now. macOS installs ONE package for this target,
so the expectation and the archive agreed on every developer machine, and
`verify:package` did not run anywhere else.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@stuffbucket
stuffbucket merged commit 07e859c into main Sep 6, 2026
6 checks passed
@stuffbucket
stuffbucket deleted the fix/ci-packages-every-electron-app branch September 6, 2026 06:13
stuffbucket added a commit that referenced this pull request Sep 7, 2026
`main` is red at `6d8f346`, and #57 is red with the same error naming a
different file. Neither is a dependency break — which is exactly what
the failing pull requests made it look like.

## The bug

`@electron/packager` derives its staging base from a constant:

```js
// common.js
baseTempDir(opts) {
  return path.join(opts.tmpdir || os.tmpdir(), 'electron-packager')
}

// packager.js
async ensureTempDir() {
  if (this.useTempDir) {
    await fs.remove(this.tempBase)   // the whole shared directory, every run
  }
}
```

The directory *inside* that base is already unique — `stagingPath` calls
`mkdtemp`, which is where `tmp-TRr4aR` comes from — so uniqueness is not
what is missing. The unconditional wipe of the shared **parent** is what
throws it away.

Since #45, CI packages two applications rather than one (`ci.yml`: "Two
Forge builds, not one"). So the second build deletes the first's staged
tree while asar is midway through reading it. asar crawls, `lstat`s
every path, then opens each in turn, so the loss surfaces as ENOENT on a
file it had **already stat'ed** — whichever file it reached at that
instant.

That accounts for the whole symptom set:

| Observed | Because |
|---|---|
| `resources/app/package.json` on `main`,
`node_modules/minipass/LICENSE.md` on #57 | whatever asar was reading
when the wipe landed |
| Failing package moves between `maximal-electron` and `maximal-client`
| whichever build started first loses |
| `lstat` succeeds, `open` ENOENTs, same process | the tree is deleted
between crawl and read |
| Green locally, red in CI | one build locally; two concurrently in CI |
| Red on `main` with no Electron bump | nothing to do with any
dependency |

## The fix

`mkdtemp` one level up, in both applications. Packager still wipes the
base, but it is one this build created and owns, and `move()` relocates
the finished build into `out/`, so nothing accumulates there.

Both applications must set it. One alone still leaves the other wiping a
directory it does not own.

## Verification

Planting another build's staging tree at the shared path — the exact
path from the CI error — and running a package:

```
without this change   sentinel GONE
with this change      sentinel PRESENT
```

No timing dependence: the wipe is unconditional, so this is
deterministic rather than a race that has to be caught. Separately, a
packaged run with this change creates no `electron-packager` base at
all, staging under `forge-maximal-electron-AAbIdm` instead.

`tsc --noEmit` and `eslint` pass in both packages. The real check is
this branch's own `electron package` job, which exercises the two
concurrent builds that were colliding.

## Worth reporting upstream

A fixed, shared temp base that is `rm -rf`'d once per run makes
concurrent `@electron/packager` invocations unsafe for anyone, not just
this repository.
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