Repository navigation
Keep FSEvents overflow recovery subscription-scoped - #2666
Conversation
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
This pull request changes watcher overflow recovery so one busy subscription does not restart every watcher subscription in the process.
I am reviewing it now. I will check security, code quality, architecture, duplicate code, performance, and the relevant test path.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
This change keeps a file-system overflow tied to the one watcher that reported it. The affected watcher retries and scans itself again.
Other watchers stay active. Fatal watcher errors still restart the shared child process.
I found no blocking security, correctness, architecture, or performance defect.
The child uses the existing overflow classifier. The parent uses the subscription ID to route the error to one watcher.
RootSubscription keeps control of its retry and scan policy. I found no duplicate recovery system and no need for a production refactor.
This private child protocol ships with the daemon bundle. It does not change server-to-daemon data, so no daemon protocol increase is necessary.
I found three low-priority test improvements:
- The benchmark checks stable counts, but it does not check the expected values.
- The benchmark measures proxy dispatch, but it does not measure the complete
RootSubscriptionrecovery path. - Turbo needs
--env-mode=looseto pass the benchmark variable. The pull request gives the correct command.
Validation passed for the changed proxy test file, all 12 tests, the host-watcher typecheck, and git diff --check.
The optional benchmark passed all 13 tests. It showed zero child restarts and no effects on 99 unrelated subscriptions.
GitHub CI passed. A full local package run had timeouts in unchanged tests during high host load.
Browser testing with doobie does not apply because this change has no browser path. The independent final review gate returned APPROVE.
562d7e8 to
d3078ca
Compare
## Human comments ## What was wrong Host and runtime tests covered the same contracts at two layers. Examples: - `workspace-dispatch` tests that were exact twins of the `host-files` handler tests; - agent-runtime recovery and provider-registry tests left over after #2325 moved recovery onto typed hints and made the registry id-agnostic; - `managed-config` tests repeated by the server-move service tests. Others tested a shared helper instead of their subject: the plugin-host env test called the `process-utils` sanitizer directly and never touched `PluginHostManager`. Two could not detect their bug: - the concurrent skill-staging test lacks a pinned clock, so it catches a same-millisecond temp-dir collision only by chance; - the watcher recovery harness is env-gated and asserts constants it hard-codes. A few tests kept exports alive only for themselves: `listPathsRecursively`, `diffCumulativeText`, `sendJsonRpc` and `toJsonRpcMessage`. ## What changed Found by a read-only test audit using the repo `test-audit` skill (#4361). - **Duplicate tests deleted.** Tests were tightened first where needed; for example, the relative-path handler test now asserts the error code and message. - **`runtime.fake-approvals.test.ts` deleted:** its unique assertions move into `runtime.interactive-requests.test.ts`, which now asserts the full command approval payload (reason, cwd, actions). - **`listPathsRecursively`:** its depth and exclusion cases now run through `listWorkspacePaths`, and the function is no longer exported. The dispatch test lists a nested directory. - **`diffCumulativeText`:** its tests fold into the assembler test, and it is no longer exported. - **`sendJsonRpc`:** inlined into `sendJsonRpcRequest`. `toJsonRpcMessage` is no longer exported. - **Unchanged:** request bytes, published Plugin SDK output and host-daemon wire shapes. - **Not in this PR:** the opt-in root-recovery benchmark (#2666), pending its author. Production +4/−15, tests +176/−1080. ## How you verified - `pnpm exec turbo run test lint typecheck` is green across host-daemon, agent-runtime, host-watcher, host-workspace, provider-bridge-acp, provider-bridge-protocol and provider-parity. - The only failures are the two `command-discovery` tests that fail on this machine when `/tmp/.agents` exists; they pass with `TMPDIR=/var/tmp/...`. - Off-pipeline suites: - provider-parity: 59/59. - integration `environment-actions`: 5/5. - agent-runtime `test:integration`: only the two real-Codex tests that also fail on base. - An independent verifier used before and after worktrees on 175d5ac and one mutation per removed test (39 tests). - Result: 31 OK, 4 with no unique failure mode, 4 partial losses. All 4 are restored here, and each fails under its mutation. - It also built `@get-bb/plugin-sdk` in both trees: `dist/` and `bundled-types/` are byte-identical. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
Human comments
What was wrong
RootSubscriptionalready distinguishes the native FSEventsFile system must be re-scannedcondition from fatal watcher failures and performs targeted refresh/reconnect/refresh recovery. The subprocess boundary introduced by PR #250 erased that distinction: every parcel callback error became the samewatch-error, and the parent unconditionally killed the shared watcher child, replayed every subscription, calledlistEntriesfor every root, and emitted synthetic updates to unaffected watches. Whole-child recycling is required for fatal Linux backend failures such as inotifyEINTR, but it turns a recoverable subscription-specific FSEvents overflow into O(all active watches) work.Historical supporting evidence, separate from the controlled benchmark below:
64c74f0a0and1283e636eintroduced targeted FSEvents recovery.2160f2838moved that lifecycle intoRootSubscription.9786b64d9made fatal Linux inotify callback errors terminal in-process to prevent retry leaks.cba0b9e89intentionally added whole-child recycling for fatalEINTR, child crashes, and hangs. Its interception was broad because the child protocol had no recovery classification, not because FSEvents overflow was intended to become global.What changed
rescan-subscriptionorrecycle-child.rescan-subscriptiononly to the matching proxy callback with the original message, allowing the existingRootSubscriptiontargeted recovery to run without replacing the child.This changes only the bundled parent/child watcher subprocess protocol. It does not change the server/host-daemon wire protocol, so
HOST_DAEMON_PROTOCOL_VERSIONis unchanged.How you verified
Controlled end-to-end benchmark
Both revisions ran sequentially on the same machine with byte-identical benchmark code and generated fixture contents: macOS 26.5.1 / Darwin 25.5.0 arm64, Node 22.23.1, pnpm 9.15.0. “Before” is
origin/mainata2fcbaf55with only the two benchmark files applied; “after” isd3078ca4c. Each scenario used 2 warm-ups and 20 measured iterations. Every iteration created a fresh real child process, IPC channel, native watcher set,HostWatcher, andRootSubscriptionset.Each root contains 8 directories with 16 × 4 KiB files each plus one 4 KiB trigger file: 129 files, 528,384 bytes, 9 top-level entries, and 137 recursive tree entries per root.
The measured path is:
real file write → real @parcel/watcher/FSEvents subscription in a forked child → production child handler and IPC channel → production proxy → HostWatcher.watchPathRoot → RootSubscription → production 250 ms reconnect retry and 75/500 ms callback scheduler → calibrated recursive readdir/read/SHA-256 downstream refreshRoot 0 alone receives the injected overflow. Measurement begins before the real trigger-file write and stops only after exact settled-work predicates pass. Before requires one child restart, all N proxy/native replay subscriptions, all N real
listEntriescalls, all N synthetic event callbacks, and all N recursive downstream scans. After requires the affected native unsubscribe/reconnect, both targeted rescan notifications, and both affected-root downstream scans. Subscribe/unsubscribe starts must equal completions, and a 100 ms quiescence assertion rejects late work after settlement.The controlled-load mode runs repeated SHA-256 work for 8 ms and yields for 8 ms on the benchmark process's event-loop thread. It is reproducible and does not load every CPU core or the live bb server. “Idle” means no intentional benchmark load, not a dedicated idle host.
Settled recovery latency
Milliseconds, p50 / p95 / max. The N=57 distributions mostly overlap because targeted recovery deliberately retains its retry and two debounce phases; the after idle p50 is higher. The scaling benefit becomes clear at N=100, especially under controlled load.
Maximum event-loop delay per iteration
Milliseconds, distribution of each iteration's maximum delay as p50 / p95 / max.
Initial readiness
Milliseconds from constructing the watcher graph until all HostWatcher
onReadycallbacks and all native subscriptions were ready, p50 / p95 / max. This happens before overflow injection and is recorded separately from recovery latency.Deterministic settled work
Counts were identical across all 20 idle iterations and all 20 controlled-load iterations for each revision. “2 scans after” is the affected
RootSubscription's dropped-event refresh plus its post-reconnect refresh; zerolistEntriesmeans zero global proxy replay scans, not zero targeted recovery.listEntriescalls / entriesRemaining controlled substitutions and limitations
tsx, rather than the packaged production entry, so it can wrap the real parcel backend and emit telemetry. The child handler and IPC protocol under test are production code.Full per-iteration JSON, including event-loop utilization, per-iteration delay p50/p95/max, load cycles, readiness, latency, and all counters, is produced by
BB_WATCHER_BENCHMARK_OUTPUT.Reproduction harness:
packages/host-watcher/test/root-recovery-benchmark.test.tsandpackages/host-watcher/test/fixtures/parcel-recovery-benchmark-child.ts.Regression and validation
Applying the new proxy test to
a2fcbaf55fails withexpected [ Array(2) ] to have a length of 1 but got 2; it passes ond3078ca4c:pnpm exec turbo run test --filter=@bb/host-watcher --force— 47 passed, 3 opt-in/platform-skipped.pnpm exec turbo run typecheck --filter=@bb/host-watcher— passed.pnpm exec turbo run build --filter=@bb/host-watcher --filter=@bb/host-daemon— 5 Turbo tasks passed; watcher child bundle built at 1,945 bytes.pnpm exec turbo run test --filter=@bb/host-daemon --force -- --run src/watch-manager.test.ts test/parcel-watcher-not-loaded-in-parent.test.ts— 19 passed.The full host-daemon run reached 564/565 passing tests, but current
origin/mainand this branch both fail host-daemon typecheck athost-branches-dispatch.test.ts:392becausehost.list_branchesis absent from the current command union. That unrelated daemon work is not changed here.No linked issue.