Repository navigation
fix(plugin): wait only for the stopped Windows tree, and only on the process table while it runs - #1863
Conversation
…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
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
|
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) |
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
|
Merge pass review-work report. Overall: PASSED.
What was checked
Follow-ups (MINOR)
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. |
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
…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>
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 secondstop(after the stale-lock restart) printedcould not confirm Ovis stopped; its pid file was keptafter waiting out its 10 s.Causes
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 /tdoes 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.isAlivefirst 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
scripts/windows-plugin-stop.test.tsruns the real stop path with a handed-in table that holds such a stray. On main it fails after ~10 s withcould 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 becauseplugin.tsreads its state directory once on import (and Windows runs test files in one process).shell-agent.test.tspins 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).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:Startedcomes from localCreationDate, so a clock stepped back (or the repeated DST hour) could make a real child look older than its parent.