Skip to content

fix(windows): stop an old-id server that outlived herdr, re-read the PC on Try again, show the QR with a token and a readable log (#2264) - #2275

Merged
devswha merged 1 commit into
mainfrom
fix/windows-app-update-old-server
Oct 28, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/windows-app-update-old-server

Conversation

@devswha

@devswha devswha commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #2264

Problem

Testing the Windows app's Update for an older server (#2091, #2113) in the Windows 11 VM, with Ovis.exe 0.4.19 and devswha.herdr-web-ui 0.3.45 installed under the old id, found four problems (reproduced again on main 9a44f27 before this change):

  1. An old-id server that outlived herdr was never stopped, so Update failed and then looped. The app and install.ps1 run the old checkout's scripts/plugin.ts stop outside herdr. Releases before 0.4.13 read their pid from HERDR_PLUGIN_STATE_DIR and, without it, from ~/.local/state/herdr-web-ui, while herdr keeps it in %LOCALAPPDATA%\herdr\plugins\devswha.herdr-web-ui\server.pid. The stop said "not running", install.ps1's herdr plugin uninstall devswha.herdr-web-ui failed with Os { code: 32 }, and the half-deleted checkout kept serving 0.3.45 on 7317 under a herdr list that names only devswha.ovis.
  2. Try again after that ran the deleted checkout (error: Module not found ...devswha.herdr-web-ui-210f619d6b7b\scripts\plugin.ts, shown as "Could not stop the Ovis server").
  3. With a token, no QR: GET /api/access was read without the token, answered 401, and the app told a PC that runs Tailscale to install it.
  4. The log showed raw CLIXML (#< CLIXML <Objs ...>).

Change

  • Old-id stop (install.ps1, Model.PluginCommand): the old id's plugin.ts (stop, status, phone) runs with HERDR_PLUGIN_STATE_DIR set to herdr's state dir for the plugin, found as scripts/plugin-state.ts finds it (XDG_STATE_HOME, else %LOCALAPPDATA%), and restored afterwards. A stop that finds no server there runs once more with the original environment, so a server started by hand from the old checkout (pid in its own dir) is still stopped. Every new-id release (0.4.14+) finds herdr's dir by itself and is run as before.
  • Try again after a failed Update reads the PC again: it updates again while one is due (or the plugin is gone), and for a current server it runs the update's last steps again: the login start, and the start when it is stopped.
  • Phone address with a token: the token that opened GET /api/updates (the PC's own, from the plugin's env/.env, as before) is sent to GET /api/access at the same origin. When that still answers 401 the app says the token is missing or did not work, instead of "install Tailscale".
  • Log: the installer starts with -Command instead of -EncodedCommand. In the VM, Windows PowerShell 5.1 started with -EncodedCommand and redirected output wrote progress, warning and error records to stderr as CLIXML whatever -OutputFormat and stdin were; -Command writes the plain lines. Run hands the script to cmd in an environment variable, so its | and quotes arrive as written.

Tests

  • scripts/windows-install.test.ps1: the old id's stop is told herdr's state dir (with and without XDG_STATE_HOME), the variable is not left set, and a stop that finds no server there asks again without it. Fails on main's install.ps1 ("The old id's stop must look for its pid where herdr keeps the plugin's state"), passes with this change (VM, desktop session).
  • app/windows/tests (Ovis.Tests.exe): the state dir, the phone step for a token the app could not use, and a real Windows PowerShell run with the app's arguments that must print host, warning and error lines without CLIXML. 20/20 pass in the VM; the PowerShell case fails with main's -EncodedCommand arguments.
  • bun run check fast: green.

Manual QA (winvm, Windows 11, herdr 0.9.3, Bun 1.4.2; Ovis.exe built at version 0.4.19)

Setup each time: winvm reset (dev-ready-4), herdr plugin install devswha/herdr-web-ui --ref v0.3.45, a HERDR_WEB_TOKEN and a marker line in its env, herdr server, then herdr alone ended (taskkill /IM herdr.exe /F): the 0.3.45 server keeps running.

main this change
Update "The installer stopped with an error", CLIXML in the log; afterwards the old server (same pid) still serves 0.3.45 on 7317, the old checkout is half-deleted, herdr lists only devswha.ovis Running on this PC: only devswha.ovis 0.4.19, /api/updates says current_version 0.4.19, no old process or checkout, env marker and token moved, Run value set
Phone step with a token "Install Tailscale on this PC..." with Get Tailscale "Tailscale runs here" → Make the phone address → QR code and https://winvm.example.ts.net
Failed Update, then Try again "Could not stop the Ovis server", Module not found ...devswha.herdr-web-ui-...\scripts\plugin.ts (a file in the old checkout held open, so the old id's uninstall fails with os error 32) the log shows herdr's error and herdr failed (exit 1) as plain lines; Try again reads the PC again and lands on Running on this PC (devswha.ovis 0.4.19), no Module not found
Screenshots

main: main: Update fails with CLIXML in the log main: Try again runs the deleted checkout main: with a token, install Tailscale

this change: fix: Update ends running 0.4.19 fix: QR with a token fix: a failed update shows plain log lines fix: Try again reads the PC again

Reviews

  • omo-native-code-reviewer: PASS, four LOWs, all fixed here (a stop that finds no server through herdr's dir asks again without it; the token-needed text also covers a token that did not work; [IO.Path]::Combine for an empty XDG_STATE_HOME; the PowerShell test waits with a bound).
  • Codex (gpt-6.1-sol, fast, xhigh), four rounds: round 1 BLOCK with two MEDIUMs (Try again skipped a start that failed after a successful reinstall; forcing the state dir hid an old server started by hand), round 2 BLOCK with one MEDIUM (Try again skipped the login start while the server already ran), all fixed; rounds 3 and 4 (the -Command switch) PASS with no findings.

Not in this PR (LOW, pre-existing)

  • When install.ps1 fails after installing the new id but before the old id's uninstall (as in the forced failure above), the old checkout's leftovers stay on disk; herdr no longer lists the old id and the app shows the new one running, so nothing breaks, but nothing removes them either.
  • check fast once failed scripts/self-hosted-runner.test.ts ("the stub never hung") under load; it passes alone on this branch and on main (30/30), and a rerun of the whole check was green.

…PC on Try again, show the QR with a token and a readable log (#2264)

- install.ps1 and the app run the old id's plugin.ts with herdr's state dir
  (HERDR_PLUGIN_STATE_DIR), where releases before 0.4.13 keep their pid; a stop
  that finds no server there asks again without it.
- Try again after a failed Update reads the PC again instead of the removed
  checkout, and finishes the update's last steps for a current server.
- GET /api/access gets the PC's own token that opened GET /api/updates; a token
  it cannot use is named instead of "install Tailscale".
- The installer runs with -Command, not -EncodedCommand, so Windows PowerShell
  writes plain lines instead of CLIXML.

Closes #2264
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between d75d738 and 5df2937.

Files selected for processing: 8
  • app/windows/README.md
  • app/windows/src/MainForm.cs
  • app/windows/src/Model.cs
  • app/windows/src/Setup.cs
  • app/windows/tests/SetupTests.cs
  • changelog.d/windows-app-update-outlived-server.md
  • install.ps1
  • scripts/windows-install.test.ps1
  • 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

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit hit its review limit on this PR ("Review limit reached"), so no CodeRabbit review ran. This PR sends a token to an HTTP endpoint and changes the installer path, so the code-review agents' reviews stand in. Their findings and how each was resolved, all on the head before 5df29370 unless named:

omo-native-code-reviewer (one round): VERDICT PASS, no CRITICAL/HIGH/MEDIUM. Four LOWs, all fixed in 5df29370:

  • Forcing HERDR_PLUGIN_STATE_DIR hides a 0.4.12/0.4.13 old-id server started by hand from the checkout (its pid is in ~/.local/state/...). Fixed: a stop that does not print stopped ... (pid N) runs once more with the original environment, in Model.PluginCommand and in install.ps1; windows-install.test.ps1 covers it.
  • The token-needed text said the token was not found, also when it was found but refused. Fixed: "did not find it, or it did not work".
  • Join-Path '' 'herdr' throws in Windows PowerShell 5.1 for an inherited empty XDG_STATE_HOME. Fixed: [IO.Path]::Combine.
  • The PowerShell test read stdout before its bounded wait. Fixed: both streams read asynchronously, then WaitForExit(60000) and a kill.
  • Security check by the reviewer: the token goes to GET /api/access only after GET /api/updates at the same origin (from the plugin's own status line) accepted it, a refused token is not sent again, and it is never logged.

Codex (gpt-6.1-sol, fast, xhigh), four rounds:

  • Round 1, BLOCK, two MEDIUMs: (1) Try again skipped a start that failed after a successful reinstall: UpdateAgain returned once the PC read as Installed. Fixed: an Installed server that is stopped is started as the update would have. (2) the hand-started old-id server above. Fixed as above.
  • Round 2, BLOCK, one MEDIUM: Try again skipped the login start when the server already ran (install.ps1 starts the moved server before the app adds the login start). Fixed: UpdateAgain runs LoginStart() for any Installed server, and restarts only a stopped one.
  • Round 3: PASS, no findings.
  • Round 4 (the switch from -EncodedCommand to -Command, after the VM showed -OutputFormat Text does not stop CLIXML): PASS, no findings; quoting through Run's environment-variable hand-off, installer scope, error handling, param binding and the inherited OVIS_REF checked.

Verification on 5df29370: winvm before/after QA (screenshots in the PR body), Ovis.Tests.exe 20/20 in the VM (its PowerShell case fails with main's arguments), windows-install.test.ps1 passes (fails on main's install.ps1), bun run check fast green. pr-check.ps1 -Pr 2275 is running in winvm; its result follows.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

pr-check.ps1 -Pr 2275 in the Windows 11 VM (fresh %TEMP% clone of head 5df29370, desktop session): PR-CHECK PASS.

STEP-PASS windows-install.test.ps1 (exit 0, 24s)
STEP-PASS preflight.ps1 (exit 0, 0s)
STEP-PASS bun install --frozen-lockfile (exit 0, 20s)
STEP-PASS bun run build (exit 0, 20s)
STEP-PASS bun test (windows set) (exit 0, 84s)
STEP-PASS playwright chromium (exit 0, 1s)
STEP-PASS windows-terminal-browser-qa.ts (exit 0, 27s)
PR-CHECK PASS

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

CI note: "Browser regression (other scripts)" was cancelled at its time limit in all three attempts of run 40704268690 (51-52 min each), with no failing script. Attempt 3 (runner herdr-ci-devswha-ThinkStation-P620-15): 105 scripts PASS, two failed once and passed on their retry (chat-virtual-browser-qa.ts, composer-fit-demo-regression.ts, both FLAKY), then "The operation was canceled" at 17:05Z with scripts still running. Attempts 1 and 2 were the same, on P620 runners while that PC was over its CPU cap. "Integration and browser" fails only because that job was cancelled.

This PR changes only app/windows, install.ps1, scripts/windows-install.test.ps1 and a changelog fragment: nothing a browser script runs. Fast checks, Native Windows install, Real Windows install, the Windows app build (Ovis.Tests and the old-server Update screen) and Integration tests pass. I am not rerunning it again; it should pass once the runners are less loaded.

devswha added a commit that referenced this pull request Oct 28, 2026
…r-fit timing out under load (#2287)

Closes #2285

## What was wrong

`Browser regression (other scripts)` kept ending as cancelled at its
50-minute `timeout-minutes`. It looked like hung demo scripts, but no
script hung. Each job waited a long time for a herdr check slot
(`scripts/check.ts`, `check: took a slot after Ns`) and then ran the
lane until the job timeout stopped it:

| job | PR | slot wait | lane before the cancel |
| --- | --- | --- | --- |
| 122862337418 | #2266 attempt 1 | 1340 s | finished, 107/108 in 1238 s
(a real `file-viewer-regression.ts:1395` failure) |
| 122889113275 | #2266 attempt 2 | 2110 s | 14 min, cancelled |
| 122878703515 | #2260 | 1755 s | 20 min, cancelled |
| 122872125320 | #2275 | 1635 s | 22 min, cancelled |

The scripts that "STARTed and never finished" were the ones running at
the cancel. Their logs in the browser-logs artifact print `PASS` lines
up to the cancel second. For example,
`sidebar-activity-demo-regression.log` ends with a PASS at 15:35:59, the
same second as `##[error]The operation was canceled.` The longest single
script run in these jobs was 357 s.

`ci.yml` gives these jobs `timeout-minutes: 50` and `CHECK_WAIT_SECONDS:
2400`, and time spent waiting for a slot counts against the timeout. On
2026-10-28 the P620 had 20 runners queuing for 4 slots
(`CHECK_HOST_MAX_RUNS=4`), and waits reached 37.6 min.

## What this PR changes

`scripts/ci-browser-parallel.ts` now limits each run of a script to
`BROWSER_SCRIPT_TIMEOUT_SECONDS` (default 600 s, about twice the slowest
run seen on a loaded host). Before this, a script that really hung, or a
process it started that kept its output open, would have used up the
whole job. Past the limit:
- the script's whole process tree (read from `ps` before anything is
signalled, so Chromium and servers it started are included) gets
SIGTERM, then SIGKILL after 5 s;
- the lane prints `TIMEOUT <script>` and the script's last 40 log lines
straight away;
- the script fails with exit 124 and is not run a second time;
- the summary, `summary.json`, the `::error` annotation and the job
summary all name it with `Timed out after Ns`.

It also fails a script that exits but leaves a process holding its
output open: if the output is still open 5 s after the exit, the run
fails with `Exited N, but a process it started still held its output`. A
run's processes carry a mark in their environment, so the stop finds
them through `/proc` on Linux even after they are moved to init.
Anything still alive after the SIGTERM grace gets SIGKILL, including a
child that ignores SIGTERM and writes nowhere. The script's own pid is
only signalled while the script is still running.

`scripts/composer-fit-demo-regression.ts:278` gave `setInputFiles` a 32
MiB + 1 byte buffer. Playwright sends a buffer to the page as base64
(about 45 MB), which on a loaded host ran past the 30 s timeout. That is
a real load failure inside this job: it failed twice in #2260's job and
twice in a row locally at load 80-110. It now passes a sparse file of
the same size by path. Chromium reads only its size, and the app still
refuses it by size (`src/lib/api.ts`) before reading.

`docs/development.md` documents the setting and says to check the slot
wait first when a job is cancelled at its timeout.

No workflow file is changed.

## Done outside this PR

- Host (Dori's call): the P620's runner count goes from 20 to 8 (2
reserved for main, 6 for PRs), with `CHECK_HOST_MAX_RUNS=4` kept. With 4
slots, at most 4 jobs can wait, so in the worst case a job waits one
slot round (about 20 min) and then runs the lane (about 21 min), within
50 min. Jobs beyond that now queue at GitHub, which does not count
toward `timeout-minutes`.
- Proposal for the owner, not applied: `timeout-minutes: 50` -> `75` for
Integration tests, Browser regression (ui-regression) and Browser
regression (other scripts), so the 40-minute `CHECK_WAIT_SECONDS` budget
and the lane both fit inside the job.

## Verification

- `bun test scripts/ci-browser-parallel.test.ts`: 4 pass. The two
deadline tests fail on the runner before this PR: the hung stub runs
into the test's 15 s spawn limit, and the exit-but-holding stub is never
caught.
- The real runner on a hung stub that leaves a child holding stdout,
with `BROWSER_SCRIPT_TIMEOUT_SECONDS=2`. Before this PR it still showed
only `START` when the outer bound killed it at 30 s, and the child was
left alive. With it, the run exits 1 after 2.4 s, with `TIMEOUT`, the
script's last lines and exit 124, and the child is gone.
- A child that ignores SIGTERM and writes nowhere. It survived the first
commit of this PR (Codex's HIGH) and is killed by the second.
- The six scripts named in the issue, run through the parallel runner
with 6 workers and `BROWSER_RETRY=0` under `dori heavy` on a host at
load 60-110:
- with the composer-fit fix: 6/6 in each of three runs (359 s, 334 s,
320 s);
- before it: 5/6 twice, both times composer-fit failing with
`setInputFiles` timing out at line 278.
The other five scripts passed every time. None hung, and none was
reported STOPPED with real Chromium.
- `bun run check fast` on 72d6486: typecheck, build, and unit tests
(8250 pass, 0 fail).
- Reviews:
- omo-native-code-reviewer: PASS, with one MEDIUM (a script that exits
but leaves a process holding its output) that is now fixed.
- Codex Sol 6.1 fast xhigh: first review BLOCK, on a HIGH (a child
ignoring SIGTERM survived), two MEDIUMs (re-parented children, stale
pids) and one LOW (zombies in the test). All were reproduced and fixed,
and the re-review is a PASS. Known limits it names: on Linux, orphans
are found through `/proc`, and a narrow pid-reuse race remains between
reading and signalling.
  - The composer-fit change (test only) had no separate reviewer.
@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Merging 5df2937 (closes #2264). Codex was at capacity, so an omo reviewer and an independent second reviewer on the Windows PC reviewed it. The old-id stop runs the old checkout's plugin.ts with HERDR_PLUGIN_STATE_DIR set to herdr's state dir for that plugin, passed as environment data, not interpolated into PowerShell, and restored in finally; the fallback runs at most once, only after a successful stop that stopped nothing. The old releases' stop still checks the process (Bun executable, that checkout's server/managed.ts, creation time against the pid file) before taskkill, so a stale pid file pointing at another process is left alone. Try again re-reads the plugin list first and prefers the new id, so it never runs the deleted checkout. The token stays in memory and in the Authorization header (never on a command line, URL, QR or log); a 401 from /api/access now says the access is locked instead of telling the PC to install Tailscale. The log uses plain -Command, with no output filtering. On the Windows 11 PC the second reviewer reproduced case 1 with the real 0.3.45 server in an isolated profile: the main-style stop said 'not running', this head's stop stopped it; a stale pid record pointing at an unrelated Bun process was refused and that process left alive; the token opened /api/access in a real Model.ReadStatus run and a wrong token set AccessLocked. windows-install.test.ps1, the app tests (20 pass) and both app builds passed there too. CI at this head: the Windows app tests (20 pass, incl. the state-dir and real PowerShell cases), the native installer regression with the new legacy-state case, and a real install of 0.4.19 with herdr 0.9.5 pass. Not filed: the readable-log test starts powershell.exe directly instead of through Run.Program (app/windows/tests/SetupTests.cs ~222-249); UpdateAgain's retry paths have no automated test (Model.cs ~181-194, covered by the PR's manual VM run).

@devswha
devswha merged commit f49c231 into main Oct 28, 2026
36 of 42 checks passed
@devswha
devswha deleted the fix/windows-app-update-old-server branch October 28, 2026 17:49
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.

Windows app: Update fails and loops for an old-id server that outlived herdr; Try again, QR with a token and the log are wrong too

1 participant