Skip to content

fix(server): await bounded process metadata probes - #1407

Closed
christi4nity wants to merge 11 commits into
devswha:mainfrom
christi4nity:fix/nonblocking-process-probes
Closed

christi4nity wants to merge 11 commits into
devswha:mainfrom
christi4nity:fix/nonblocking-process-probes

Conversation

@christi4nity

@christi4nity christi4nity commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Change

Addresses #1404. Await process-birth and terminal-identity metadata on live status, conversation and pending-input paths instead of synchronously waiting for ps on 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.ts discovery is unchanged and needs a separate bounded streaming/coalescing change.

Validation

  • Typecheck, generated types/themes and production build pass.
  • Focused process/GJC/OmO/Codex/conversation unit tests: 263 pass, 28 platform skips (including GJC status after rebasing).
  • Isolated pending/Hermes/API/herdr/OmO contracts: 224 pass, 5 skips on the final rebased head; the final pending suite has 68 passing tests.
  • Controlled slow-child tests cover timer/HTTP responsiveness, deadline, streaming output cap and child admission limit.
  • Delayed-probe pending tests cover foreground replacement, lease loss, session replacement, PID reuse and an unknown intermediate birth. The 600 ms delivers / 1,500 ms holds controls use the async birth API.
  • 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 at scripts/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.
  • The Hermes contract fixture used a copied platform-signed /bin/sleep, which macOS killed before startup even on unchanged base. macOS now uses a test-owned Bun stand-in; the contract passes.
  • Fresh independent read-only review passes after fixing both known-birth and unknown-intermediate PID-reuse races.

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 -> SpawnSyncEventLoop chain. One includes BunObject_callback_spawn (async) and Unix-socket connect work; another includes GC; the third is mostly the normal event loop. The shared spawn_maybe_sync implementation 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: Background to Interactive. 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.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ec8e24f4-a31d-4599-b16f-6c306521f78f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72c91eed-27a2-4c80-95bd-7a0d4b9ba5c2
📥 Commits

Reviewing files that changed from the base of the PR and between 4a8204b and a751e55.

📒 Files selected for processing: 18
  • changelog.d/nonblocking-process-probes.md
  • server/codex.ts
  • server/conversation.test.ts
  • server/conversation.ts
  • server/core/pending.ts
  • server/gjc-runtime.ts
  • server/gjc-status.ts
  • server/hermes.contract.test.ts
  • server/hermes.ts
  • server/omo-identity.test.ts
  • server/omo.contract.test.ts
  • server/omo.test.ts
  • server/omo.ts
  • server/omp.ts
  • server/pending-input.contract.test.ts
  • server/process-start.test.ts
  • server/process-start.ts
  • server/shell-agent.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Process and terminal metadata checks no longer synchronously stall the Web UI, helping it remain responsive during runtime discovery.
    • Pending messages are held rather than sent when the target process, session, or interaction lease changes during verification.
    • Metadata probes now stop on timeout or excessive output, avoiding prolonged waits.

Runtime process and terminal metadata lookups now use asynchronous probes. The changes update process discovery across several runtimes and revalidate pending delivery targets after asynchronous checks.

Changes: Asynchronous runtime probes

Layer / File(s) Summary
Bounded asynchronous process probes
server/process-start.ts, server/process-start.test.ts, changelog.d/nonblocking-process-probes.md
Adds bounded subprocess probes and asynchronous process start-time APIs. Tests cover responsiveness, deadlines, output limits, concurrency limits, and invalid results.
Runtime metadata lookup integrations
server/codex.ts, server/gjc-runtime.ts, server/gjc-status.ts, server/hermes.ts, server/omp.ts, server/hermes.contract.test.ts
Codex, GJC, and Hermes await process or terminal metadata lookups. GJC transcript resolution and OMP callers also await their results.
OmO and foreground process discovery
server/omo.ts, server/conversation.ts, server/shell-agent.ts, server/omo-identity.test.ts, server/omo.contract.test.ts, server/omo.test.ts, server/conversation.test.ts
OmO identity and transcript resolution, conversation checks, and shell-agent matching use asynchronous process lookups. Related tests await the asynchronous results.
Pending delivery target revalidation
server/core/pending.ts, server/pending-input.contract.test.ts
Pending delivery refreshes process and pane observations after the probes, checks the lease again, and holds messages when the target changes or its process birth becomes unknown.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: devswha

Merge Risk: 🟡 Moderate · up to a751e

A process replacement could receive pending text or Enter, while heavy process discovery could hide panes or hold input unnecessarily. Resolve the wrong-target delivery risk before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: awaiting bounded process metadata probes in the server.
Docstring Coverage Passed Docstring coverage is 83.87% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 17 files. (1 skipped: 1…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description includes the required Change and Validation sections. It clearly explains the problem, resulting behavior, scope, known limitations, test coverage, and validation results.
Full details: Docstring Coverage

Explanation

Docstring coverage is 83.87% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 17 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch fix/nonblocking-process-probes
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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 added a commit that referenced this pull request Oct 19, 2026
…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.
devswha and others added 7 commits October 20, 2026 05:03
# 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).
@devswha

devswha commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Maintainer scope reduction after reviews of head 02d590d

This supersedes the previous async-pending follow-up.

Head: 7a56bac9559652607a83f3df575dd2254fae5c6b.

Commits:

  • c70fd210 - fix(pending): retain main synchronous identity checks

  • 7a56bac9 - fix(codex): preserve screen matching with unknown process birth

  • Restored server/core/pending.ts and server/pending-input.contract.test.ts to
    origin/main (bcaa07f at implementation).
    Removed only the async-pending checks/helpers and their dedicated contract cases;
    main's synchronous birth checks and applicable pending regressions remain.

  • Kept asynchronous status/conversation probes, the eight-child ceiling, 64-waiter
    FIFO and slot-until-exit behavior, OmO holder rules, and the Portal READY fixture.

  • Fixed OmO H1 / Codex MEDIUM 4: unknown process birth disqualifies only the resume
    hint window. It no longer exits before reported threads, cwd candidates and
    independent screen matching. No updated_at fallback was restored.

  • Added an unknown-birth matching-screen regression. Before the fix it returned
    null instead of the rollout (0 passed, 1 failed); after the fix it and the
    obsolete-resume unknown-birth control both pass.
    Fail-before log: /tmp/merge-pass/1407-scope-fail-before.log.

  • Narrowed the changelog and development docs to status/conversation probes.
    Pending-input birth checks still block the macOS event loop: the pending part of
    macOS: captured synchronous subprocess wait blocks the Web UI while Herdr remains responsive #1404 remains deferred.

Follow-up: /tmp/merge-pass/1407-followup.md records Codex HIGH 1-3 for a future
async pending implementation, OmO M3 (unknown-birth session loss/status flapping),
M4 (test-only refusal mode), and L1-L5. It also preserves the removed pending
implementation's M1/M2 lessons. These are explicitly deferred, not claimed fixed.

Portal conclusion is unchanged: the reported failure was not reproduced in the
previous 5 original-head, 55 main and 10 merged-tree runs. Its process helper is
unrelated. The retained READY signal fixes the fixture's exec-readiness gap,
without claiming that race was observed in those runs.

Verification:

  • Touched and retained-path units: 396 passed, 0 failed across nine files using
    HERDR_TEST_MODE=unit bun test --timeout 15000. Log:
    /tmp/merge-pass/1407-scope-unit.log.
  • bun run check run bun test --timeout 15000 server/pending-input.contract.test.ts server/hermes.contract.test.ts server/omo.contract.test.ts server/submit.contract.test.ts server/keys-lifecycle.contract.test.ts: 178 passed, 0 failed, exit code 0.
    Report node_modules/.cache/check/76e2ce35-f9d5-422a-9c72-f9374cc05c3f/report.json
    confirms unchanged source and verification: verified.
  • bun run check fast: exit code 0; 4,569 units passed, 0 failed, 8 skipped across
    350 files. Workflow syntax, generated types/themes, both TypeScript projects and
    production build all passed. Report
    node_modules/.cache/check/e9de8322-50a3-4898-bb19-1fb32028d531/report.json
    confirms unchanged source and verification: verified.

No native macOS or Windows run is claimed. No GitHub comment is being posted, and
this session stops at the pushed head for the maintainer's merge pass.

Push completed: immediately before the normal fast-forward push, the fork's
fix/nonblocking-process-probes branch still equalled
02d590d402f9b66c52c061628776619ff1cbb1bc. The push advanced it to
7a56bac9559652607a83f3df575dd2254fae5c6b, and a subsequent remote lookup
confirmed that exact head. The worktree is clean. No merge or GitHub comment
was performed.

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:

  1. Queued input can reach a different OmO session (server/omo.ts ~435): an unknown birth discards the pane's holders, so OmoStatus.sessionOf() becomes empty, and the unchanged pending guard accepts a missing session identity. Queue a message for session A, switch to B in the same process without a new herdr session report, then let discovery time out: the paste and Enter go to B. With a known birth (or main's resolver) the message is held with pending_target_changed.
  2. Unknown custom processes vanish before the completeness check (server/omo.ts ~379 vs ~424): custom runtimes with an unknown birth are dropped first, so a known launcher's --session-id hint can again restore the session its engine left, and a vanished custom peer lets another pane claim its transcript through cwd/time inference.
  3. MEDIUM (server/codex.ts ~1535): with resume in argv and an unknown birth, the early return still skips matchShortCodexAnswers.

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.

@devswha

devswha commented Oct 19, 2026

Copy link
Copy Markdown
Owner

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.

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

2 participants