Skip to content

fix(plugin): wait only for the stopped Windows tree, and only on the process table while it runs - #1863

Merged
devswha merged 1 commit into
mainfrom
fix/windows-stop-tree
Oct 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/windows-stop-tree

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Fixes #1833.

What failed

The Native Windows install job failed once (run 40088346948, attempt 1) in scripts/windows-plugin.test.ts › "starts after its launcher exits, stops its owned tree and restarts on Windows": the second stop (after the stale-lock restart) printed could not confirm Ovis stopped; its pid file was kept after waiting out its 10 s.

Causes

  1. A process that is not the server's was waited for. stop() snapshots the server's tree by walking parent numbers in the process table (descendantProcesses). Windows keeps a process's parent number after that parent exits, and hands the number to the next process. An unrelated process left over from an earlier holder of the server's number (or of one of its children's) is taken for a member; taskkill /t does not end it, so stop waits for it until the deadline and fails with exactly Flaky: Windows plugin stop/restart test can time out confirming Ovis stopped #1833's message. The walk now skips a row that started before the process now holding its parent's number (only when both starts are known; equal starts are kept), and everything below it.
  2. Each wait round ran the PowerShell table query before checking liveness. One slow query on a busy runner could spend the deadline after the tree was already gone. The loop now asks isAlive first and queries the table only while a member's number is still taken (to tell a reused number from a member that still runs).

Proof

  • New scripts/windows-plugin-stop.test.ts runs the real stop path with a handed-in table that holds such a stray. On main it fails after ~10 s with could not confirm Ovis stopped; its pid file was kept; it also requires no table query once the tree is gone. The reviewer checked each change alone: the walk fix alone fails the query count, the loop fix alone fails the stop result. It runs in a process of its own because plugin.ts reads its state directory once on import (and Windows runs test files in one process).
  • shell-agent.test.ts pins the walk: a stray with an older start and its subtree are left out, rows without a start are kept.
  • bun run check fast: passed (6387 pass, 0 fail).
  • Reviews: omo-native-code-reviewer (approve, no blockers), Codex (codex review: no findings).

Not verified

The maintainer's Windows PC (home-window) has been offline (Tailscale: last seen 14 h ago), so this was not reproduced on real Windows; the Native Windows install job of this PR is the real-Windows run. Noted by review, not changed here: Started comes from local CreationDate, so a clock stepped back (or the repeated DST hour) could make a real child look older than its parent.

…process table while it runs

The Native Windows install job failed once (#1833) with "could not confirm Ovis stopped;
its pid file was kept" after the stop path waited out its 10 s.

stop() snapshots the server's tree by walking parent numbers in the process table. Windows
keeps a process's parent number after that parent exits and hands the number on, so an
unrelated process left over from an earlier holder of the server's number (or of one of its
children's) was taken for a member. taskkill does not end it, and stop waited for it until
its deadline. The walk now skips a row that started before the process holding its parent's
number (when both starts are known), and everything below it.

Each wait round also ran the PowerShell process-table query before asking whether any
member was still alive, so one slow query on a busy runner could spend the deadline after
the tree was already gone. It now asks the table only while a member's number is still
taken, to tell a reused number from a member that still runs.

scripts/windows-plugin-stop.test.ts runs the stop path with a handed-in table holding such
a stray: on main it fails after 10 s with the #1833 message, and it also requires no table
query once the tree is gone. It runs in a process of its own, since plugin.ts reads its
state directory once on import.

Fixes #1833
@coderabbitai

coderabbitai Bot commented Oct 24, 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 33 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 8fe7da9 and e07e3c1.

Files selected for processing: 4
  • scripts/plugin.ts
  • scripts/windows-plugin-stop.test.ts
  • server/shell-agent.test.ts
  • server/windows-processes.ts
  • 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 24, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit's review was rate-limited ("Review limit reached"), so no CodeRabbit review ran on this PR. The reviews below stand in for it.

omo-native-code-reviewer: APPROVE, no blockers. It checked each change alone in a scratch copy: the walk fix alone fails the table-query count, the loop fix alone fails the stop result after ~10 s, main fails with the #1833 message. Low notes, not changed here: (L1) Started is local CreationDate, so a clock stepped back or the repeated DST hour could make a real child look older than its parent; (L2) without a real-Windows reproduction the root cause is inferred — if a process survives taskkill instead, stop still fails loudly; (L3) informational.
Codex (codex review): no actionable regressions.

devswha pushed a commit that referenced this pull request Oct 24, 2026
A herdr-backed check waiting for a slot could wait out all of CHECK_WAIT_SECONDS and be
refused while newer runs got slots ahead of it: #1863's "Browser regression (other scripts)"
waited the full 2400 s for one of the P620's 3 slots and exited 1 with no test failing.
acquireWaiting asked acquire again every 2 s, and acquire gave a free slot to whichever run
reached the admission port first.

A run refused as busy now takes a ticket, its place in the queue: a port above the admission
port (QUEUE_TICKETS of them) that answers when the run first found the PC busy. Under the
admission port, acquire refuses a run that wants a slot while a run with an older ticket waits;
a run without a ticket comes after every ticket. A ticket is a listening port, so a run that
dies leaves no place behind, and the runner containers of a host already share that loopback for
the slots. The ticket goes when the run is admitted, refused for good or out of time; a run that
finds every ticket taken waits without one and tries again each round. Older checks ignore
tickets; nothing breaks while both run. MAX_LOCK_PORT drops by QUEUE_TICKETS. A waiting run
(acquireWaiting's retries, with a ticket or without one when all were held) with an older run
ahead of it is refused before it takes the admission port, and asked again under it (a run's
first try meets its checkout and resource claims first, so a second run in its checkout is
still refused as such at once): one that held the port only to find the queue would keep the head out of it, round
after round (a livelock found in review).

acquireWaiting takes the clock and the wait between rounds as seams, so the tests drive every
round: a freed slot goes to the run that waited, not to one that arrives after it; two waiters
are served in the order they first found the PC busy, whichever asks first; the place goes when
the run stops waiting; a run still waits when every ticket is held; a run behind the head
never takes the admission port. The earlier waiter holds the higher ticket port, so only the
time can order them. Ordering by port only, dropping the check before the admission port,
making it apply to every run, or the queue itself each fail a named assertion. The tests' free port ranges now cover the ticket ports, so a
waiting run elsewhere on the loopback cannot come ahead of a test's run. A refusal by queued
runs says so instead of blaming the run limit.

The check CLI tests' throwaway runs now use a lock range of their own: on the shared one they
waited in line behind every real run waiting for a slot (with a stand-in run waiting on a private
lock base, the old fixture fails after 90 s as in this PR's first CI run; the new one passes in
0.7 s).

Fixes #1881
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED.

Lane Verdict Confidence
QA (code-review agent's matrix; artifacts kept) PASS -
Code review (omo-native-code-reviewer, programming + remove-ai-slops) PASS (WATCH) -
Gate review (another model) No code blocker. Its only hold was required CI still queued; the merge pass merges only once every required check is green HIGH

What was checked

  • Tests: 42 tests pass, and the typecheck passes. Native Windows CI passed at this head, including the existing restart and identity-safety tests.
  • Mutants: removing the start-time skip fails both new tests, with stop returning 1 after about 10.8 s. Removing the isAlive-first exit fails the stop test.
  • The tree walk: it skips a row only when both start times are known and the row's is strictly earlier than the process now holding its parent's number. Equal and unknown start times are kept, and the gate checked those cases directly. A reused parent's subtree is excluded.
  • Liveness: isAlive-first decides the same way as before and drops a table query.
  • Other platforms and the pid file: Linux and macOS are unchanged. The pid file is still kept unless stop is proven.
  • Overlap: git merge-tree is clean with fix(plugin): keep one previous server.log and bound the failed-start tail #1855, which also edits scripts/plugin.ts.

Follow-ups (MINOR)

  • No test pins equal start times. A <= mutant at server/windows-processes.ts:37 passes the suite, and Windows start times often step in 15.6 ms.
  • scripts/windows-plugin-stop.test.ts isn't in the Native Windows job's fixed list (ci.yml:108), so it runs only on Linux, with faked Windows parts.

All required checks are green and no review thread is open.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit 9a9daed into main Oct 24, 2026
23 of 25 checks passed
@devswha
devswha deleted the fix/windows-stop-tree branch October 24, 2026 15:47
devswha pushed a commit that referenced this pull request Oct 24, 2026
A herdr-backed check waiting for a slot could wait out all of CHECK_WAIT_SECONDS and be
refused while newer runs got slots ahead of it: #1863's "Browser regression (other scripts)"
waited the full 2400 s for one of the P620's 3 slots and exited 1 with no test failing.
acquireWaiting asked acquire again every 2 s, and acquire gave a free slot to whichever run
reached the admission port first.

A run refused as busy now takes a ticket, its place in the queue: a port above the admission
port (QUEUE_TICKETS of them) that answers when the run first found the PC busy. Under the
admission port, acquire refuses a run that wants a slot while a run with an older ticket waits;
a run without a ticket comes after every ticket. A ticket is a listening port, so a run that
dies leaves no place behind, and the runner containers of a host already share that loopback for
the slots. The ticket goes when the run is admitted, refused for good or out of time; a run that
finds every ticket taken waits without one and tries again each round. Older checks ignore
tickets; nothing breaks while both run. MAX_LOCK_PORT drops by QUEUE_TICKETS. A waiting run
(acquireWaiting's retries, with a ticket or without one when all were held) with an older run
ahead of it is refused before it takes the admission port, and asked again under it (a run's
first try meets its checkout and resource claims first, so a second run in its checkout is
still refused as such at once): one that held the port only to find the queue would keep the head out of it, round
after round (a livelock found in review).

acquireWaiting takes the clock and the wait between rounds as seams, so the tests drive every
round: a freed slot goes to the run that waited, not to one that arrives after it; two waiters
are served in the order they first found the PC busy, whichever asks first; the place goes when
the run stops waiting; a run still waits when every ticket is held; a run behind the head
never takes the admission port. The earlier waiter holds the higher ticket port, so only the
time can order them. Ordering by port only, dropping the check before the admission port,
making it apply to every run, or the queue itself each fail a named assertion. The tests' free port ranges now cover the ticket ports, so a
waiting run elsewhere on the loopback cannot come ahead of a test's run. A refusal by queued
runs says so instead of blaming the run limit.

Merge-pass review fixes: a ticket lookup has an absolute 1.5 s deadline and drops a listener that
does not answer like a ticket (one that kept talking held the admission port indefinitely); a
waiting run reads its checkout and resource markers before the queue order, so a same-checkout or
resource conflict is refused at once; a new ticket ranks after every live ticket whatever the clock
says (a clock stepped back reversed the order), and tickets are taken one run at a time on a ticket
desk port above the admission port, so two runs taking places at once cannot miss each other; a run that finds the desk taken waits
for it (up to 3 s) instead of a whole round, in which a later run could take a place first.

The check CLI tests' throwaway runs now use a lock range of their own: on the shared one they
waited in line behind every real run waiting for a slot (with a stand-in run waiting on a private
lock base, the old fixture fails after 90 s as in this PR's first CI run; the new one passes in
0.7 s).

Fixes #1881
devswha added a commit that referenced this pull request Oct 24, 2026
…1886)

Fixes #1881.

## What failed

A herdr-backed `bun run check` waiting for a slot could wait out all of
`CHECK_WAIT_SECONDS` and be refused while newer runs got slots ahead of
it. #1863's "Browser regression (other scripts)" (run 40096402408)
waited the full 2400 s for one of the P620's 3 slots, held in turn by
runners 2, 6, 7, 8 and 12, and exited 1 with no test failing.

## Root cause

`acquireWaiting` asked `acquire` again every 2 s, and `acquire` gave a
free slot to whichever run reached the admission port first, whether it
had waited 40 minutes or arrived a moment ago. Nothing recorded who had
been waiting, so under steady load a waiting run could lose every round.

## Fix: a first-come-first-served queue on the shared loopback

- A run refused as busy takes a **ticket**: a port above the admission
port (`QUEUE_TICKETS` = 24 of them) that answers when the run first
found the PC busy. A ticket is a listening port, so a run that dies
leaves no place behind, and the runner containers of a host already
share that loopback for their slots (confirmed with lane ci-p620-max:
one loopback network per host, one queue per host).
- `acquire` refuses a run that wants a slot while a run with an older
ticket waits; a run with no ticket comes after every ticket.
- A **waiting** run (`acquireWaiting`'s retries) with an older run ahead
of it is refused **before** it takes the admission port, and asked again
under it. One that held the port only to find the queue could keep the
head out of it round after round (a livelock Codex found in review, also
for waiters left without a ticket when all 24 are held). A run's
**first** try meets its checkout and resource claims first, so a second
run in the same checkout is still refused as `same-checkout` at once.
- The ticket goes when the run is admitted, refused for good or out of
time. Older checks ignore tickets; nothing breaks while both run.
`MAX_LOCK_PORT` drops by `QUEUE_TICKETS`. Messages say when queued runs,
not the run limit, caused a refusal.
- Known limit: runs asking for different slot counts (only while a host
changes `CHECK_HOST_MAX_RUNS`) still queue in one line, so a head that
does not fit yet holds back a later run that would.

## Proof (deterministic, no sleeps)

`acquireWaiting` takes the clock and the wait between rounds as seams;
each test drives every round explicitly:
- a freed slot goes to the run that waited, not to one that arrives
after it;
- two waiters are served in the order they first found the PC busy,
whichever asks first (the earlier one holds the higher ticket port, and
a probe between them is told only the earlier one is ahead);
- a run behind the head never takes the admission port, with or without
a ticket;
- a second run in the same checkout is refused `same-checkout` at once
while runs wait;
- a run gives its place up when it stops waiting, and still waits when
every ticket is held.

Mutations, each failing a named assertion: order by port only; the early
check dropped; the early check for every run; `retry` ignored; the queue
disabled. The slots tests: 32 runs, 4 at a time, 0 failures. The
existing "stops waiting at its deadline" test now runs on the seams
instead of a real 60 ms, and the tests' free port ranges cover the
ticket ports.

## Reviews

- omo-native-code-reviewer: APPROVE (three rounds; its findings — test
port ranges, ordering by time not port, same-checkout refusals hidden
behind the queue, messages — are fixed).
- Codex (Sol 6.1, `codex exec`, four rounds): the livelock (P2) and the
overflow-waiter starvation (P2) are fixed; final round: no findings.

`bun run check fast`: passed (6398 pass, 0 fail). CI behaviour change in
`scripts/check.ts`: a real review is needed.

---------

Co-authored-by: mp <mp@local>
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.

Flaky: Windows plugin stop/restart test can time out confirming Ovis stopped

1 participant