Skip to content

fix(installer): skip the payload download when the install is current - #2437

Merged
yuezengwu merged 4 commits into
first-tree-ai:mainfrom
Walternater:fix/portable-install-skip-payload
Nov 14, 2026
Merged

yuezengwu merged 4 commits into
first-tree-ai:mainfrom
Walternater:fix/portable-install-skip-payload

Conversation

@Walternater

@Walternater Walternater commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Re-running install.sh on an up-to-date machine downloads the whole portable payload — tens of MB, bundled Node runtime included — and then throws it away: the versions/<version> check happens after extraction, so the download has already completed. The installer is the documented install-or-upgrade path, so a re-run has to be cheap.

Summary

  • Resolve the installed version from $PREFIX/current before the payload step, and exit right after wiring PATH and the background service.
  • Skip only when every moving part is in place: current/VERSION, the bundled runtime, the app entry, and both shims — and the shims must point at this prefix, so re-running with a different --prefix is not mistaken for an installed machine.
  • Anything missing falls through to the normal install, which therefore also repairs an interrupted one. That surfaced a second bug on the same path: an existing versions/<version> directory was reused unconditionally, so an install that had lost its runtime died in the pre-commit smoke check instead of being repaired. It is now reused only when complete, and re-extracted otherwise.
  • local.* dev builds compare unequal to every released version, so the installer would replace them silently. It now warns first; upgrade treats local builds as ahead and refuses.

Validation

  • pnpm check and pnpm typecheck pass.
  • apps/cli/tests/portable-builder.test.ts: 46 passed, including three new cases:
    • a re-run with the tarball deleted still exits 0 and prints already installed; skipped the payload download, so no fetch happened;
    • a re-run after deleting current/node reinstalls and restores the runtime;
    • local.20260101 → 1.2.3 prints the replacement warning and moves current.
  • Negative controls, reverting one piece at a time: disabling the fast path, dropping the runtime check from the version probe, and dropping the local-build warning each turn exactly one case red.
  • dash -n (Linux's /bin/sh) parses the script, and the two main scenarios were re-run under dash, not just macOS's sh.

Change Surface

  • CI / packaging / release plumbing

Notes

  • package or install behavior changes: re-running install.sh on a current machine no longer fetches the payload; an incomplete versions/<version> directory is now replaced instead of reused; replacing a local.* build is announced.
  • docs or tests updated to match: apps/cli/tests/portable-builder.test.ts.
  • follow-up work: none. The daemon's own npm install -g self-update ([Bug] Daemon auto-update is not restart-safe: killed npm install corrupts node_modules and crash-loops the whole host #2394) is a separate, non-atomic path and is untouched.
  • not covered here: the published curl | sh flow — the channel rewrite in renderInstallerForChannel does not touch the new code, and the tests drive the same download branch through FIRST_TREE_PORTABLE_DOWNLOAD_BASE_URL=file://.

Fixes #2088.

@yuezengwu yuezengwu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use consistent completeness checks for the fast path and for reusing an extracted version. I ran all 46 portable-builder tests successfully, then reproduced two false-success cases using the same local fixture:

  • Remove current/INSTALL.json and rerun. installed_portable_version still returns the release version, so the installer exits 0 and claims the payload was skipped without restoring metadata that the portable updater reads.
  • Remove current/VERSION and rerun. The fast path correctly declines, but the reuse check accepts the old version directory and discards the fresh extraction. The installer exits 0 with VERSION still missing, so later reruns fetch the payload again.

Please require both metadata files before skipping or reusing a version, validate the candidate before replacing an existing version directory, and cover both missing-file cases alongside the missing-runtime test.

Re-running install.sh on an up-to-date machine downloaded the full portable
payload (tens of MB with the bundled Node runtime) and then discarded it,
because the version check only happened after extraction. The installer is
the documented install-or-upgrade path, so a re-run must be cheap.

Resolve the installed version from $PREFIX/current before the payload step and
exit after wiring PATH and the service when everything is already in place:
the version file, the bundled runtime, the app entry, and both shims. Any
missing piece falls through to the normal install, so the same code path
repairs an interrupted install instead of skipping it.

An existing version directory is now only reused when it is complete, since
the fast path already handles the complete case; an incomplete one is
re-extracted rather than failing the pre-commit smoke check later.

A local.* dev build compares unequal to every released version, so the
installer would silently replace it. Warn before doing that; `upgrade`
treats local builds as ahead and refuses instead.
The two checks disagreed: the fast path required VERSION but not
INSTALL.json, and reuse required INSTALL.json but not VERSION. Both
half-states are false successes — a prefix with no INSTALL.json skipped the
install even though the portable updater reads it, and a version directory
with no VERSION was reused, discarding the fresh extraction and leaving the
file missing.

Both now call portable_version_dir_complete(), which requires VERSION,
INSTALL.json, the bundled runtime and the app entry. The incomplete directory
is also replaced only after the extracted candidate has passed its INSTALL.json
validation, so a bad download cannot cost the directory already on disk.

The repair test is now a three-case table (runtime, VERSION, INSTALL.json), and
each case fails when its check is removed from the shared predicate.
@Walternater
Walternater force-pushed the fix/portable-install-skip-payload branch from 88780ea to e8fd61f Compare November 13, 2026 05:29
@Walternater

Copy link
Copy Markdown
Contributor Author

You were right on both counts — the two checks had drifted apart, and each half-state is a false success.

Fixed in e8fd61f4:

  • Both paths now call one predicate, portable_version_dir_complete(): VERSION, INSTALL.json, the executable bundled runtime, and app/cli/index.mjs. The fast path and the reuse check can no longer disagree about what "installed" means.
  • The incomplete directory is now replaced after the extracted candidate passes its INSTALL.json validation, instead of before extraction, so a bad download cannot cost the directory that is already on disk.
  • The repair test is a three-case table — missing runtime, missing VERSION, missing INSTALL.json — and each case asserts the rerun restores all four files and never prints is already installed.

Negative controls, reverted one at a time: dropping the INSTALL.json check turns the metadata case red, dropping the VERSION check turns the version-marker case red. Full file: 48 passed. pnpm check and tsc --noEmit (first-tree-dev) pass.

The repair path now deletes the incomplete version directory only after the
extracted candidate passes its INSTALL.json validation. A stale candidate
whose metadata disagrees with the manifest must fail the install without
wiping what an earlier attempt left behind; without the reorder the existing
directory is gone before validation runs.
@Walternater

Copy link
Copy Markdown
Contributor Author

One more commit since that reply: 9213ec88 pins the validate-before-replace order. A stale candidate whose INSTALL.json disagrees with the manifest now fails the install and leaves versions/<version> exactly as the interrupted attempt left it; reverting to the old order (delete, then extract) turns that case red.

CI is green on 9213ec88 (14/14), and the repair table now covers the runtime, VERSION, and INSTALL.json.

@yuezengwu yuezengwu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The shared completeness check fixes both missing-metadata cases, and all 49 checked-in portable-builder tests passed locally. The same-version repair can still replace a working CLI before the candidate passes the runtime smoke check. After installing the fixture, I removed only current/INSTALL.json and confirmed the existing shim still returned its version. A same-version candidate with matching metadata then failed the smoke check. The installer exited 1, and the same shim now failed because current already pointed at the replacement files.

Please run the runtime smoke check against the candidate directory before removing or replacing the existing directory, and add a same-version repair regression that verifies the old shim still works after the candidate fails.

A same-version repair swaps files into the live version directory, so running
the runtime check after the swap meant a payload that cannot start replaced a
working CLI: the installer exited 1 and the existing shim was already pointing
at files that never ran.

The check now runs against the candidate directory (the fresh extraction, or
the reused directory) before anything on disk is removed or replaced. The
regression installs the fixture, drops current/INSTALL.json so the next run
takes the repair path, points the fixture at a payload whose runtime fails, and
asserts both the failure and that the old shim still prints its version.
Restoring the old order turns that assertion into an empty string.
@Walternater

Copy link
Copy Markdown
Contributor Author

Correct, and the order was the whole bug: a same-version repair writes into the version directory current already points at, so any check that runs after the swap is checking a replacement that has already taken over.

Fixed in 3ea1b838:

  • The runtime smoke check now runs against $VALIDATION_DIR — the fresh extraction, or the reused directory — before anything is removed or moved into place. The replacement only happens after both the INSTALL.json validation and the smoke check pass.
  • Regression test keeps the working install when a same-version repair fails its smoke check: install the fixture, remove current/INSTALL.json so the next run takes the repair path, point the fixture at a payload whose runtime exits non-zero, then assert the install fails and first-tree --version still prints 1.2.3.
  • Negative control: restoring the old order (swap, then smoke) makes that assertion return an empty string, which is exactly the shim failure you saw.

50/50 portable-builder tests pass; pnpm check and tsc --noEmit are clean.

@yuezengwu yuezengwu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The installer now runs the candidate runtime smoke check before replacing the existing directory. The new regression confirms that a failed same-version repair leaves the previous shim runnable. All 50 portable-builder tests passed locally, including the missing-file repair cases, and the installer passed the shell syntax check.

@yuezengwu
yuezengwu merged commit e8a8418 into first-tree-ai:main Nov 14, 2026
15 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install.sh: exit early when the installed version is already the latest

2 participants