Skip to content

fix(install): install.ps1 has herdr build a branch or commit from its own sources, as install.sh does - #3902

Merged
devswha merged 3 commits into
mainfrom
fix/windows-install-from-source
Nov 15, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/windows-install-from-source

Conversation

@devswha

@devswha devswha commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Why

"Real Windows install" fails on every head of #3892 (runs 43711123916, 43712359544, 43717953303) with
error: Cannot find module '@noble/hashes/sha2.js' from '...\checkout\shared\relay-e2ee.ts', right after
"Ovis: already installed". That PR is not at fault. Since #3800 (0.5.4):

  1. windows-install-e2e.ps1 -Ref <head sha> runs install.ps1, which installs the plugin at that commit with
    herdr plugin install --ref <sha> and does not set OVIS_FROM_SOURCE. install.sh sets it for any
    ref that is not a release tag ("a branch builds its own sources"), and install.ps1's own header says
    a branch installs from source.
  2. herdr's build step, bun scripts/plugin-launch.ts install, then takes the v0.5.4 release binary whenever
    the checkout's server/ and shared/ trees equal the ones in the signed manifest. test(ui-regression): run the UI regression in parts that each fit the lane's limit #3892 only changes
    scripts/, docs/, ci.yml and one line of package.json on top of the v0.5.4 commit. So its trees are
    v0.5.4's (server e30e62ab…, shared 532541c2…), and the build step installs the binary without
    running bun install.
  3. The plugin starts fine (the binary). Then the second install.ps1 run (herdr running) reads the status
    with bun <checkout>\scripts\plugin.ts status. That is a checkout without node_modules, so it fails.

PRs based on today's main pass only because main's server//shared/ have moved on since v0.5.4.
After the next release, every PR in this workflow that leaves those trees alone would fail the same way.
A user can hit it too: $env:OVIS_REF = '<branch or commit>'; irm https://ovis.sh/install.ps1 | iex
with herdr running, on a ref whose server/ and shared/ match the release (e.g. main right after a
release). The install ends with exit 1, and the branch runs the release's binary and client instead of
its own sources.

What changes

  • install.ps1: for a ref that is not a vX.Y.Z tag, herdr plugin install runs with
    OVIS_FROM_SOURCE=1 (the rule install.sh has), and the caller's variable is restored afterwards. The tag test is case-sensitive (-cnotmatch): tags are
    lowercase, so V0.5.4 is built from source, as install.sh's v[0-9]* case reads it. The
    launcher remembers that choice (.ovis/server/from-source), so herdr's later start and status commands
    keep running the checkout's sources.

  • install.ps1, a rerun over a branch already installed. This applies only to a rerun with OVIS_REF (or
    -Ref) naming a branch or commit, meaning anything other than a lowercase vX.Y.Z tag, over an installed checkout
    that has scripts/plugin-launch.ts and no .ovis/server/from-source naming its package.json version. That is the
    state an earlier install.ps1 left a branch in: the release's binary, with no node_modules. A plain rerun with no
    ref, or one with a tag, leaves that checkout as it is, and its status read still fails (see Follow-ups). The
    rerun:

    1. says "the installed branch runs the release's binary; building it from its own sources";
    2. stops that server with bun scripts/plugin-launch.ts stop, with OVIS_FROM_SOURCE cleared for this one
      command. A caller's OVIS_FROM_SOURCE=1 would send the stop to scripts/plugin.ts, which cannot run
      without the packages. If the stop fails, the rerun stops with a message;
    3. builds the checkout in place with OVIS_FROM_SOURCE=1 bun scripts/plugin-launch.ts install, which is
      herdr's own build step: bun install, bun run build, and the marker. The launcher writes the marker
      before it builds, so if the build fails, install.ps1 removes the marker again and stops with the error.
      Ovis is left stopped, and the next rerun with the same OVIS_REF builds again rather than starting
      sources that were never built. scripts/plugin-launch.ts's order is not changed here: herdr's own
      build step fails the install in that case anyway, and only this in-place rebuild needs the retry;
    4. restores the caller's OVIS_FROM_SOURCE, then runs the usual start (start-windows) and status read, which
      now run the branch's sources.

    The plugin is not reinstalled, so its ref and herdr's config stay. A checkout whose marker names its version is
    not rebuilt. The trigger is only "branch ref and no marker for this version", so it also rebuilds a checkout that
    still works without its marker: for example, a branch herdr plugin update moved onto the binary while its old
    node_modules stayed, or a tag checkout rerun with a branch ref. That costs a server restart and a build, not a
    failure.

  • scripts/windows-install.test.ps1: the herdr stand-in records what the build step was told. With the
    variable unset, a branch is built from source and the caller's variable is left unset; a release tag
    (v1.2.8, from source because its manifest is of the old shape) is not forced to source. A rerun over an installed
    plugin whose checkout has the launcher but no from-source marker (no packages) calls the launcher's stop and
    then install under OVIS_FROM_SOURCE=1, installs nothing through herdr, starts it and reads the status. With
    a tag ref, or once the marker names the version, nothing is rebuilt. The rerun case also runs with the caller's
    OVIS_FROM_SOURCE=1 set: the stand-in launcher fails a stop under that variable, as the real one does without
    packages. The stop still reaches the binary and the variable is 1 again afterwards. A build that fails (the
    stand-in writes the marker, then exits 1) ends the rerun with "bun failed" and leaves no marker, and the next
    rerun builds again. V1.2.3 counts as a branch, both on a fresh
    install (the one that replaces a copy without Windows support) and on a rerun.

  • INSTALL.md: "Binary or source" names install.ps1 beside install.sh. Changelog fragment.

Follow-ups (not in this PR)

  • install.sh's release-tag test (case "$ref" in v[0-9]*.[0-9]*.[0-9]*) is an unanchored glob, so
    v0.5.4-rc1, 'v0.5.4 ' and v1.2.3/feat count as release tags there and get the release's binary.
    install.ps1 now anchors and matches case. install.sh is left unchanged here.
  • At a release tag, install.ps1 can still end with the same Cannot find module: a plugin under the old id
    (moved, then installed fresh at the tag) or a copy from before Windows support (replaced the same way) gets the
    release's binary from herdr's build step, and the status read after the start ($script = ...\scripts\plugin.ts)
    needs the checkout's packages. The same holds for a rerun over a plugin herdr plugin install devswha/ovis
    installed at a tag. It also holds for a plain rerun, with no OVIS_REF, over a branch an earlier install.ps1 left
    on the binary: the in-place rebuild needs the ref. This PR's rerun repair covers none of these, because it needs OVIS_REF naming a branch or commit. The
    fix there is to read the status through the plugin's launcher (scripts\plugin-launch.ts status, which runs
    the binary or the sources as the build chose), in install.ps1 and in install.sh's
    bun "$root/scripts/plugin.ts" status.

Validation

  • bun run check fast: passed (workflow syntax, generated types/themes, typecheck, build, unit tests; exit 0, through heavy-run).

  • scripts/windows-install.test.ps1 runs only on Windows. GitHub's "Native Windows install" runs it, and
    the native Windows VM run is reported in a comment on this PR.

  • Before: runs 43711123916 / 43712359544 / 43717953303 above, plus the tree comparison:
    git rev-parse <ref>:server <ref>:shared gives the same trees for v0.5.4, a8ba05e, d3af150 and
    fb5e23e as the v0.5.4 ovis-server.json sources, and different trees for current main.

  • Not shown here: the real-install "after" on a commit whose trees match the release. This PR's own
    "Real Windows install" run starts from main, whose trees differ from v0.5.4, so it builds from source
    with or without this change. It checks that a branch install still works end to end, not the binary case.

  • Head c2b03f0 (round 3: the stop without the caller's OVIS_FROM_SOURCE, the marker removed after a failed build,
    the changelog): bun run check fast passed (exit 0). Windows VM pr-check.ps1 -Pr 3902 passed (PR-CHECK PASS):
    windows-install.test.ps1 STEP-PASS (exit 0, 49s) with the new caller-variable and failed-build-retry cases,
    plus preflight, bun install --frozen-lockfile, build, the Windows bun test set and the terminal browser QA.
    Not run: a real install of a branch on the binary followed by a rerun (pr-check runs the stand-in test).

This touches install.ps1, so it waits for GitHub's checks (Native Windows install, Real Windows install).

… own sources, as install.sh does

Since #3800 herdr's build step (scripts/plugin-launch.ts install) takes the release binary when a
checkout's server/ and shared/ trees match the release's. install.ps1 installed a branch or commit
without OVIS_FROM_SOURCE, so such a checkout got no packages, and the status read that follows,
bun scripts/plugin.ts status, failed with "Cannot find module" (Real Windows install on #3892).
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Windows installs so selecting a branch or commit builds the plugin from the selected source instead of failing with a missing-module error.
    • Release-tag installs retain their existing build behavior.
  • Documentation
    • Clarified that both Windows and shell installers use source builds when a branch or commit is selected.
  • Tests
    • Added coverage for source selection and preservation of existing environment settings during installation.

On Windows, install.ps1 temporarily enables source mode when installing a non-release ref, then restores the prior environment value. Tests cover branch and release-ref behavior. The documentation and changelog describe the update.

Changes: Windows source install

Layer / File(s) Summary
Select source mode during plugin install
install.ps1, scripts/windows-install.test.ps1, INSTALL.md, changelog.d/windows-branch-install-from-source.md
For non-release refs, install.ps1 sets OVIS_FROM_SOURCE=1 during plugin installation and restores the previous value afterward. Tests check the value observed during branch and release-ref installs. The documentation and changelog describe the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#3800: Introduced the installer source-build and release-binary paths that this change updates.
Merge Risk: Minimal · up to 24beb

Windows installs of branches or commits now select source mode, matching install.sh, and the caller's environment is restored afterward. No concrete merge-blocking risk was found; native Windows CI results are still awaited.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: install.ps1 now makes herdr build a branch or commit from its own sources, as install.sh does. It matches the changeset, which sets OVIS_FROM_SOURCE=1 for non-tag refs…
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.
Description check Passed The description follows the template: it has a Why/Change-style body that explains the problem and resulting behavior, and a detailed Validation section listing commands run (bun run check fast), re…
Full details: Title check

Explanation

The title names the main change: install.ps1 now makes herdr build a branch or commit from its own sources, as install.sh does. It matches the changeset, which sets OVIS_FROM_SOURCE=1 for non-tag refs in install.ps1. The title is long (101 characters) but still specific and accurate.

Full details: Description check

Explanation

The description follows the template: it has a Why/Change-style body that explains the problem and resulting behavior, and a detailed Validation section listing commands run (bun run check fast), results, and the Windows-only test that is pending on GitHub checks. It is long and dense, but the required content is present. The template's Change heading is not used verbatim (it uses Why and What changes), and no issue link is given for the feature. The author describes a fix to a bug, so a linked issue is not strictly needed. The template's HTTP/WS contract-test line is not applicable, and the description does not say whether the template's full check was run.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 139759a and 24beb14.

Files selected for processing: 4

  • INSTALL.md
  • changelog.d/windows-branch-install-from-source.md
  • install.ps1
  • scripts/windows-install.test.ps1

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Native Windows check (Windows 11 VM, pr-check.ps1 -Pr 3902, head 24beb14): PR-CHECK PASS.

  • windows-install.test.ps1: STEP-PASS (exit 0, 50s), including the two new assertions: a branch with OVIS_FROM_SOURCE unset is installed with OVIS_FROM_SOURCE=1 and the caller's variable is left unset ("native installer release selection, ... explicit ref ..." block), and the v1.2.8 tag is not forced to source ("the release binary ..." block).
  • preflight.ps1, bun install --frozen-lockfile, bun run build, bun test (windows set), windows-terminal-browser-qa.ts: all STEP-PASS; clone removed.
    Not run: the new test against main's install.ps1 (a forced "before"). Without the change, install.ps1 never sets the variable, so the branch assertion would read ''.

…ds it from source; tags match by case

A branch an earlier install.ps1 installed without OVIS_FROM_SOURCE runs the release's binary with no
packages, and a rerun read its status through scripts/plugin.ts and failed the same way. For a ref
that is not a release tag, a checkout with the launcher but no .ovis/server/from-source for its
version is now stopped and built in place with OVIS_FROM_SOURCE=1 bun scripts/plugin-launch.ts
install before the start and the status read. Release tags are matched case-sensitively (-cnotmatch).
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Native Windows check at a90aed4 (Windows 11 VM, pr-check.ps1 -Pr 3902): PR-CHECK PASS.

  • windows-install.test.ps1: STEP-PASS (exit 0, 50s). Its first block ("native installer release selection, rerun, ...") now also holds the rerun repair. An installed checkout with the launcher and no from-source marker gets the launcher's stop, then install under OVIS_FROM_SOURCE=1, with no herdr reinstall, then is started and reads running. A tag rerun and a rerun with the marker rebuild nothing. V1.2.3 is treated as a branch on a fresh install and on a rerun.
  • preflight.ps1, bun install --frozen-lockfile, bun run build, bun test (windows set), windows-terminal-browser-qa.ts: all STEP-PASS; clone removed.
  • Not run: a real install of a branch left on the release's binary, followed by a rerun (pr-check runs the stand-in test, not windows-install-e2e.ps1).

…OVIS_FROM_SOURCE, and a failed build is retried

With OVIS_FROM_SOURCE=1 set by the caller, the launcher handed the repair's stop to
scripts/plugin.ts, which cannot run without the packages, so the repair could never run. The stop
now runs with the variable cleared, restored afterwards. The launcher names the version in
.ovis/server/from-source before it builds; when the in-place build fails, install.ps1 removes it
again so the next rerun with the same OVIS_REF builds again. The changelog says a rerun repairs
only with OVIS_REF naming the branch or commit.
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Native Windows check at c2b03f0 (Windows 11 VM, pr-check.ps1 -Pr 3902): PR-CHECK PASS. windows-install.test.ps1 STEP-PASS (exit 0, 49s), including the new cases. With the caller's OVIS_FROM_SOURCE=1 set (the stand-in launcher fails a stop under it), the rerun still stops the binary, builds, and leaves the variable 1. A build that fails ends the rerun with "bun failed" and leaves no marker, and the next rerun builds again. preflight, bun install --frozen-lockfile, build, bun test (windows set), windows-terminal-browser-qa.ts: STEP-PASS; clone removed.

@devswha
devswha merged commit 857bbb0 into main Nov 15, 2026
15 of 16 checks passed
@devswha

devswha commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head c2b03f0963b2 as 857bbb0167a8 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

This is the fix for the Real Windows install failure that #3892 was merged over: install.ps1 did not set OVIS_FROM_SOURCE for a ref that is not a release tag, so a branch or commit whose server/ and shared/ trees equal a release's was left on the release's binary and the installer's second pass failed. At this head a branch or commit builds from its own sources, as install.sh does, and a rerun that names the branch repairs an install the old installer left on the binary. Native Windows install and Real Windows install passed on this head (run 43723962103). A release tag still installs the verified binary and a plain install is unchanged.

Three review rounds; each finding of the earlier rounds is closed at this head (a caller's own OVIS_FROM_SOURCE no longer breaks the repair's stop; a failed build is retried on the next run; tags are matched case-sensitively).

Not run by the reviews: PowerShell itself (none on the review machine; the Windows VM check passed), and a real end-to-end install left on the release binary followed by a rerun.

Left open, not blocking (owner PR; traced, not run):

  • MEDIUM (codex): a repair interrupted with Ctrl+C can leave an incomplete build marked as ready: the marker is removed in catch, which an interrupt does not reach (move it into finally behind a success flag).
  • MEDIUM (codex): the repair treats any requested branch as the installed checkout: the existing-plugin path never compares the ref with the checkout or changes its revision.
  • LOW: a failed build leaves Ovis stopped without saying so; a developer source checkout with no marker can fail to stop when offline; the repair also rebuilds a working checkout whose marker is gone (once); install.sh's tag test is unanchored; at a release tag the status read still goes through scripts\plugin.ts.

Review reports: ~/.cache/ovis-tmp/reports/

@devswha
devswha deleted the fix/windows-install-from-source branch November 15, 2026 14:54
devswha added a commit that referenced this pull request Nov 15, 2026
…ut off, refuses another ref, and says Ovis is stopped after a failed build (#3916)

Follow-up to #3902 (install.ps1 builds a branch or commit from its own
sources, and a rerun repairs an install left on the release binary). It
fixes what #3902's last reviews found by reading, then what #3916's
reviews at e41af29 and d974c30 found. The reviews read the code; the
Windows VM runs below are the only runs.

## What changes

1. **A build that is cut off is built again, within one limit.**
`scripts/plugin-launch.ts install` writes `.ovis/server/from-source`
*before* it builds.
- **Ctrl+C:** PowerShell runs `finally`, not `catch`, so the marker is
removed in `finally` unless the build returned 0.
- **A closed window or a restart:** no `finally` runs. So the repair
trusts the marker only beside what a finished from-source build leaves:
`node_modules` (`bun install`) and `dist/index.html` (`bun run build`,
which is `vite build`). The PTY-host step is not needed on Windows.
- A leftover marker is removed before the stop, so the stop does not go
to sources that never built.
- **No cached release binary:** when the checkout has neither the
release's binary (`.ovis\server\bin\ovis-server.exe`) nor
`node_modules`, the stop is skipped. Nothing of the checkout can be
running then. The launcher's stop would ask the release, find that this
branch's sources are not the release's (or be offline), and fail in the
unbuilt sources: shown below with the real launcher.
- **The limit:** a checkout that still holds the packages and client of
an *earlier* build looks finished when a later build is cut off, because
the marker of the new version is written before `bun install`. The
changelog fragment says so. A stamp written only after the build
returns, in `scripts/plugin-launch.ts`, is the follow-up.
2. **A requested ref must name the installed checkout.** herdr checks a
plugin's ref out detached. Before it stops or builds anything, the
repair compares `git rev-parse HEAD` in the checkout with what the ref
names:
- a hexadecimal ref of 4 to 40 characters is matched against the
checkout's objects with `git rev-parse --disambiguate=<ref>`, so short
ids work, and a local ref of that name cannot stand in for GitHub's
branch;
- otherwise `git ls-remote <url> -- <ref> <ref>^{}` finds a branch, a
lightweight tag, or an annotated tag by its peeled commit.

When they differ (another branch, a branch that moved since it was
installed, another commit), or when GitHub cannot be asked, the
installer says so with both commits ("…, not <id>" for a commit id) and
how to move the plugin (INSTALL.md, Update: `herdr plugin install …
--ref <ref>` replaces the checkout). It also says **nothing was stopped
or changed by this run**. I chose the message over switching the
checkout inside the installer: a rerun keeps the installed plugin today,
for every ref.
3. **A failed rebuild says Ovis is stopped and how to get it back.** It
hands over `OVIS_REF=<ref>` for the rerun. When the checkout keeps the
release's binary of **this** version (the kept `ovis-server.json` names
it, and `ovis-server.exe` and its `dist\index.html` are there), it adds
`herdr plugin action invoke devswha.ovis.start-windows`. With the marker
gone, the launcher's start runs that binary (`verifiedInstall`, which
also checks the signature).

`changelog.d/windows-branch-install-from-source.md` (#3902's fragment)
is amended rather than joined by a second one. #3902's merge commit
857bbb0 is only in `beta/v0.5.5-beta.*` tags, in no `vX.Y.Z` release.

Still open, not in this PR:
- The launcher writes the marker before the build. That affects the
earlier-build case above, and a cut-off `herdr plugin install` build
step on every platform. It belongs in `scripts/plugin-launch.ts`.
- An install whose source build is complete ignores a different
`OVIS_REF` ("already installed"). That was so before #3902, for every
ref, and checking it on every rerun needs the network.
- A developer's source checkout with no marker cannot be stopped when
offline.
- install.sh's test for a release tag is not anchored.
- The status read goes through `scripts\plugin.ts` at a release tag.

This PR touches `install.ps1` and a `.ps1` test, so it waits for
GitHub's own checks: **Native Windows install** and **Real Windows
install**.

## Validation

**The real launcher, in the Windows VM.** This used a real clone of main
(0de9571, v0.5.4) as the plugin checkout, in the state a cut-off source
build leaves: marker `0.5.4`, no `node_modules`, no `dist`, no
`.ovis\server\bin`. herdr was a stand-in (plugin list, not running);
git, Bun and `scripts/plugin-launch.ts` were real.
- **d974c308's install.ps1:** the stop went to the launcher, which said
"this checkout's server/ and shared/ are not the ones v0.5.4 was built
from … runs from source", then "Cannot find module
'@noble/hashes/sha2.js'". The installer threw "Could not stop the Ovis
the release's binary runs, so the branch was not built…".
- **This PR's install.ps1:** no stop, then the real build (237 packages
installed, `vite build`, no Rust PTY host for win32-x64), then the
installer finished. Afterwards the marker was `0.5.4`, `node_modules`
and `dist\index.html` were present, and there was still no cached
binary.

**The test's stand-in launcher** now fails a stop exactly where the real
one does: under `OVIS_FROM_SOURCE=1`, with a marker naming the version,
or with no cached binary, whenever `node_modules` is missing. Checkouts
"on the release's binary" now keep one. Cases in
`scripts/windows-install.test.ps1`:
- **Build cut off by Ctrl+C:** the installer runs in a pipeline of its
own, stopped with `PowerShell.Stop()`. The marker must be gone and the
rerun must rebuild.
- **Build cut off where no `finally` runs, with a cached binary:** the
rerun must stop the binary and rebuild.
- **The same with no cached binary (new):** the rerun must rebuild
without a stop.
- **Refusals:** another branch, a branch that moved, another commit id,
and GitHub out of reach must leave nothing stopped or built. The first
three must name both commits.
- **Refs that name the installed commit:** 12- and 5-character ids and
an annotated tag must build the checkout.
- **Failed build:** the message must hand over
`OVIS_REF=feat/windows-install` and the start-windows command. **New:**
it must not hand over the start when the kept binary is of another
version.

**Before and after of these cases, natively in the VM** (Windows
PowerShell 5.1, fresh clones of main; a scratch copy of the test whose
`Assert` reports and continues, stopped after the repair section):
- **origin/main's install.ps1:** 20 pass, **12 fail**: every new
behaviour, including the no-cached-binary cut-off.
- **d974c308's install.ps1** (the previous head): 30 pass, **2 fail**:
- "A cut-off build with no release binary kept must be built again
without a stop (launcher: stop): Could not stop the Ovis the release's
binary runs…";
  - the start of a kept binary of another version was handed over.
- **This PR's install.ps1:** 32 pass, 0 fail.
- The unchanged test file with this PR's install.ps1, in full: exit 0,
every PASS line.

Other checks:
- `bun run check fast` on the final commit: passed (exit 0) at 1203aad:
lint, generated files, typecheck, build, and unit tests (17461 pass, 0
fail, 54 skip; heavy-run slot 12, 567 s).
- The VM's `pr-check.ps1 -Pr 3916` at the new head: in a PR comment.
- Skipped: `bun run check full` (no TypeScript changed), and
`install.sh` tests (not touched).
devswha added a commit that referenced this pull request Nov 15, 2026
…ly after it succeeds, and install.ps1 trusts that stamp (#3923)

Follow-up to #3916 (install.ps1's repair of a branch install), before
the next release. It fixes the two places where #3916's changelog
fragment said more than the code did. Both were named in #3916's last
reviews, and I checked each one against origin/main before changing
anything. Commits two and three are review rounds: t87 at c695d61, then
dori's delta review and t87 at c86d601.

## What changes

1. **A from-source build counts as finished only after it succeeds**
(`scripts/plugin-launch.ts`, all platforms). The launcher wrote
`.ovis/server/from-source` *before* `bun install` and the build. Two
things went wrong because of that:
- A build cut off in `bun install` made every rerun stop at a stop that
could not load its packages.
- A later build that was cut off looked finished, because an earlier
complete build had left `node_modules` and `dist/index.html` behind.

   **What each file means:**
- `.ovis/server/from-source`: **unchanged.** It means "this checkout
runs from source" for the version it names. The launcher writes it
before the build, and every `install` removes it first. The launcher
still reads only this file.
- `.ovis/server/source-build`: **new.** Each `install` removes it first.
When the source path is taken, it says `started` before the marker and
before `bun install`. It is replaced by `<version> <commit>` only after
`bun install`, the build and the PTY-host step have all returned 0.
Where git cannot read the commit, it holds the version alone.
- **install.ps1** counts a checkout as built only when all of these
hold:
     - the marker names `package.json`'s version;
     - `node_modules` and `dist\\index.html` are there;
- the stamp is absent (an **old checkout**, built by today's launcher:
still taken as built, so the update does not rebuild it), or is
`<version> <installed commit>`, or is the version alone where
install.ps1's own git cannot read the commit either.

Where install.ps1's git *can* read HEAD, a version-alone stamp means one
rebuild, and that rebuild stamps the commit. Accepting the version alone
there would keep accepting a checkout that has moved since. The git-less
launcher case still works: its build is taken as finished wherever the
installer cannot read the commit either.

   **The stop before a rebuild, and one rule for a live server:**
- With a cached release binary, the stop goes to it. If that stop fails,
the run is refused, as before.
- Without a cached binary, the stop runs with `OVIS_FROM_SOURCE=1`,
straight into `scripts/plugin.ts` with no release look-up. If that stop
fails, the failure is passed over: a leftover `dist\\index.html` no
longer refuses on its own. That was the dead end dori found: a rebuild
over an earlier finished build, cut off in `bun install`, was refused on
every rerun.
- Then, **whether the stop ran, failed or had nothing to run it with**,
install.ps1 asks the record `scripts/plugin.ts` keeps of its server:
`server.pid` and `server.owner` (pid and Windows creation time). It
looks in herdr's plugin state dir under either id, in
`HERDR_PLUGIN_STATE_DIR`, and in `~\\.local\\state` for a server started
by hand. A live one refuses the build.
- A successful stop takes the record away (`plugin.ts`'s stop removes
`server.pid`), so this costs a healthy repair nothing. The tests below
cover that: the release binary's server and a source server, both
stopped and then built.
- **The refusal** names the process. It suggests `Stop-Process -Id N`
only when the creation time was compared and matched. Otherwise it says
the record names a process that could not be verified as the Ovis
server.
- **A pid now held by another process** (the creation time differs) is
not the server, so it does not refuse: the recorded server is provably
gone. I kept this against Codex's MEDIUM at c86d601. Refusing would
only block a repair with nothing running.

Every release writes `server.pid` (since v0.1.0), and `server.owner`
since v0.4.20; a record without `server.owner` counts as unverified.
Vite 8.3.4 empties `dist` in `renderStart`, before chunks are rendered
and written, so a cut-off build can leave no client while an earlier
server still runs. Route (A) (release out of reach) and route (B) (two
interruptions) are both covered by the record.

2. **`OVIS_REF` over an installed Ovis that needs no build is now
mentioned.** install.ps1 used to print only "already installed".
install.sh did the same, on its plugin and herdr-core paths. Both now
print one line, with no network call: `the installed … is at commit
<12>; OVIS_REF does not move an installed … (INSTALL.md, Update)`.
- install.sh leaves the commit out when herdr names no plugin root.
Before, `git -C ""` read the commit of whatever directory the installer
ran in.
- install.ps1 reads HEAD with `git … 2>$null` under a local
`$ErrorActionPreference = 'Continue'`. A folder that is no git checkout
no longer fails a rerun, and git's message stays off the console.

3. **install.ps1 no longer grows PATH on every run** (the cause of
GitHub's red "Native Windows install" at c86d601, twice). install.ps1
put `%USERPROFILE%\.bun\bin;%LOCALAPPDATA%\Programs\Herdr\bin` in front
of `$env:PATH` on every run. `windows-install.test.ps1` runs the
installer many times in one process, so PATH grew 84 characters a run.
- Measured on windows-latest with debug output, from a throwaway draft
(#3925, closed and deleted): 2692 characters at the start, 8132 just
before the star test's `refuses` case, 8216 inside it.
- Past cmd.exe's 8191, gh's `.cmd` stand-in exited 255 with no output,
so the installer saw no `404` and printed only the link. The case just
before it ran at 8132 and passed.
- This PR's new cases added the runs that crossed the limit. The VM's
shorter PATH and user name never got there.
- Now the pair is put first only when PATH does not already start with
it. A first run is unchanged, and a rerun in the same session (a user's
`irm … | iex` twice) no longer grows it.

The changelog: I amended
`changelog.d/windows-branch-install-from-source.md`. It is #3902's
fragment, still unfolded, and holds both sentences, rewrapped near 100
columns.

**Faults that remain after this PR:**
- **A live server that left no record where install.ps1 reads**, over a
built client, is built under. That covers a server not started through
`scripts/plugin.ts` (for example `bun run start` in the checkout) and
one started with a `HERDR_PLUGIN_STATE_DIR` other than herdr's.
- Every released version writes `server.pid`, so this is never a server
a release's start made.
- On Windows, `bun install` then fails on the files the server holds
open. The installer's failure then says a server no stop reached may
still run from the checkout, and gives `Get-CimInstance Win32_Process |
Where-Object CommandLine -like '*<checkout>*'` to find it and
`Stop-Process` to stop it. The marker is taken back, so herdr's start
path is as it was.
- **With a cached release binary, a failed stop refuses every rerun,
even where nothing runs**, in two states:
- **A kept binary of another version over broken or missing packages.**
The launcher does not run another version's binary, so the stop goes to
the sources and cannot load. This is #3916's review LOW, unchanged.
Recovery: remove the checkout's `.ovis\\server\\bin` and run the
installer again. The stop then goes to the sources, is passed over
unless a live server is recorded, and the build runs.
- **A binary of this version whose stop finds a pid record it cannot
verify** (the pid taken by another process since): `plugin.ts` stop says
"could not verify the recorded Ovis process" and exits 1. Recovery:
delete that `server.pid` in
`%LOCALAPPDATA%\\herdr\\plugins\\devswha.ovis`, then run again.

  I did not change behaviour there in this round.

This PR touches `install.*`, a `.ps1` and `scripts/plugin*`, so it waits
for GitHub's own checks (Native Windows install, Real Windows install),
not only a local gate.

## Validation

**This round (820454a over c86d601):**
- **`scripts/windows-install.test.ps1` in the Windows VM**, Windows
PowerShell 5.1, a scratch copy whose `Assert` reports and continues,
stopped after the repair section:
  - c86d601's install.ps1: 65 pass, **8 fail**.
  - This head's: 73 pass, 0 fail.

  Cases that flip (they fail at c86d601 and pass here):

  | case | expected now | at c86d601 |
  |---|---|---|
| a build cut off in bun install over the client of an earlier one |
stop fails, passed over, built and stamped | refused ("Could not
stop…"), on every rerun |
| the same, the server recorded without its creation time | refused,
names the pid, no `Stop-Process` | refused with `Stop-Process -Id` |
| a stamp of the version alone, which this installer's git can read the
commit of | rebuilt | kept |
| a server recorded as running with nothing to stop it with (no
packages, no release binary) | refused, no launcher call | built under
it (`install 1`) |
| a failed build after a stop that could not run | the failure names the
checkout to find a server by, marker taken back | "…and Ovis is stopped"
|

  New cases that pass on both heads:
- The counterpart of the first case with a recorded live server:
refused, with `Stop-Process -Id`.
- "a release binary's server recorded as running, stopped by its stop":
built, so a successful stop clears the record and a healthy repair goes
on.
- The version-alone stamp where install.ps1's git cannot read HEAD
either: kept.

The test now uses its own herdr state dir (`XDG_STATE_HOME`) for its
whole run, restored at the end. Without that, the unconditional record
check found the VM's own Ovis: pid 8856, creation time verified, in
`%LOCALAPPDATA%\\herdr\\plugins\\devswha.ovis`. That is live evidence
that the check reads a real server's record.
- **GitHub's red job, reproduced in the VM:** the real file as GitHub
runs it (Windows PowerShell 5.1, `CI=true`, desktop session), with PATH
padded so it reaches the runner's length.
- c86d601 fails in the star block ("A yes must star once": the same
lost `404`, one case earlier than on the runner because the padding is a
little larger).
  - This head passes every section, exit 0.
- Unpadded, c86d601 passes in the VM, which is why the VM's pr-check
was green there.
- **The full, unchanged test file in the VM's desktop session**
(`Invoke-InSession`): every section printed PASS.
- **git's stderr, in the VM, against a folder that is no git checkout,
under `$ErrorActionPreference = 'Stop'`:**
- Windows PowerShell 5.1.26100 (ConsoleHost): `2>$null` alone **throws**
"fatal: not a git repository". The new form gives exit 128, an empty
commit, and no error.
- pwsh 7.6.9: the new form gives the same; `2>$null` alone does not
throw.
- `scripts/install-star.test.ts` (Linux): 44 pass, 0 fail. The new "says
no commit when herdr names no plugin root, rather than the one of the
directory it runs in" fails with c86d601's install.sh.
- `scripts/plugin-launch.test.ts` and `scripts/changelog-fold.test.ts`:
25 pass, 0 fail. `sh -n` and `dash -n install.sh`: OK.
- `bun run check fast` on 820454a, through heavy-run: passed (exit 0):
workflow syntax, generated files, typecheck, build, and unit tests
(17562 pass, 0 fail, 54 skip; heavy-run slot 12, 530 s).
- The VM's `pr-check.ps1 -Pr 3923` at 820454a: in a PR comment.

**Earlier rounds:**
- c86d601: VM 54 → 61, 0 fail; routes (A) and (B); stamp plus outputs.
- c695d61: origin/main 39 / 10 fail → 49 / 0; the real launcher in the
VM with partial `node_modules`.

**Not run:**
- macOS.
- `bun run check full`.
- A real cut-off `bun install`.
- A real build under a real unrecorded server: the
bun-install-fails-on-open-files walk is the stand-in case "a failed
build after a stop that could not run".
- shellcheck and PSScriptAnalyzer: not on this PC, and the repo has no
lint script for them.
devswha added a commit that referenced this pull request Nov 15, 2026
…the launcher stamps the commit its build started from (#3928)

Follow-up to #3923 (merged as c9084e0), before the next release. It
covers small points from #3923's last reviews (the merge pass's two
review tables, dori's receipt) and from CodeRabbit's two threads on
#3923. Most of them are install.ps1 refusals that now name a recovery
that works. The second commit answers the reviews of a5ea99e: dori's
block, and t87's two reports.

This PR does not change when the installer builds, stops or refuses,
except where a point says so:
- point 4b: the repair's stop is told herdr's state dir;
- point 7: the launcher's stamp;
- point 8: which commit counts as the installed one, and which stamps
are accepted where it cannot be read;
- point 9: the trees a release binary is tied to.

## What changes

1. **An unverifiable record whose pid another process holds now names
the file to delete** (install.ps1, `Get-RecordedServer` and the
refusal). "Unverifiable" means `server.owner` is missing or cannot be
read.
- Before: when the stop could not run (broken or missing packages, no
release binary), every rerun refused with "check what it is before
stopping it", and nothing ever cleared the record.
- Now: `Get-RecordedServer` gives back the `server.pid` file it read.
The refusal names that file's full path and says to delete it if the
process is not Ovis, then run again.
2. **A failed stop through a kept release binary now names its
recovery** (the refusal "Could not stop the Ovis the release's binary
runs"). One recovery for each state:
- **The kept binary is of another version** (or its `ovis-server.json`
cannot be read). Now: remove `<checkout>\.ovis\server\bin`, then run
again.
- **A binary of this version that fails its check** (signature,
executable or bundled client: `scripts/server-install.ts`
`verifiedInstall`), with the release out of reach, and no server
recorded as running. The stop never reached a server. Now it says so and
gives the same recovery: remove the folder. *(second commit)*
- **The binary is of this version, and its stop cannot verify a live
pid** (the pid in `server.pid` is another process's now, or the record
has no creation time). Now the refusal names that `server.pid` and says
to delete it if the process is not Ovis.
- **A verified server that the stop failed to stop.** As before, plus
"It runs as process N (Stop-Process -Id N stops it)".
3. **"Ovis is stopped" is said only after a stop that stopped one.**
`scripts/plugin.ts`'s stop exits 0 both for a server it stopped (stdout
`stopped Ovis (pid N)`) and for none (`Ovis is not running`).
install.ps1 now reads that line; there is no new protocol. A build that
fails after a stop that stopped nothing keeps the "an Ovis no stop
reached may still run … `Get-CimInstance`" advice.
4. **A server started by hand.**
- **(a) Its refusal says what it is.** A record in `~\.local\state\ovis`
or `\herdr-web-ui` belongs to any hand-started Ovis, from any checkout.
The refusal now reads "An Ovis started by hand is recorded as running in
`<dir>`".
- **(b) The repair's stop no longer stops it.** *(second commit)* The
stop is now told `HERDR_PLUGIN_STATE_DIR = <herdr state>\plugins\<id>`,
as herdr's own stop and the installer's legacy move are (the caller's
value is kept when it has one).
- Run without it, `scripts/plugin.ts` takes a live record in
`~\.local\state` first. With packages that load, it stopped a
hand-started server, possibly another checkout's, before any refusal.
- Now that server is left running, and the record check refuses with
(a).
- The record holds nothing that names its checkout (`server.pid`: the
pid; `server.owner`: pid and creation time), so the installer refuses it
rather than guessing.
5. **The changelog fragment** (`windows-branch-install-from-source.md`,
#3902's, still unfolded): every sentence now holds. The installer stops
a server that herdr's start recorded, where the checkout can run that
stop. Where a recorded server still runs (one started by hand among
them), or the kept binary cannot run the stop, nothing is built, and it
says what to stop or remove.
6. **A failed build where no stop could run and no record was found**
prints a short line instead of the long `Get-CimInstance` advice.
7. **The launcher's finished stamp names the commit the build started
from** (`scripts/plugin-launch.ts`, from CodeRabbit's thread on #3923 at
`:94`).
- HEAD is read before the build and again after it. The stamp becomes
`<version> <commit>` only when both reads agree; otherwise it stays
`started`, with one line on stderr. The launcher still returns 0: the
build did succeed, and herdr's own build step runs the same launcher.
- *(second commit)* install.ps1 re-reads the stamp after its build. When
it is still `started`, it says that the checkout moved while it was
built, that herdr's next start still runs that build as it is, and that
a run with `OVIS_REF` naming the commit the checkout is at now builds
that one.
8. **One rule for the installed commit: a checkout's top level only.**
`git -C <dir> rev-parse HEAD` reads the repository that *contains*
`<dir>`.
- All three readers now ask `git rev-parse --show-prefix` first and read
HEAD only when it prints nothing: install.sh `ref_not_moved`,
install.ps1 `$installedCommit`, and *(second commit)* the launcher's
`headCommit()`. So a plugin folder inside another repository has no
commit, and its launcher stamps the version alone.
- I used `--show-prefix` instead of comparing `--show-toplevel` with the
folder as resolved paths. It gives the same answer without comparing
Windows path spellings (8.3 names, junctions, slashes, case).
- *(second commit)* **Where install.ps1 cannot read the commit, it
accepts any stamp whose first word is this version.** That covers
`<version> <commit of the repository around it>`, which #3923's launcher
(and a5ea99e's) already wrote in a nested folder. install.ps1 is
fetched fresh on every `irm | iex`, so those users would otherwise hit a
refusal the moment this merged. Where it *can* read the commit, nothing
changes: the stamp must name it, so a moved checkout is rebuilt once.
- Only a nested or git-less folder whose build really is unfinished
(`started`, or packages or client missing) is still refused, because the
installer cannot tell whether that folder is `$Ref`. That refusal now
gives its recovery: stop Ovis, run `$env:OVIS_FROM_SOURCE = '1'; bun
'<root>\scripts\plugin-launch.ts' install`, then run again. The launcher
builds the folder as it is and stamps the version alone, which the next
run accepts.
9. **The release binary's source trees are this folder's own** *(second
commit, same family)*. `sourceTrees` (`scripts/server-manifest.ts`) read
`HEAD:server`, which git resolves from the repository's top level. In a
folder inside another repository, that named the surrounding
repository's `server/`. It now reads `HEAD:./server` and
`HEAD:./shared`. A tree id names content, so it holds at any depth; it
needs no top-level rule, only the folder's own path.

**Readers of the commit that keep their rule, and why:**
`scripts/plugin-runtime.ts`, `server/managed.ts` and install.sh's
release lookup (`install.sh:324`) compare HEAD with the
`source_revision` that `server/updater.ts` wrote from its own `git
rev-parse HEAD`. They form one writer–reader pair, read at the same
depth, and never meet the stamp or the installers' commit. Moving only
the readers to the top-level rule would split them from the updater.
What the updater does in a folder inside another repository is its own
question, outside this PR.

## States touched

| state | before | after |
|---|---|---|
| unverifiable record (no `server.owner`), live pid of another process,
stop cannot run | refused on every rerun, "check what it is before
stopping it" | refused, names `<dir>\server.pid` to delete if it is not
Ovis; deleting it lets the next run build |
| kept release binary of another version over broken packages | "Could
not stop … Stop it (stop-windows, or restart herdr)" on every rerun |
names `<checkout>\.ovis\server\bin` to remove; removing it lets the next
run build |
| kept binary of this version failing its check, release out of reach,
no record | the same dead end | says no server is recorded and the
binary failed its check; names the folder to remove; removing it lets
the next run build |
| kept binary of this version, stop cannot verify a recorded live pid |
the same dead end | names that `server.pid` to delete if that process is
not Ovis; deleting it lets the next run build |
| hand-started server recorded in `~\.local\state`, packages that load
the stop | the repair's stop stopped it (any checkout's), then built |
left running; refused: "An Ovis started by hand is recorded as running
in `<dir>`" |
| the same, the stop cannot load | "Ovis still runs from this checkout"
| "An Ovis started by hand is recorded as running in `<dir>`" |
| build fails after a stop that found no server | "and Ovis is stopped"
| "an Ovis no stop reached may still run …" with the `Get-CimInstance`
line |
| build fails, nothing to run a stop with, no record | the long
`Get-CimInstance` advice | a short line |
| HEAD moved during the launcher's build | stamp `<version> <new
commit>` | stamp stays `started`; install.ps1 says so |
| nested plugin folder (inside another repository), finished build |
commit of the repository around it printed and compared | no commit;
launcher stamps `<version>`; accepted |
| nested folder with a stamp `<version> <outer commit>` from #3923's
launcher | accepted (both sides read the outer commit) | accepted (any
stamp of this version, where the commit cannot be read) |
| nested folder, build unfinished | refused ("is it a git checkout?") at
a5ea99e | refused with the recovery (build it with its launcher);
following it, the next run accepts it |
| release binary's source trees in a nested folder | the outer
repository's `server/` and `shared/` | the folder's own |

## Faults that remain

- **A build left `started` because HEAD moved is still used by the next
plain start on every platform.** The start reads only the marker. That
is no worse than main, where the stamp claimed the new commit and nobody
noticed. install.ps1 now says it, and its next run with `OVIS_REF`
naming the commit rebuilds it. A rebuild at start (herdr's start hook,
possibly over a running server) is its own change.
- **With no git on PATH, the launcher fails on every command**, in
`sourceTrees` (`Bun.spawnSync` throws ENOENT), before it stamps
anything, as on main. Follow-up: catch the spawn error there and return
`{ error }`.
- **A live server that left no record where install.ps1 reads is built
under**, as #3923's body says. The `Get-CimInstance` line a failed build
prints finds it; it matches on `CommandLine`, so it can also list an
editor or shell opened on the folder.
- **The commit readers of the updater pair keep any depth**:
`plugin-runtime.ts`, `managed.ts`, `install.sh:324`, `updater.ts` (see
above).

## Validation

On 260f292 (the second commit, over a5ea99e). origin/main moved
meanwhile to fd6ca75 (#3927, a copilot test, no overlap); not rebased,
so that this push needs no force-push.

**This round:**
- **`scripts/windows-install.test.ps1` in the Windows VM**, Windows
PowerShell 5.1.26100, in the VM's desktop session (`Invoke-InSession`),
with `CI=true`, run as ci.yml runs it, in a clone of a5ea99e with this
commit's `install.ps1` and test file:
- unpadded (PATH 335 characters at the start): every section printed
PASS, exit 0;
- **PATH padded to 2710 characters at the start**: every section printed
PASS, exit 0.
- **Counts, the whole file**, from a scratch copy whose `Assert` counts
and continues, with this commit's test file:

  | install.ps1 | pass | fail |
  |---|---|---|
  | c9084e0 (main), round 1 | 174 | 10 |
  | a5ea99e (this PR's first commit) | 189 | 9 |
  | 260f292 (this commit) | 195 | 3 |

The 3 failures in every row are the gh-ordering negative control, which
relies on `Assert` throwing (an artifact of the counting copy; the real
file passes that section). At a5ea99e these new cases fail:
- "the same, with packages that load the stop: it is left running": the
stop stopped the hand-started server and the run built (2 assertions);
- "the same, stamped by an earlier launcher with the commit of the
repository around it": "git could not read the commit…", the HIGH;
- "a build cut off in a folder inside another git checkout": no recovery
named;
- "a kept release binary of this version that fails its check, the
release out of reach": "Stop it … or restart herdr";
- "a build during which the checkout moved to another commit": nothing
said.

"the same, stamped with the version alone by the launcher" passes at
a5ea99e too, since that form was already accepted there. Each refusal
case with a recovery does what the message says and asserts the next run
builds, or, for the nested folder, accepts the folder with the stamp the
launcher wrote (`1.2.3`).
- The stand-in's stop now reads only the state dir it is told (else
`~\.local\state`'s while a pid is recorded there, else herdr's), as
`scripts/plugin.ts` does. The stand-in launcher stamps the version alone
where the git stand-in reads no commit, leaves `started` when HEAD
moves, and fails for a kept binary that fails its check. The git
stand-in's first line is `$global:LASTEXITCODE = 0` (line 33), which
also covers its `--show-prefix` answer (dori's LOW; no change needed).
- **TS tests** (Linux, `HERDR_TEST_MODE=unit`): `plugin-launch.test.ts`,
`install-star.test.ts`, `changelog-fold.test.ts`,
`server-manifest.test.ts`: 99 pass, 0 fail. The new tests fail without
their change:
- "stamps the version alone for a folder that is not a checkout's top
level…", against a5ea99e's HEAD-only `headCommit` in a scratch copy: 14
pass, 1 fail;
- "the git trees … are the folder's own server/ and shared/…", against
the old `HEAD:server`: 26 pass, 1 fail.
- `sh -n` and `dash -n install.sh`: OK.
- **`bun run check fast`** through heavy-run (slot 10, 522 s): exit 0,
unit tests 17566 pass, 0 fail, 54 skip.
- The VM's `pr-check.ps1` at this head: in a PR comment.

**Round 1 (a5ea99e):** VM counts c9084e0 174/10 → a5ea99e 181/3 with
that round's test file; the real file passed unpadded and padded; 71 TS
tests; `check fast` exit 0 (17564 pass); VM pr-check PASS; Native
Windows install and Real Windows install passed.

**Not run:** macOS; `bun run check full`; the real launcher with HEAD
moved during a real `bun install` (the test stands in for git); a real
cut-off build, a real Ovis release binary failing its check, or a real
hand-started Ovis in the VM (the states are made with the test's
stand-ins, and its own process as the recorded server); a real plugin
folder nested in another repository on Windows (the git stand-in answers
`--show-prefix`; the launcher's rule is run with real git on Linux);
shellcheck and PSScriptAnalyzer.
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