Repository navigation
fix(server): await bounded process metadata probes - #1407
christi4nity wants to merge 11 commits into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: 🟡 Moderate · up to
|
a751e55 to
7bab7e3
Compare
…ng argv (#1419) ## Change `server/portal.test.ts` "does not treat an arbitrary interpreter as a Portal script" read `/proc/<pid>/cmdline` as soon as the child was alive. Right after `Bun.spawn` the child can still show the parent's argv until the interpreter has started the script, so the test failed intermittently on CI (Fast checks on #1407, #1360 and #1352 today; each passed on rerun). The fixture script now prints `READY` once it runs, and the test waits for that line (bounded, 2 s) before reading argv. No production code changes. This is the test commit from #1407 (dbdc8d1), split out so other PRs stop failing on it while #1407 is still in review. ## Validation - `HERDR_TEST_MODE=unit bun test server/portal.test.ts`: 31 pass, 0 fail, three runs in a row.
# Conflicts: # docs/development.md
…is known With the engine's birth unknown its holder of the new session is dropped, while the launcher's known birth still let its --session-id hint restore the session the pane had left. Hints and herdr's report now need every birth in the pane (Windows, which never knows one, keeps main's behaviour).
|
Maintainer scope reduction after reviews of head 02d590d This supersedes the previous async-pending follow-up. Head: Commits:
Follow-up: /tmp/merge-pass/1407-followup.md records Codex HIGH 1-3 for a future Portal conclusion is unchanged: the reported failure was not reproduced in the Verification:
No native macOS or Windows run is claimed. No GitHub comment is being posted, and Push completed: immediately before the normal fast-forward push, the fork's The merge pass also pushed 232826d (launch hints and herdr's report are used only when every process birth in the pane is known) and merged main twice. The Portal test fix from this branch landed separately as #1419. Status: parked, not merged for now (maintainer decision). With the pending-input path restored to main, the reviewers still reproduce two HIGHs at 232826d, both from how an unknown (refused or timed-out) birth flows through OmO resolution:
Each round closed the reported cases; the remaining ones share one root: "unknown" from an async probe becomes "no session" in OmO resolution, and downstream code (pending input, status, cwd inference) treats "no session" as "nothing to protect". A way forward is to carry an explicit "unknown" state out of OmO resolution and make every consumer fail closed on it (pending holds, status keeps the previous binding, inference skips the pane), or to keep OmO resolution synchronous as on main and make only the GJC/Hermes/Codex paths async. The full review notes are in the comments above; happy to pick this up again in either direction. |
|
Thank you for this, and for staying with it through five review rounds. Closing it for now: with async probes, an unknown process birth kept turning into "no session" in OmO resolution, and queued input could then reach a different session (details above). The stall itself is still tracked in #1404, with the two directions that look workable; the maintainer fixes and the probe pool stay on this branch for reference, and the PR can be reopened if one of those directions is taken. |
… and await name lookups' git (#1980) ## Change #1404 sampled the server's main thread on macOS waiting inside `Bun.spawnSync` while herdr answered in under a millisecond. #1748 bounded those waits at 1 s, but each one still held every connection while it ran. This change removes the synchronous subprocess calls from the paths that run per request or per status poll: - **macOS process metadata no longer runs `ps`.** `process-start.ts` (`processStartedAt`, `processStartLowerBound`, `processStartUpperBound[Async]`), `gjc-runtime.ts` `gjcTerminal` and `hermes.ts` `hermesTerminalId` read the process's start and controlling terminal from the kernel's `kinfo_proc` (`sysctl KERN_PROC_PID`, plus `devname(3)` for the tty), through `bun:ffi` on libSystem. `claude-store.ts` already made the same read for Claude on macOS; the helper moves to `server/darwin-process.ts`. The read takes microseconds and starts no process, so it **stays synchronous**: no caller changes, and no new "unknown" state reaches OmO resolution or pending input (the reason #1407 was closed). The start is now exact rather than `ps`'s whole seconds, and every comparison keeps its tolerance. - **`files.ts` `filesNamed`** (opening a file an agent named without its folder) awaits the streaming git listing `paneFiles` already used, which has the same 3 s deadline, `SIGKILL` and 16 MiB cap, instead of `Bun.spawnSync`. `file-view.ts` `locateFile`/`locateFileInFolder` become async; `findFile`, their only production caller, already was. - Lookups for one folder that arrive while its git listing runs share that listing, instead of each starting a git (the old synchronous lookup ran them one after another). - **`usage.ts`**: the keychain FIFO's `mkfifo` is awaited and killed after 5 s. - **CI**: the macOS job also runs `server/darwin-process.test.ts`, the only check that the kernel record's terminal field matches `ps`. This is a workflow change. Still synchronous, on purpose, because each runs once at startup or inside the owner guard, not per request: `process-owner.ts` (owner guard; its persisted `lstart` birth format is compared across restarts), `managed.ts` (`git rev-parse` before the supervisor starts), `remote-entry.ts` (Windows marker at bridge start), `pty/host.ts` and `pty/sidecar.ts` (PTY host detection). Refs #1404 (it also asks about the reporter's remaining stalls, which #1407's comments tie to a `Background` LaunchAgent `ProcessType`; this PR does not claim to close that). Covers the macOS half of #1545's "no spawnSync reachable from currentIdentity". ## Validation - **eamac** (macOS 27.0.1 arm64, Bun 1.4.3), a fresh clone of origin/main `7ab4bde0b` and then the same clone with this patch. A script runs the four metadata reads a status poll makes (`processStartedAt`, `processStartLowerBound`, `hermesTerminalId`, `gjcTerminal`) in a loop for 4 s. Meanwhile a 2 ms timer measures event-loop gaps and a separate process sends HTTP requests to the same server every 20 ms: | | one round of reads, p50 | longest timer gap | HTTP p50 / max | |---|---|---|---| | main | 6.6–6.8 ms | 14.6–20.7 ms | 2.7–3.0 / 14.5–14.8 ms | | this PR | 0.06 ms | 2.6 ms | 0.2 / 0.7 ms | | main, `taskpolicy -b` (background QoS, as the reporter's LaunchAgent ran) | 27.6–29.6 ms | 52.5–53.2 ms | 9.9–11.3 / 48–52 ms | | this PR, `taskpolicy -b` | 0.47 ms | 11.5 ms (69 ms once) | 0.6–0.7 / 10.6 ms (112 ms once) | The two background-QoS outliers come from the scheduler throttling a busy loop; no subprocess is started. - New `server/darwin-process.test.ts` checks the `e_tdev` offset and the NODEV/short-answer cases. On macOS it also checks that the kernel's start and tty match what `ps -o tty= -o lstart=` prints for a live child, and that a missing pid gives null. The kinfo_proc layout was checked with clang on eamac: `sizeof(struct kinfo_proc)` = 648, `offsetof(kp_eproc.e_tdev)` = 572. - New `files.test.ts` case: while a fake git blocks on a FIFO, `filesNamed` lets a timer run before it answers, and a second lookup of the same folder shares that one git (one `Bun.spawn`; without the sharing it makes two, checked). Rewiring `filesNamed` to `Bun.spawnSync` makes that test fail (checked, then restored). The existing "both inventories" test now asserts that `Bun.spawnSync` is never called. - macOS focused suites on eamac (darwin-process, process-start, claude-store, gjc-runtime, files, file-view, hermes, grok, muse-store, usage): 342 pass, 7 skip, 1 fail. The failure is #1971, which fails the same way on unchanged main (3 of 3 runs). - Linux focused suites: 347 pass, 3 skip, 0 fail. - `bun run check fast` on the final head (5f8b825, rebased on main after #1986): all pass, unit 7261 pass, 0 fail, 25 skip. On eamac with a real tty, the macOS process tests give 299 pass, 3 skip, 0 fail. - Reviews: omo-native-code-reviewer: APPROVE, no blockers. Its findings and how each was resolved: - MEDIUM: `darwin-process.test.ts` did not run in the macOS CI job. Fixed: `ci.yml` runs it. - LOW: comments still gave `ps`'s whole seconds as the reason for the macOS start tolerances. Fixed: reworded; the tolerances are unchanged. - LOW: concurrent lookups of one folder each started their own git. Fixed: one shared listing per folder. - LOW: the offset unit test writes at the offset the code reads, so it cannot catch a wrong offset. Covered by the macOS CI test, which compares with `ps`. - NIT: `sysctlCall()` makes a closure per call. Kept: negligible. - Codex Sol review did not run (host stall); the merge pass reviews. - Astra gate (merge pass) B1, PID reuse could pair one process's terminal with another's start: fixed in 4d5ac0d. `darwinTerminal` returns the tty and the start from one `kinfo_proc`, and `gjcTerminal` and Hermes's breadcrumb lookup take both from it. A new test feeds two records to one lookup and checks that only the first is read; going back to two reads fails it (checked). On eamac with a real terminal (`ssh -tt`, `/dev/ttys001`), the tty and start match `ps`; darwin-process, gjc-runtime, hermes and process-start tests: 56 pass, 3 skip, 0 fail. --------- Co-authored-by: mp <mp@local>
Change
Addresses #1404. Await process-birth and terminal-identity metadata on live status, conversation and pending-input paths instead of synchronously waiting for
pson macOS. Each probe has a 1.5-second deadline, a streaming 4 KiB output limit and an eight-child ceiling (excess work returns unknown, without a queue). Cancellation kills only the probe child.Pending input rechecks terminal/process/session identity and sender authority after the new awaits. A replacement process, lost lease or unreadable previously known birth holds the message; it does not replay input. macOS birth tolerance and Linux/Windows behavior are retained. Synchronous helpers remain for fixture setup only, with no production callers.
Native samples show the Web UI main thread waiting inside Bun's synchronous subprocess machinery while direct Herdr pings remain responsive. The exact JavaScript caller is not proven. This change removes the metadata callers;
server/files.tsdiscovery is unchanged and needs a separate bounded streaming/coalescing change.Validation
CHECK_DIR=/tmp/hc-nbp-rf UNIT_TEST_WORKERS=2 bun run check fast: 4,484 pass, 79 skips, one known macOS installer-test failure atscripts/install-star.test.ts:284, reproduced on unchanged base. An unchanged collector timing test flaked on an earlier full run; focused rerun and final fast run pass./bin/sleep, which macOS killed before startup even on unchanged base. macOS now uses a test-owned Bun stand-in; the contract passes.Rebased onto main after its cold-GJC-lookup change, preserving the new status-specific lookup policy. The rebase has a fresh independent PASS review, typecheck, focused tests and isolated contracts. GitHub Actions has not run on this fork PR; local checks are not a substitute for maintainer-approved CI.
Local install outcome
The reviewed metadata-only fix was ported onto the installed v0.4.12-based diagnostic build and separately reviewed/tested before its approved install. Existing diagnostics and the personal frontend patch were retained. This did not resolve the observed freezes: the ten-minute post-install run had 156/590 sub-second Web UI health failures (26.44%), versus 184/759 (24.24%) before. Direct Herdr pings had 0 failures in both runs. System load and the reboot differ between windows, so this does not establish a regression or an improvement.
The three new native main-thread samples do not show the earlier
BunObject_callback_spawnSync -> SpawnSyncEventLoopchain. One includesBunObject_callback_spawn(async) and Unix-socket connect work; another includes GC; the third is mostly the normal event loop. The sharedspawn_maybe_syncimplementation name alone is not evidence of a synchronous API call. The exact remaining JavaScript caller is unproven. Keep #1404 open. File discovery remains a separate safety follow-up, not a confirmed explanation of these new stalls.Not merged or released.
Follow-up: local macOS scheduling correction
After the negative metadata-only install result above, the user approved changing only the local Web UI LaunchAgent from
ProcessType: BackgroundtoInteractive. The same build then passed ten minutes of read-only health checks: 0/598 failures, worst14.5ms, versus156/590 failures before. Direct Herdr pings had zero failures throughout. Herdr and all8 fresh-baseline terminal identities were preserved; diagnostics, Nightfox, launcher, runtime environment and paused automatic updates are unchanged.Owned process-probe controls reproduced the priority-sensitive stalls without real terminals. This points to a local macOS scheduling/workload interaction; it is not another code change in this PR or proof against every future stall. The setting is retained under the user's approval. Full outcome is recorded on #1404, which stays open pending normal-use confirmation.