Repository navigation
perf(desktop): slim bundles and fetch postgres for local mode - #23
Merged
Merged
Conversation
nixuuu
force-pushed
the
perf/desktop-bundle-size
branch
from
November 3, 2026 17:11
46f5e15 to
cd72d9a
Compare
nixuuu
marked this pull request as ready for review
November 3, 2026 17:11
nixuuu
added a commit
that referenced
this pull request
Nov 3, 2026
Since #23 each desktop artifact also carries `package-sizes-<target>.json` (uploaded for the job log). `publish-desktop` rejected it as "Unexpected desktop asset", so the nightlies after #23/#28/#30 published server artifacts but no desktop installers. The merge step now skips the size reports; the update-metadata test covers it.
nixuuu
added a commit
that referenced
this pull request
Nov 6, 2026
macOS checks each newly written executable on its first launch. A cold `postgres --version` took 3-3.6 s on an idle Mac; on a freshly installed, busy Mac it went past the old 10 s limit per binary and failed with a generic error. Each retry extracts new files, so it pays the cost again. - Run the three `--version` checks in one hard 3 min budget, with a "Checking PostgreSQL with macOS security…" status after 5 s. - SIGKILL on timeout. Waiting for the exit and the output is bounded too, so a retry cannot hang. - Name the cause (timeout, blocked by the OS, failed run, wrong version) and log the binary, exit code or signal, the timeout, the timing and trimmed stdout/stderr. - Remove com.apple.quarantine from the verified, extracted runtime. A quarantined binary waited in syspolicyd until killed. - Drop Electron's IPC prefix from setup errors. Fixes: #23
nixuuu
added a commit
that referenced
this pull request
Nov 6, 2026
## Evidence A colleague ran nightly `0.2.0-nightly.92` on a fresh MacBook Pro (M5 Pro, macOS 27.0.1). The first local setup failed twice with `Downloaded PostgreSQL could not run on this computer`. The desktop log had only that generic line. "Try again" sometimes looked stuck on "Setting up PostgreSQL…". The 7th attempt worked, and `initdb`, postgres, migrations, gateway and worker then started normally. Measured on a Mac Studio, macOS 27.0.1, idle, using the installer's own steps in a temp dir (real npm download, SHA-512, extract, `preparePostgres`, `--version`): | Run | `postgres` | `pg_ctl` | `initdb` | | --- | --- | --- | --- | | cold, fresh files (3 runs) | 3010–3608 ms | 146–162 ms | 309–431 ms | | second launch, same files | 20–24 ms | 3–5 ms | 12–14 ms | | fixed installer end to end, same pin already installed by Canopy elsewhere | 3376 ms | 146 ms | 374 ms | | fresh files with `com.apple.quarantine` | hung until killed at 180 s (SIGTERM, exit 143); syspolicyd logged `Unable to initialize qtn_proc` every 2 s | | | | quarantine set, then removed with `xattr -dr` | 3010 ms | 151 ms | 309 ms | Files extracted by Canopy carry only `com.apple.provenance`, not quarantine. `preparePostgres` (thin plus ad-hoc signing of 113 Mach-O files) takes 4.4–5 s. ## Root cause macOS checks each newly written executable on its first launch, and the slow part is `postgres`, which loads ICU, OpenSSL and libxml2. The cost depends on the files, not their content: every retry extracts a new runtime and pays it again. The smoke check gave each binary a fixed 10 s `AbortSignal.timeout`. On a freshly installed, busy Mac that first launch went past 10 s. Any timeout or kill turned into the same generic error, with no detail in the log. Later attempts passed once the Mac was less busy, not because of a cache. ## Fix - `postgres-check.ts`: the three `--version` checks share one hard budget of 3 min. After 5 s the setup screen shows "Checking PostgreSQL with macOS security… This can take a minute the first time." - On timeout the child gets SIGKILL. Waiting for its exit and for stdout/stderr is bounded by a 2 s grace, so a retry cannot hang. Cancelling kills the running check at once. - The error names the cause: timeout, blocked by the OS (signal), failed run, or wrong version. `logs/desktop.log` gets the binary, the exit code or signal, whether the timeout fired, the elapsed time, and trimmed stdout/stderr with the runtime path replaced by `<runtime>`. A successful install logs the first-launch times. - On darwin, `preparePostgres` removes `com.apple.quarantine` from the extracted runtime. Integrity still comes from the pinned SHA-512, checked before extraction. - Retries already reused the verified `package.tgz.partial`; a test now covers it, and that no `extracted/` or `install/` directory is left after a failure. - The setup screen drops Electron's `Error invoking remote method 'canopy:configure': Error:` prefix. - Confirmed that another PostgreSQL cannot interfere: binaries run by absolute path, the service env allowlist has no `PG*` or `DYLD*`, Postgres uses a random port on `127.0.0.1` with no Unix socket (`-k ""`), and it has its own data dir. Documented in `docs/desktop.md`. `Fixes: #23`: #23 moved PostgreSQL from the signed bundle to a runtime download, which runs freshly written binaries through the 10 s check. ## Tests `apps/desktop/test/postgres-check.test.ts` uses an injectable spawn and short budgets: - a launch stuck until SIGKILL; - a process that never exits or closes its output, which stays bounded; - a slow launch that shows progress; - signal, exit and version classification, with no path in the message; - cancellation; - a real installer retry against the fixture registry: the first attempt fails, the download is reused (1 request), and the stage directories are cleaned up. `bun install`, `gen:check`, `typecheck`, `lint`, `format:check`, `check:tmp` (1530 pass, 0 fail) and the web build are all clean. ## Not verified - A real fresh macOS 27 MacBook running the packaged app, where the controller is a child of Canopy.app. The Mac Studio tests ran over SSH. The 3 min budget is a judgement, not a measured worst case. - What a GUI-session app sees when it launches a quarantined binary (a Gatekeeper dialog or a block). Canopy's extraction does not add quarantine, so the removal is a precaution. - The hang on "Try again" could not be reproduced directly. The old code could appear stuck for up to about 35 s (5 s of synchronous preparation plus 3 × 10 s with no new status) and had no bound on reading stdout. Both are now bounded and visible. ## Copy audit (docs/copy.md §8) | Before | After | Why | | --- | --- | --- | | `Downloaded PostgreSQL could not run on this computer. Check the desktop logs and OS security policy, then try again.` (every failure) | timeout: `PostgreSQL did not respond within 3 min. macOS may still be checking it for security. Try again.` | names the likely cause; one idea per sentence | | same | signal: `macOS stopped PostgreSQL from running. Check System Settings → Privacy & Security, then try again.` (other OS: `Your computer stopped PostgreSQL from running. Check your security software, then try again.`) | concrete action and settings path | | same | wrong version: `Downloaded PostgreSQL reports an unexpected version. Try again.` | separate cause | | same | other failures: `Downloaded PostgreSQL could not run on this computer. Check the desktop logs, then try again.` | drops the vague "OS security policy" | | — | progress after 5 s: `Checking PostgreSQL with macOS security… This can take a minute the first time.` (other OS: `Checking PostgreSQL… This can take a minute the first time.`) | §4.6: -ing verb with ellipsis, says it happens only the first time | | `Error invoking remote method 'canopy:configure': Error: …` | `…` | no internal jargon on the surface | Checks: sentence case; each error ends with an action; no paths or jargon; no humour in errors; sentences ≤ 20 words. Glossary: no new terms. The texts sit in the existing startup alert and status line, so the layout is unchanged.
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shrinks the desktop app (macOS 0.2.0-nightly.5 measured 1.8 GiB on disk) and follows the product decision that agent CLIs are never bundled.
node_modulesin app.asar/app.asar.unpacked; runtimenode_modulesonly for what the bundles load at runtime.pathToClaudeCodeExecutableto the installedclaude(codex/grok were already from PATH); a missing CLI is reported by the provider probe.Linux AppImage unpacked: 1468 → 418 MiB (AppImage 586 → 184 MiB). macOS estimated 1.8 GiB → ~400 MiB (+ ~70–110 MiB Postgres cache only in local mode).
Tests: check:tmp 687 pass / 0 fail; desktop + guards 15 pass (real Postgres start from the downloaded layout, hash mismatch, interrupted download, offline, remote without download, durability, shutdown).
Draft until verified on macOS: Developer ID signing/notarization of the single Bun, Postgres download under quarantine (ad-hoc signing, ICU symlinks), local mode start, installed Claude/Codex/Grok turns (checklist in docs/release.md).