Repository navigation
fix(plugin): keep one previous server.log and bound the failed-start tail - #1855
Conversation
…tail Every plugin start appended to one server.log forever, and a failed start read the whole file into memory to show its last 15 lines (a 3 GiB log took 3 GB of RSS). - start moves server.log over server.log.1 before opening the log, unless the recorded server is still alive (then it appends as before); a move that fails is reported and the start appends. - a failed start reads at most the last 64 KiB its own server wrote, through the start's own handle, dropping a line the read cut, and writes its start: line through that handle too. - tests in scripts/plugin.test.ts; changelog fragment. Rebuilt small from origin/main in place of fix/plugin-startup-log-retention.
|
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 1 minute. 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 |
|
Merge pass review-work for 66f000c: REVIEW FAILED on the failed-start tail contract. Both points are small.
Checked and passing:
|
The byte that shows whether a cut read starts a line now counts inside LOG_TAIL_BYTES, so the reader never takes more than 64 KiB. The changelog says the bound covers the plugin's own output: on Windows the plugin.ps1 wrapper still prints the last 15 lines of server.log itself.
|
Addressed both points in 9f6e27b:
|
…d never signal pid 0 (#1864) ## What failed `bun run check fast`'s unit step sometimes ended right after `server/skills/omo.test.ts` with **no failure reported**: the check report says the step was terminated by `SIGKILL` (3 of 5 runs on one lane, #1855's worktree), the log stops mid-run with no summary. ## Root cause The file queued next, `server/shell-agent.test.ts` ("answers a shell SIGKILL does not end within the bound"), kills the probe shell's pid in a `finally`. That pid stays `0` when the shell's pid file never appears: its `fs.watch` can fail on a PC near its inotify limit (this one: 119 of 128 instances in use), or the 5 s bound can run out under load. `process.kill(0, "SIGKILL")` ends the caller's **whole process group**, and `scripts/ci-tests.ts` ran every test file in the one group that `scripts/check.ts` starts the step in: every file in flight, the runner and the step died at once, with nothing printed. ## Fix - `scripts/ci-tests.ts` starts each unit test file in a process group of its own. A file that signals its own group now fails by that signal and is named (`FAILED` / `NO RESULT`), and the run goes on. What a file leaves running in its group is ended when it exits (as check.ts's step cleanup did before). - Since the files' groups no longer get an interrupt sent to the step's group, the runner passes SIGINT/SIGTERM/SIGHUP on to every file still running, stops starting new ones, and kills what is left of their groups once the files ended or after 5 s, then exits 130/143/129. Windows (no process groups) keeps the old spawn. - `shell-agent.test.ts`, `check.test.ts` and `updater.test.ts` no longer signal a pid or group that a missing or half-written pid file left at 0. ## Proof - **Deliberate reproduction** with a scratch test file calling `process.kill(0, "SIGKILL")`, full unit suite: main's runner dies (wrapper `Killed`) after 448 of 455 files with no summary — the reported signature. This branch reports all 455, names the file as `FAILED` and `NO RESULT` (`exit 137`, "ended by SIGKILL"), and exits 1. - `shell-agent.test.ts`: 32 runs, 8 at a time: 0 failures. `check.test.ts`: 54 pass. - Interrupts: SIGINT to the runner while 8 files ran: exit 130, 0 test processes left. SIGTERM with a test child that ignores TERM and INT: exit 143 in 1.2 s, the child gone. - `bun run check fast`: passed (6386 pass, 0 fail). Two earlier runs on this branch failed only in `server/omp-process.test.ts` and `server/rpc-diagnostics.test.ts`, flakes fixed separately (#1862 and a follow-up PR). - Reviews: omo-native-code-reviewer (approve; its should-fix — no SIGKILL after forwarding an interrupt — is implemented as suggested) and Codex (`codex review`, one P2, the same point, fixed). Part of the flaky-tests lane (`check fast` reliability). Co-authored-by: mp <mp@local>
|
Merge pass review-work report. Overall: PASSED.
Checked
Accepted limitation: on Windows, the wrapper's tail can still read a long line whole and goes by pathname. That behaviour predates this PR and is now stated. 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. |
…server that still runs (#1611) (#2166) Closes #1611. ## What it does for the user Two plugin starts at the same moment, such as herdr's startup hook and the Start action, no longer open two servers and leave `stop` saying "Ovis is not running" while one keeps going. - **Starts and stops take turns** through `lifecycle.lock` in the dir herdr hands the plugin (the owner lock of `server/owner-guard.ts`, taken over at once when its owner is proved gone). A start holds it from deciding whether a server runs until its own answers or the start fails; a stop holds it until the server is gone. One that waits says so in the plugin's log and gives up after 60 s. - **A start opens no second server while the recorded one still runs.** It keeps the server's birth in `server.owner` beside `server.pid`. Inside its turn it refuses when that very process still runs, even if it does not answer and its port looks free (with herdr away, the supervisor's bridge lets go of the port for a moment). A missing, mismatched or unreadable birth, a reused pid, or an exited-but-unreaped server fall back to main's behaviour: start a server. - A state dir the plugin cannot write fails at once instead of being waited on as if another start held it. - `docs/development.md` describes the lock and the existing startup-log policy (one `server.log.1`, the 15 lines and 64 KiB a failed start reads, which bounds that read, not a live log's size). #1855 already shipped the rotation and the bounded tail; this is the remaining part of #1611 (the lifecycle claim, and the recheck of the running server inside it). ## How it was verified Each new regression test fails on the code before its fix and passes after: | Test (`scripts/plugin.test.ts`) | Before | After | | --- | --- | --- | | two starts at the same moment open one server, whose record `stop` finds (stand-in servers gated over a unix socket, no sleeps) | main: 2 servers | 1 | | a server an earlier start left running is left alone when it does not answer and its port is free | main: spawned over it | refused | | a state dir that cannot be written fails at once | efcff1c: waited (timed out) | exit 1 at once | | an exited, unreaped recorded server does not block a start | efcff1c: refused | starts | | the lock stays in the dir herdr hands while the record is under the old id's | efcff1c: lock in old dir | new dir | | a live server whose birth could not be read is not replaced (CodeRabbit) | 94fe6ab: spawned over it | refused | | a waiting `stop` does not block on the lock's file guard another process holds | 8ee148f: blocked silently | says it waits | | a start that waited follows the port the start before it moved to | 8ee148f: failed at the old port | already running there | | a server whose record cannot be written is stopped, not left unrecorded | 8ee148f: left running | stopped | | `stop` does not signal a process that took the recorded server's pid | 8ee148f: signalled it | left alone | | an exited, unreaped lock owner is proved gone (`server/process-owner.test.ts`) | 8ee148f: kept the lock | gone | | a live server whose birth matches stays ours after the wall clock steps forward past its record | 7a2f97f: taken for replaced | kept, and `stop` stops it | Real surface, with the real `server/managed.ts`, an isolated HOME, state and config dir, a free port and herdr unreachable: - **Two concurrent `bun scripts/plugin.ts start`.** On main, run 4 of 5 left `server.pid` naming a dead pid and the live server running after `stop`. On the fix, the second start waits its turn, refuses ("still running but does not answer"), and `stop` stops the one server. - This run is what caught that the lock alone was not enough: the waiting start found the port free and spawned again. That led to the birth check. - **A lock whose owner was SIGKILLed** does not block the next start. - **Codex's old-id sequence replayed:** efcff1c spawned 2 servers, the fix 1. The suites (`scripts/plugin.test.ts`, `scripts/windows-plugin-stop.test.ts`, `server/owner-guard.test.ts`, `server/process-owner.test.ts`) and `bun run check fast` pass on the head (8d886ec). The three real-surface runs above (two concurrent starts, a SIGKILLed lock owner, Codex's old-id sequence) passed again on 7a2f97f, and the two-concurrent-starts run on 8d886ec. ## Reviews - **omo-native-code-reviewer (efcff1c): APPROVE.** It raised one MEDIUM (an unwritable state dir was waited on for 60 s), fixed in 94fe6ab. - **Codex Sol 6.1 Fast xhigh (efcff1c): CHANGES, 2 MEDIUM, both reproduced and fixed in 94fe6ab.** - A zombie server blocked starts. - The lock followed the record into the old id's dir, so two starts could take different locks. - **CodeRabbit (94fe6ab): 1 Major, fixed in 8ee148f.** A server whose birth could not be read at spawn was taken for gone. The record now says the birth is unknown, and only a restart since the record, another birth under the pid, or a later start time lets a start replace it. - **Merge pass, Codex (94fe6ab): 4 introduced MEDIUM + 1 pre-existing, all fixed in the last commit.** - A start that waited kept the port it read before its turn; it now reads the saved port again inside its turn. - A failed `server.owner` write left the spawned server running unrecorded; records are written whole, and a start that cannot record its server stops it and confirms it exited. - The lock's native guard (flock / LockFileEx) could block past the 60 s deadline. `server/owner-guard.ts` gains an opt-in attempt that does not wait (`LOCK_NB` / `LOCKFILE_FAIL_IMMEDIATELY`), used only by the plugin's lock; the supervisor and the remote bridge keep blocking as before. - A lock owner killed but not yet reaped (a zombie) kept the lock. `ownerGone` now counts a Linux zombie as gone, which is right for the supervisor's lock too. - Pre-existing on main: POSIX `stop` ignored the identity and could signal a reused pid. Now that the birth is recorded, `stop` leaves alone a pid the record proves another process holds, and rechecks before SIGKILL. A pid-only record from an older version is signalled as before, so an upgrade still stops its server. - **Merge pass, round 2 (7a2f97f): 1 MEDIUM, fixed in 8d886ec.** The "record from before this boot" check ran before the birth comparison, so a forward clock step made a live server with a matching birth count as replaced. A recorded birth now decides alone; the boot check is kept for records without a birth. - **Codex Sol, final round on the delta (94fe6ab):** APPROVE, no findings (eight probes: guard failure, zombie replacement, old-id dir during lock waits, `status`, the early `stop`, the exported Windows `stop`). ## Known limits (LOW, not fixed here) - **Ovis for Mac** kills `stop`/`start` after 60 s. A stop that waits for a start in progress and then stops the server can pass that, and Restart would then say it could not stop. - **Polling cost while waiting:** each 250 ms check reads the lock holder's birth. On Windows that is a PowerShell query, which adds up while a start waits. - **Waiters are not served in order.** Start, stop and start close together can leave the last one at its 60 s limit. - **Old and new id installs at once:** a plugin still installed under the old id and one under the new id lock in their own dirs. The installer stops the old one before moving it, as before. - **`scripts/plugin.ps1`** still shows the log's last 15 lines itself after a failed start on Windows (unchanged, as in #1855). No HTTP/WS contract, auth or workflow change. `server/owner-guard.ts` and `server/process-owner.ts` are remote-bundle inputs; per docs/development.md the release PR raises `REMOTE_BUNDLE_VERSION`, so this PR does not.
What it does for the user
server.log.1and starts a freshserver.log, instead of appending every run to one file that grows forever. While the recorded server is still running, the start appends to its log as before; if the log cannot be moved (Windows, a program holding it open), the start says so on stdout and in the log, and appends.start:failure line is written through the same handle.scripts/plugin.tsprints. On Windows,scripts/plugin.ps1(unchanged here, and older than this PR) still shows the last 15 lines of the currentserver.logwithGet-Content -Tail 15after a failed start, so a very long line is read whole there and a rotation in between could show another run's lines. The changelog says so.Why
This replaces the local-only branch
fix/plugin-startup-log-retention(8 commits, ~1.6k lines, process-group / Windows process-tree proofs and a lifecycle claim file). That branch was judged worth shipping but over-engineered; this is the same user-facing change rebuilt from current main in ~100 lines ofscripts/plugin.tsplus tests. It deliberately trusts the recorded server pid instead of proving every possible writer gone: a leftover process that still writes the old log keeps writing intoserver.log.1, which is harmless.How it was verified
scripts/plugin.test.ts(server.log): rotation keeps exactly one previous run; a live recorded server makes start append; a 100 KB line followed by two lines shows exactly those two (the cut line is dropped); a single line too long to read whole still shows its end; the last 15 lines are shown.bun run check fastpasses (typecheck, build, unit tests: 454 files).No HTTP/WS contract, auth or workflow change.