Skip to content

fix(tests): read omp-process test targets only once they are up - #1862

Merged
devswha merged 2 commits into
mainfrom
fix/omp-process-test-started-target
Oct 24, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/omp-process-test-started-target

Conversation

@devswha

@devswha devswha commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What

server/omp-process.test.ts failed now and then in bun run check fast's unit step: the probe answered null about 16 ms after the target was spawned (keeps a process's empty arguments where they stand: received undefined). Seen in the check logs of three lanes (feat-branch-review-base, chore-ci-p620-max, chore-pin-action-commits).

Why

The tests probed a bun target right after Bun.spawn returned. A fresh bun spends its first milliseconds paging in its ~90 MB binary in uninterruptible sleep, and the probe's helper answers null for a process in state D by design (that is what keeps a WSL read blocked in the kernel out of the bridge, server/omp-process.ts). So the test raced the target's own startup.

Measured on this PC under lane load:

  • state of a fresh bun target 5 / 10 / 20 ms after spawn: D in 17 / 36 / 16 of 1600 samples;
  • with the target's binary evicted from the page cache before each spawn (posix_fadvise(DONTNEED) on a copy of bun): 34 of 40 immediate reads wrong;
  • a bun target that printed READY first was still wrong in 24 of 40: it keeps faulting pages in after it prints.

Fix (test only)

  • The targets are a small shell (/bin/sh -c 'echo READY; read _' sh <args>) that says when it is up and then waits in a read (state S); each test reads it only after READY. With both sh and bun evicted: 0 of 40 wrong.
  • Reads that are not about the probe's deadline get 30 s instead of the 1 s default, which the bun helper can miss on a loaded PC. The deadline test itself is unchanged.

The production probe is unchanged.

Verification

  • 200 runs of the file, 8 at a time, beside a full unit run: 0 failures.
  • bun run check fast: passed (6386 pass, 0 fail).
  • Reviewed by omo-native-code-reviewer (approve, no blockers) and Codex (codex review: no findings).

Part of the flaky-tests lane (check fast reliability).

Second commit: the same flake in server/codex-daemon.test.ts

"returns null when a live process's CODEX_HOME is its deleted cwd" failed in check fast with the home fallback (/home/devswha/.codex) instead of null: it read /proc/<pid>/environ of a sleep child spawned a moment before, and until its exec a child still shows the parent's environment (1030 of 1600 reads right after spawn lacked the CODEX_HOME it was given). The child is now /bin/sh -c 'echo READY; read _', read after READY with no exec after it; a control asserts its environ holds CODEX_HOME=. after the cwd is removed, and skipping the removal now fails the test. 200 runs, 8 at a time: 0 failures. Reviewed by omo-native-code-reviewer (its blocker on an earlier version — an exec after READY could be read mid-exec and pass without reaching the cwd — is what this version fixes). Test-only, so no new Codex review. bun run check fast passed on this branch.

server/omp-process.test.ts failed now and then in check fast's unit step with the probe
answering null 16 ms in ("keeps a process's empty arguments where they stand": received
undefined), on three lanes.

The tests probed a bun target right after Bun.spawn returned. A fresh bun spends its
first milliseconds paging in its binary, in uninterruptible sleep (state D in 17-36 of
1600 samples 5-20 ms after spawn on this PC under lane load), and the probe answers null
for a process in D by design: that is what keeps a WSL read blocked in the kernel out of
the bridge. With the target's binary evicted from the page cache first, 34 of 40
immediate reads were wrong; a bun target that printed READY first was still wrong in 24
of 40, since it keeps faulting pages in after it prints.

The targets are now a small shell that prints READY and waits in a read, and the test
reads it only after READY (0 of 40 wrong with both binaries evicted). The reads that are
not about the probe's deadline get 30 s instead of the 1 s default, which a bun helper
can miss on a loaded PC. 200 runs, 8 at a time beside a full unit run: 0 failures.
@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 20 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 eb0e3ee.

Files selected for processing: 2
  • server/codex-daemon.test.ts
  • server/omp-process.test.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.

server/codex-daemon.test.ts "returns null when a live process's CODEX_HOME is its deleted
cwd" failed in check fast with the home fallback (/home/devswha/.codex) instead of null.

The test read /proc/<pid>/environ of a sleep child spawned a moment before. Until its exec,
a child still shows the parent's environment, without the CODEX_HOME it was given: 1030 of
1600 reads right after spawn on this PC, 8 at a time.

The child is now a shell that prints READY and waits in a read, with no exec after it, so
the process the test reads is the one that said it is up (an exec after READY could be
caught midway with an empty environ, and the test then passed without reaching the cwd).
A control asserts the child's environ holds CODEX_HOME=. after the cwd is removed. Skipping
the removal now fails the test with the live directory. 200 runs, 8 at a time: 0 failures.
@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 (commit 1, omp-process): APPROVE, no blockers. Nits: READ_MS (30 s) is longer than a plain bun test timeout, so a stuck read would show as a test timeout (fails either way); the target is spawned just before try (it cannot outlive the run: its stdin is a pipe the test holds). Left as is.
omo-native-code-reviewer (commit 2, codex-daemon): first version REQUEST_CHANGES — READY was printed before exec sleep, so a read could land mid-exec on an empty environ and pass without reaching the deleted cwd. Resolved: the child is now /bin/sh -c 'echo READY; read _' (no exec after READY), plus a control that its environ holds CODEX_HOME=.; skipping the cwd removal now fails the test. 200/200 runs clean.
Codex (codex review, commit 1): no findings. Commit 2 is test-only: no Codex review, per the lane's review policy.

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. This PR changes only a test file, so by the maintainer's token rule it merges on the code review, the merge pass's own check and CI, without the gate reviewer.

Lane Verdict
Code review (omo-native-code-reviewer, programming + remove-ai-slops) PASS (CLEAR)
Merge pass's own check test files only: server/omp-process.test.ts and, in eb0e3ee, server/codex-daemon.test.ts
Code review of the eb0e3ee delta PASS (CLEAR)

What was checked

  • Stability: server/omp-process.test.ts ran 10 times in a row with 0 failures (6/6 each run). The conventions tests (including the fixed-sleep ratchet) and the typecheck pass.

  • Startup wait: each target is now a small shell that prints READY and then waits in read (state S). Each test reads only after READY, waiting on the target's output rather than a timer. The shell is killed and reaped in finally.

  • Coverage kept: a mutant that drops trailing empty arguments still fails the empty-arguments test.

  • eb0e3ee: the deleted-cwd codex-daemon test reads its child only once the child is up (READY), and checks that the child really has CODEX_HOME=. before it treats a null as the deleted cwd. Both test files pass 10 runs in a row.

Follow-ups (LOW)

  • The probe's state-D branch has no deterministic test. Before this PR it was reached only through the flake.
  • The READY wait has no deadline of its own; bun's 5 s per-test timeout bounds it.

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 8caf43f into main Oct 24, 2026
17 checks passed
@devswha
devswha deleted the fix/omp-process-test-started-target branch October 24, 2026 15:46
devswha pushed a commit that referenced this pull request Oct 24, 2026
… refuse a lone unread omp

Merge pass gate review of #1898:
- A pane whose only omp process could not be read got a null route, which
  fell back to the bridge's own default store for herdr's path. A live
  process whose argv and environment cannot be read now makes the route
  unproved whether or not another omp was read.
- On native Linux with herdr's argv, the route read /proc/<pid>/environ
  synchronously in the bridge. Every Linux read now goes through the
  bounded helper (timeout, size cap, refuses a process in D state), which
  fails closed to unproved.

Tests: every Linux read now goes through the real helper, so the chat
tests give it a deadline no busy PC reaches, and the routing-key test uses
#1862's started shell target, as omp-process.test.ts does.
devswha added a commit that referenced this pull request Oct 24, 2026
…o arrive (#1883)

## Change

A signed-in device (a watch-only one included) could hold every one of
the 16 read slots of
`POST /api/connection-diagnostics` by sending each report body a byte at
a time: the read had a
size bound but no time bound, so every other report got 429 until those
reads ended (#1425, item 1).

- `server/client-connection-log.ts`: each body now has one 10 s deadline
for the whole read, not a
per-chunk timeout. A timer covers a body that stops arriving; a clock
check after each chunk covers
one that keeps trickling. Past it the request gets **408
`trace_timeout`**, the reader is cancelled,
  and the slot is released by the existing `finally` in `handle()`.
- `shared/protocol.ts`: the route's comment lists the new 408.
- Item 4: `src/lib/connectionTrace.test.ts` closes every trace a test
opens (a later test's
`resumeConnectionTraces()` reached earlier tests' traces), and the new
`src/lib/api-signin.test.ts`
covers `authenticate` and `pairDevice`: request shape, reporting resumed
after a successful sign-in,
  and not resumed after a refused one.

Items 2 and 3 are left as they are, as the issue describes them: the
report quota is charged only
after validation so malformed posts cannot starve real ones (each parse
is at most 8 KiB, 16 at once),
and a 4xx refusal drops that incident's batch by design
(`connectionTrace.ts`, tested); the 408 follows
that rule and the next incident still posts.

This adds a status code to an HTTP route's contract, so it needs a real
review.

Fixes #1425

## Verification

- `server/client-connection-log.test.ts`: "ends a body that keeps
trickling in once the deadline for
the whole body passes" (fake clock, no sleeps) and "gives every read
slot back when the bodies holding
them stop arriving" (16 stalled bodies, 1 ms injected deadline). On
origin/main they fail (413 / a 5 s
  test timeout); on this branch they pass.
- `src/lib/api-signin.test.ts`: removing `resumeConnectionTraces()` from
`api.ts` fails the two
"resume" cases; resuming before the `ok` check fails the two "refused"
cases.
- Live, against `createServer({ port: 0 })` with 16 raw-TCP senders at
one byte per second, rotating
`X-Forwarded-For`: this branch answers each `HTTP/1.1 408 Request
Timeout` at 10.0 s and the next
report gets 204; origin/main answers none of them within 20 s and the
next report still gets 429.
- Reviews: omo-native-code-reviewer APPROVE (two LOW notes, both the
documented trade-offs above);
  Codex (gpt-6.1-sol, xhigh) APPROVE with no findings.
- `bun run check fast`: workflow syntax, generated files, typecheck and
build pass; unit tests
6395 pass, 4 fail, all outside this change. Three in
`server/shell-agent.test.ts` fail with EMFILE
from `fs.watch`, on origin/main too: this PC is at its inotify instance
limit (126 of 128) from
other sessions. One in `server/omp-process.test.ts` is the readiness
flake #1862 and #1869 address;
  it passes when run alone.

---------

Co-authored-by: mp <mp@local>
devswha added a commit that referenced this pull request Oct 28, 2026
… left out, and steady three flaky tests (#2101)

## Change

Fixes #2084, fixes #1965, fixes #2046, fixes #2085. Four tests that
failed on busy runners. Two of
them (#1965, #2046) were a real bug in the server, the other two were
the tests.

### #1965 and #2046: a loaded Codex thread missed in the kernel's lock
table (server)

Both tests saw the pane's other-folder rollout offered while another
loaded conversation should
have kept it from being chosen. Neither a time budget (#1965) nor a lock
registered late (#2046) was
the cause: `loaded()` prints READY only after every flock is taken, and
the "too long" guard
counts bytes (`WORD_BUDGET`), not time.

`heldThreadIds` read `/proc/locks` once. The kernel serves that file a
page at a time, and a
lock any process on the machine takes or drops between two pages moves
the lines after it, so one
read can leave a held lock out (or show one twice). Measured with 33
held flocks over 5 s of reads:
159 of 3604 reads miscounted them with nothing else locking, 581 of 2556
with two other processes
locking and unlocking. A loaded peer left out is not weighed, and the
other thread wins by
elimination: the symptom in both issues, and on a busy Linux PC the same
wrong binding in the app.

It now reads the table again, at most twice more, while a lock file in
the folder has no holder in
any read so far. A thread nobody holds costs two more reads of the
table; a held one is found in
the first read as before.

### #2085: the omo fixture read while herdr could not see its argv
(test)

herdr lists no argv for a process whose state forbids reading its memory
(state D;
`foreground_job_from_members` in herdr's `src/platform/linux.rs`). A
fresh bun is in D while it
pages its binary in, even after it has written its ready file (as #1862
found). Without argv the
server cannot tell the pane runs omo, so with no label reported the
commands are `[]`; the
labelled cases fell back to the label. Probe on an isolated herdr, a bun
copy named `omo` evicted
from the page cache: 19 of 30 reads right after the ready file had no
argv. The fixture is now a
small `/bin/sh` named so with `exec -a` that writes its ready file and
waits in `read`: 0 of 30.

### #2084: the markdown growth check counted other threads' time (test)

`linear()` timed the process's CPU time, which also counts the
compiler's and the garbage
collector's threads, and compared per-round ratios. It now times this
thread only and compares the
fastest small run with the fastest large run over up to five interleaved
rounds: being preempted or
slowed only adds time.

The thread's time comes from `clock_gettime(CLOCK_THREAD_CPUTIME_ID)`
through `bun:ffi` (Linux,
macOS; microsecond steps). The first push used
`process.threadCpuUsage()`, which counts in whole
ticks of a millisecond: a calibrated 2 ms run read 0 and the ratio was
`Infinity` in Fast checks
here (CodeRabbit flagged the same). Where that clock is missing,
`process.cpuUsage()` with the small
text calibrated to 20 ms.

Six copies on two CPUs, `--rerun-each 5` (480 ratios each):

| clock, comparison | median | p95 | max | failures |
| --- | --- | --- | --- | --- |
| process CPU, best per-round ratio (main) | 9.7 | 19.4 | 29.7 | 0 |
| process CPU, fastest of each | 9.7 | 18.0 | 30.0 | 0 |
| tick-based thread clock, fastest of each | 9.8 | 16.9 | Infinity | 4
of 240 |
| `CLOCK_THREAD_CPUTIME_ID`, fastest of each (this PR) | 9.9 | 13.7 |
27.2 | 0 |

Not a count of the parser's steps, as the issue suggested: two of the
guarded regressions
(`isTableSeparator` as one regular expression, `inlineMarks` trying the
whole pattern from
every opener) are a regular expression backtracking inside one call,
which no step count sees.

## Validation

- #1965/#2046: the new test (`counts a loaded thread one read of the
kernel's lock table left out`)
covers the peer left out of no read, every read, the first read and the
first two, and a holder
that opened the peer's lock between two reads (CodeRabbit); it fails on
the old `heldThreadIds`
  and passes with the fix. Raising the
32-thread cap to 64 fails "offers none of them past 32 loaded threads".
The whole file under load
  (`dori heavy`): 107 pass.
- #2085: `check run bun test --rerun-each 10
server/omo-prompt.contract.test.ts`: 60 pass, 0 fail.
With omo detection removed from `resolveAgent`, the three omo cases fail
(the null one with
  `[]`, as in the issue).
- #2084: with an unclosed `\[` searched again from every line, ratio
108.9, fails; with
`isTableSeparator` back to one regular expression, ratio 105.6 (106.3 on
the final clock), fails;
  restored, 47 pass.
- `bun run check fast`: pass (unit 7720 pass, 0 fail).
- No fixed sleeps added.
- Reviews:
- omo-native-code-reviewer: approve, no blockers. Its LOW note that the
three reads could tear
together was measured: with 2 and 8 other processes locking and
unlocking, 268 reads missed a
lock and none of their two re-reads missed it too. It stays a known
limit, not a guarantee.
- Codex Sol (gpt-6.1-sol, xhigh): MEDIUM, the new test read the real
table, which can tear on its
own; fixed: the test builds the table for its two locks and leaves the
peer out of the first
one or two reads (bigint inodes, Codex's LOW). No production finding.

`server/codex.ts` is in the remote bundle; `REMOTE_BUNDLE_VERSION` is
raised by the release PR
(release guards), not here.
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