Skip to content

fix(plugin): keep one previous server.log and bound the failed-start tail - #1855

Merged
devswha merged 2 commits into
mainfrom
fix/plugin-startup-log-retention-v2
Oct 24, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/plugin-startup-log-retention-v2

Conversation

@devswha

@devswha devswha commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What it does for the user

  • Each plugin start keeps the run before it as server.log.1 and starts a fresh server.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.
  • A failed start reads at most the last 64 KiB (that budget includes the one byte that shows whether the read starts a line) of what its own server wrote to show its last 15 lines, instead of reading the whole accumulated log into memory (a 3 GiB log used to take ~3 GB of RSS). The read goes through the start's own file handle, so a log another start moved meanwhile is still this run's, and the start: failure line is written through the same handle.
  • Scope: this bound covers what scripts/plugin.ts prints. On Windows, scripts/plugin.ps1 (unchanged here, and older than this PR) still shows the last 15 lines of the current server.log with Get-Content -Tail 15 after 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 of scripts/plugin.ts plus 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 into server.log.1, which is harmless.

How it was verified

  • New cases in 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 fast passes (typecheck, build, unit tests: 454 files).
  • Reviewed by the omo code-review agent (approve, no HIGH; its MEDIUM about a test that could not fail and its LOW notes were fixed) and by Codex (one LOW, the failure line written by path, fixed).

No HTTP/WS contract, auth or workflow change.

…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.
@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 1 minute.

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 9f6e27b.

Files selected for processing: 3
  • changelog.d/plugin-startup-log-retention.md
  • scripts/plugin.test.ts
  • scripts/plugin.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

Merge pass review-work for 66f000c: REVIEW FAILED on the failed-start tail contract. Both points are small.

  1. Windows still rereads the log on its own (scripts/plugin.ps1:25-32). The Windows wrapper waits for the hidden Bun launcher, then runs Get-Content -Tail 15 on the current server.log. So on Windows:

    • the tail the user sees doesn't come from the new bounded, run-owned reader;
    • a single 100,000-byte line is read whole;
    • a rotation between the child's exit and that read can show another run's log.

    This wrapper behaviour predates the PR. Please either route the launcher's bounded tail through the wrapper, or narrow the description and changelog so the 64 KiB and run-owned promises cover the launcher's own output only.

  2. The reader takes 64 KiB + 1 byte (scripts/plugin.ts:276-278). For a 100,000-byte line with no newline, the compiled function requested and returned 65,537 bytes, because the look-behind byte sits outside the budget. Please count that byte inside LOG_TAIL_BYTES, or say "about 64 KiB".

Checked and passing:

  • Tests: 38 plugin and conventions tests pass, and the typecheck passes. A mutant of the line count, 15 changed to 14, is caught.
  • Rotation: server.log rotates to server.log.1 and keeps exactly one previous run. A live recorded server makes the start append, and recordedPid() checks liveness, so a dead pid rotates.
  • Tail edge cases: an empty log, a log of exactly 64 KiB, offset exclusion and the last 15 lines all behave correctly.
  • Failed rename: when the rename fails, the start says so on stdout and in the log, then appends.
  • Native Windows CI: 14 tests pass, covering start, stop and restart. They don't exercise a failed start.

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.
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Addressed both points in 9f6e27b:

  1. Windows wrapper tail: took the narrowing option. The changelog now says the 64 KiB bound covers the plugin's own output and that on Windows the plugin.ps1 wrapper still shows the last 15 lines of server.log itself; the PR description has a Scope bullet saying the same (including the long-line and rotation caveats). plugin.ps1 is unchanged, to keep this PR's scope.
  2. 64 KiB + 1 byte: the look-behind byte now counts inside LOG_TAIL_BYTES (from = max(offset, size - LOG_TAIL_BYTES)). The long-line test now expects exactly 65,536 bytes back ("x".repeat(64 * 1024 - 4) + "end" from a 100,000-byte line).

bun run check fast passes (unit: 454 files, 0 fail).

devswha added a commit that referenced this pull request Oct 24, 2026
…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>
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED.

Lane Verdict Confidence
Manual QA (rows 1-4, MP-r2; artifacts kept) PASS at 9f6e27b -
Gate round 1 (66f000c) REJECT: the Windows wrapper rereads server.log; the reader took 64 KiB + 1 byte HIGH
Gate round 2 (9f6e27b) APPROVE HIGH

Checked

  • Tests: 38 plugin and conventions tests pass, and the typecheck passes. A mutant that changes the line count from 15 to 14 is caught.
  • Rotation: each run's log rotates to server.log.1, which keeps exactly one previous run. A live recorded server makes the start append instead. recordedPid() checks liveness, so a dead pid still rotates. A refused rename is reported and the start appends.
  • Tail edge cases: an empty log, a log of exactly 64 KiB, offset exclusion and the last 15 lines all work.
  • Round 1 fixes:
    • The tail read now stays inside 64 KiB, the look-behind byte included. For a 100,000-byte line with no newline, the compiled function requests and returns exactly 65,536 bytes, and the old off-by-one fails the boundary check.
    • The PR body and changelog now scope the bound to what scripts/plugin.ts prints. On Windows, scripts/plugin.ps1, which this PR doesn't change, still runs its own Get-Content -Tail 15.
  • Native Windows CI: 14 tests pass, covering start, stop and restart.

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.

@devswha
devswha merged commit 21482e7 into main Oct 24, 2026
10 checks passed
@devswha
devswha deleted the fix/plugin-startup-log-retention-v2 branch October 24, 2026 19:01
devswha added a commit that referenced this pull request Oct 28, 2026
…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.
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