Repository navigation
test(codex-processes): Codex fixtures say READY from the process after its exec - #3900
Conversation
…r its exec Three tests started their Codex stand-in as `echo READY; exec -a codex sleep 600`: READY came from bash before the exec. While an exec runs, /proc/<pid>/environ reads empty, and processCodexHome caches that read (no CODEX_HOME) for 30 s, so a lookup on a slow runner placed Codex A in the default store and the test that expects A's store to resolve failed with no_session_path (Fast checks on a GitHub-hosted runner, run 43710397061). They now start it with runningCodex, whose node process prints READY itself, after its exec.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Merge passMerged head
One reviewer: test-only. The fixture said READY before its exec, so a lookup could read an empty Not closed here, a product follow-up: Review reports: ~/.cache/ovis-tmp/reports/ |
… claims it as it is released never fails the run that let it go (#3905) ## What Fast checks on a GitHub-hosted runner (run 43717080636, attempt 2, PR #3738) failed `scripts/install-binary.test.ts` "lets one waiter at a time break a stale lock, with a mkdir that never refuses" with `rm: cannot remove '.../.install.lock': Directory not empty`. This is the race install.sh's `install_lock` comment had left as "a follow-up". The fault is in the script, not the test. **Mechanism.** `install_lock` claims the lock by creating `.install.lock/pid` only where none exists (noclobber), whatever `mkdir` answered. The lock was already exclusive before this PR. `install_unlock` released it with `rm -rf "$lock"`, which unlinks the pid a moment before it removes the folder. A waiter could claim the lock in that moment, with any `mkdir` (GNU, busybox, macOS, uutils). The holder's removal then failed with `Directory not empty`, and under `set -e` the install that had just finished exited 1. The waiter did hold the lock correctly. The stale-lock breaker's `rm -rf "$lock" || true` had the same interleaving, but its error was swallowed. **Fix.** - `install_unlock` and the breaker both call `install_lock_drop`. It moves the folder to `.install.lock.gone-<pid>` in one `rename(2)` (`mv`), while the holder's pid is still inside, and removes it there. A waiter never finds the folder without its holder's pid. One that resolved the folder before the rename fails to write its pid and tries again; one after it makes a fresh lock. - A run cut off between that rename and the removal (kill -9, or a signal during the `rm`) leaves its `.install.lock.gone-<pid>`. The lock's holder now removes every `.install.lock.gone-*` as soon as it holds the lock, right after the traps in `install_lock`. That cleans the leftover, and it clears an older leftover with this run's own pid before its rename needs the name. It sits in `install_lock` rather than beside the `.stage-*` sweep, because a run that waited and then finds the version installed releases the lock before reaching that sweep. - install.sh's comment, INSTALL.md and docs/development.md no longer say a race remains. **install.ps1** carries the same lock, but `Exit-InstallLock` and the breaker remove it with `Remove-Item ... -ErrorAction SilentlyContinue`. In the same interleaving the folder removal fails quietly, the waiter keeps a valid lock, and no install fails, so it is left as it is. **Tests** (scripts/install-binary.test.ts): - "leaves the lock to a waiter that claims it while the holder removes it, and both succeed" forces the interleaving with the system's own `mkdir` (no stand-in: the claim never depended on `mkdir`'s answer). - An `rm` stand-in makes the first removal of a lock folder pause where `rm -rf` does, between unlinking the pid and removing the folder, until another run holds the lock. Like `rm -f`, it takes a folder that is already gone as removed. - The second run starts once the first leaves a mark while holding the lock. The mark stays, so it cannot be missed. The wait is bounded at 30 s and exits 3 with "the first run never held the lock: no .../first-holds after 30 s", which fails the test instead of hanging it. - The test asserts the claim happened during the pause, both installs exit 0, bin holds the second's release, and no `.install.lock*` is left. - "removes the lock folder a run cut off while it released the lock left, and fails no run whose pid it names": a leftover `.install.lock.gone-1` from a dead run, plus `.install.lock.gone-<this run's pid>/.install.lock/pid`. The install exits 0 and no `.install.lock*` is left. ## Validation All on this commit, main (with #3900) merged in. | Run | Before | After | |---|---|---| | Release race, forced: `bun test --rerun-each 5 ./scripts/install-binary.test.ts -t 'claims it while the holder removes it'` | origin/main's install.sh: **5/5 fail**, holder exits 1, `rmdir: failed to remove '.../.install.lock': Directory not empty` | **5/5 pass** | | Leftover, `-t 'cut off while it released'` | 79bf6b7's install.sh (this PR's first head): **5/5 fail**, `mv: cannot overwrite '.../.install.lock.gone-<pid>/.install.lock': Directory not empty` | **5/5 pass** | | `bun test --rerun-each 30 ./scripts/install-binary.test.ts` | | **1020 pass, 0 fail** (34 tests x 30; the two new tests and the stale-lock test that failed in CI 30/30 each) | | `bun run check fast` | | **exit 0**: unit 17416 pass, 0 fail, 54 skip; typecheck, build, generated files, workflow syntax | - Waiters that must not get the lock still do not; these existing tests pass in every run: "leaves a fresh holder's lock to it when a slow breaker judged the lock before it stale", "takes over the lock of an install that died, and waits out a live one's, then says who holds it", "lets a second install in only after the first has swapped bin, not into its window" (both mkdir variants), "lets six waiters take a dead holder's lock one at a time" (its overlap marker), and "lets one waiter at a time break a stale lock". - `scripts/conventions.test.ts` and `scripts/changelog-fold.test.ts` pass; `sh -n install.sh` passes. - Skipped: `bun run check full`, the integration and browser suites (no `server/`/`src/` change), and the Windows install (install.ps1 unchanged). This PR touches `install.*`, so it waits for GitHub's own checks, including the real installer runs, not only a local merge gate.
Summary
server/codex-processes.test.tsfailed twice in one evening in Fast checks on GitHub-hostedubuntu-24.04runners: run 43710397061 (job 132800776012) and run 43714835800 (job 132814318485, PR #3808). Both times the failing test was "shows no conversation of the store an earlier read's Codex keeps once another Codex runs there", at line 186, and nothing else in the file failed. It gotno_session_pathwhere it expects{ source: "codex-transcript", path }, and the test took about 27 ms. A rerun passed it, and main's own runs never failed it.Three tests started their Codex stand-in as
bash -c "echo READY; exec -a codex sleep 600". That means READY came from bash before the exec. While an exec runs, the kernel has already switched the process to its new memory but has not laid out the environment yet, so/proc/<pid>/environreads empty.processCodexHomecaches that read (noCODEX_HOME) for 30 s. A lookup that read Codex A during A's exec therefore placed A in the default store. The test's second lookup, which expects A's own store, then found nothing there. A runner slow enough that A is still in its exec after Codex B has started (B is started right after A's READY) fails the test.The three tests now start the stand-in with the file's
runningCodex. Its node process prints READY itself, after its exec, the way the file's other process fixtures already signal from the state they promise. What the tests prove is unchanged. The two tests that expectno_session_pathnow see each stand-in's real store, so they test the earlier-read guard rather than a store read that might have come back empty.Every other process fixture in the file already signals from its final state: the Bun child after opening its files,
catechoing after Python's execv, the Python lock holders after flock, andrunningCodex/codexHoldingafter node's exec. On this PC, the only other failures of the file are 5 s timeouts in tests that start no process at all. Their cause is CPU time under heavy load, which this change does not address (see Validation).Validation
Forcing (scratch, not committed): a FUSE mount serves
/usr/bin/sleep(and, for the fixed fixture,node) and holds the read of the page the ELF loader faults in after the point of no return (the zeroed tail of the last file-backed segment) for 1-2 s. That stretches each exec of the stand-in the way a slow runner does, with the test file and product code unchanged;PATHputs the mount first./proc/<pid>/environas empty after B was ready in 5 of 5 rounds.codex-processes.test.ts:186withConversationUnavailable: no_session_path, the same as the hosted failure.sleepandnodeheld (--timeout 30000, since FUSE also slows node's start), and in 5 of 5 withsleepheld.taskseton one CPU at nice 19 or SCHED_IDLE beside a busy loop) did not reproduce it here: the exec finished within one time slice before B was ready.codexTranscriptPath(scratch, reverted), both "once another Codex runs there" tests fail.Unforced:
bun test --rerun-each 20 ./server/codex-processes.test.ts: the three changed tests passed 20 of 20. On a quiet PC (load average about 40 on 80 cores), the whole file passed all 20 passes: 5520 pass, 0 fail, 720 s. An earlier 20x run, made whilebun run check fastand the forced runs ran beside it (load average up to 124), had 5 timeouts in its first three passes. They were in tests that start no process at all ("still takes short answers below the prompts they answered", "takes no answer the screen shows with more at either end", two of "the thread id a Codex pane's terminal title shows", and "claims nothing for a long answer another pane shows under some other prompt"). Those tests are CPU-bound: this PC runs the file in about 58 s, against 11 s on the hosted runner. This change does not touch them.bun run check fastpasses.Skipped: Integration and browser, Native Windows install, macOS (no product code or other test changed). No changelog fragment, because the change is test-only.