Repository navigation
feat(watch): add Rust-backed guarded filesystem observation - #690
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 26, 2026, 11:59 AM ET / 15:59 UTC (Revision 10). ClawSweeper reviewWhat this changesAdds a Root-bound filesystem watch API with a shared Rust event hub on Linux, macOS, and Windows, guarded scans, polling fallback, and supporting docs, tests, benchmarks, and CI checks. Merge readiness⛔ Blocked before merge - 5 items remain Keep this PR open. Current main and v0.20.0 do not provide the watch API, and the related draft PR is unmerged. The callback contract for activity on a watched directory after it leaves the admitted Root still needs an owner decision and final-effect proof. Priority: P2 Review scores
Verification
How this fits togetherApplications supply an admitted filesystem Root and literal paths to observe. Native events or polling trigger guarded scans, which send bounded invalidations and health information back to the application. flowchart LR
A[Admitted Root and scopes] --> B[Watch subscription]
B --> C[Native events or polling]
C --> D[Guarded metadata scans]
D --> E{Root still valid?}
E -->|Yes| F[Invalidation callback]
E -->|No| G[Failure and joined close]
Decision needed
Why: The public callback is an observable effect of persistent native observation, and the current contract and supplied proof do not establish which outcome the package owner intends. Before merge
Findings
Agent review detailsSecurityNeeds attention: The persistent native registration and final callback leave the moved-descendant authority boundary unresolved. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep native hints advisory while enforcing the chosen Root-membership rule at the final callback, with documented behavior and real move-and-reassignment regression proof. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR introduces a capability. Its real-edit checks cover allowed delivery, but no production-path trace shows the outside-only moved-descendant outcome. Is this the best way to solve the issue? Unclear: the shared hub and guarded scans fit the package's Root model, but the final callback rule for activity outside the Root needs an owner decision and proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against faa5f129ab5d. LabelsLabel changes: No label changes. Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
ab27e92 to
1ec3642
Compare
Keep guarded Root scans authoritative, multiplex Linux advisory hints in one joined native hub, and select portable polling on unqualified platforms. Supersedes the design in #666 without changing its branch. Co-authored-by: Vincent Koc <[email protected]>
Reject trailing-dot/space and reserved device components without changing POSIX literal names. Add portable Windows scope parser regressions for the hosted CI failure. Co-authored-by: Vincent Koc <[email protected]>
Enable native events on macOS and Windows while preserving guarded scan authority and the existing public API. Keep request storage alive through cancellation completion, reconcile recoverable enumeration loss, and require real event and joined-exit proof in native CI. Co-authored-by: Vincent Koc <[email protected]>
Open overlapped directory handles directly instead of using ReOpenFile. Preserve synchronous flags for every existing guarded caller and keep reparse/identity checks unchanged. Separate deterministic FSEvents decoding assertions from legitimate live overflow coalescing. Co-authored-by: Vincent Koc <[email protected]>
Wake kernel waits for commands and acknowledge consumed callback batches so backpressure needs no timer. Recover poisoned watch locks and measure idle cost in native CI. Co-authored-by: Vincent Koc <[email protected]>
c66a694 to
ef4e425
Compare
Supersedes #666. Preserve its guarded-scan model and smaller public API, while replacing the per-subscription Node Worker with a shared Rust hub. Native events are implemented on Linux, macOS, and Windows; Bun remains on explicit polling until TSFN lifetime is qualified.
Idle-hub follow-up:
c66a694d6aa7fe19be06957096e5f3b5ddd9a109. The hub now blocks on kernel events or explicit commands, with no timer tick. Linux AWS measured 994 → 0 voluntary hub context switches over 10 seconds; post-change edit latency was 28.05 / 25.91 / 25.86 ms. All exact-head hosted checks are green (32 success, six intentional skips at verification); hosted proof is recorded below. Local macOS timing remains unqualified on this follow-up: the system FSEvents service stalled independently of the addon, including in the standalone C probe. No test threshold was relaxed and no shutdown wait was detached.Design
autohelper-unavailable; existing nativerequirepolicy remains enforced.The shared hub sleeps on inotify plus eventfd (Linux), IOCP with a posted command sentinel (Windows), or the command channel (macOS). FSEvents callbacks enqueue bounded/coalesced drain notifications; JS consumption acknowledges queued batches so backpressure retries need no timer. Watch mutexes consistently recover poisoned guards.
Events remain advisory; guarded metadata scans through the admitted Root are authoritative. Literal entry/tree scopes, depth/budgets, no-follow symlink behavior, exact Root replacement refusal, private raw names, guarded detail admission, periodic reconciliation, immediate generation fencing, and joined close remain intact. Four reconciliation passes are internal. Initial admission and scope replacement publish one undetailed reconciliation.
Linux registers through
/proc/self/fd/N/.because IN_DONT_FOLLOW plus IN_ONLYDIR rejects the bare procfs symlink. Inotify ENOSPC has the separatewatch-limitfailure code. Windows zero-byte and enumeration-loss completions overflow; immediate enumeration loss and expired anchors request guarded rebuilding instead of permanently disabling observation. macOS pathname hints may reflect activity after a swap; names never bypass guarded admission and the old Root is never replaced.No new crates. The bounded, nonblocking Node-API callback wrapper owns rejected payloads explicitly, avoiding a leak in the locked napi-rs enqueue helper. Removed #666's Worker/eval/fs.watch transport, retained directory pins, unreachable JS recursion,
persistent, configurablemaxPasses,WatchFunction, public generations/scopes, extra health counters, andclosingstate.Consumer migration
openclaw/openclaw#158182 must adopt onDirty → onInvalidate, WatchDirty → WatchInvalidation, update → setScopes, and required mode events/auto/poll instead of node. Read errors through health().failure.error and use directories for observed-directory pressure. Application settling/reload/indexing and async-work ownership remain in the consumer. Exports, declarations, API snapshot, docs/navigation, benchmarks, and CI are aligned; the changelog thanks @vincentkoc under the post-0.20.0 Unreleased section.
Idle-hub follow-up proof
cbx_8f956289a0c1, confirmed released: baseline, candidate. Same lease, one events subscription, no filesystem edits during the ten-second sample: 994 → 0 voluntary context switches, summed for the named hub thread under/proc/<pid>/task/*/status. Rust tests, clippy, 27 applicable focused tests, forced-no-openat2, real edits and three joined-exit cycles passed.top -l 2 -s 10 -stats pid,idlew,cpu -pid <pid>reported 0 → 0 IDLEW for before/after; that host-level counter did not expose the old timer wakes. The process CPU samples were 12.028 → 6.305 ms (approximately 11.4-second sampling commands), not a per-thread CPU measurement. Native build, clippy, five Rust watch tests, and the new full-callback-queue regression passed. Focused event timing failed; the full localpnpm checkwas stopped after event failures and a blocked FSEvents cleanup. A process sample showed the dispatch queue waiting inf2d_unregister_rpc, while the standalone C probe also received no events in normal OS temporary storage. The host'sfseventsdwas using 159–195% CPU. This does not change platform support or replace the required hosted proof.topsample showed 1 IDLEW, 0.0% CPU.test/watch.test.ts:62; one unchanged-head rerun passed all 16,103 tests (648 platform/opt-in skips), with no code or threshold changes.Earlier feature proof (
a690dc6)cbx_26d8fa6db974: run. Native build, clippy, Rust hub tests, required events suite, standalone edit and bounded process-exit proofs, forced no-openat2, real inotify ENOSPC with restored kernel limit, and full tests passed (16,092 tests passed, 647 platform/opt-in skips).FS_SAFE_TEST_WATCH_EVENTS=1unconditionally for linux/darwin/win32, fails missing backends or skipped event cases, asserts actual events mode, and runs a separate real-edit proof. Linux musl also requires events.Size and limits
Complete feature: 3085 additions / 10 removals, versus #666's 2899 additions / 26 removals. TypeScript meets the ~900-line goal. Rust is 1246 production lines plus 117 native test lines and exceeds its ~900-line aim: explicit callback ownership, wake/acknowledgement paths, and Windows cancellation/storage lifetime are retained rather than weakening those safety properties. Total cross-platform code now exceeds #666; the public TypeScript implementation and tests remain substantially smaller.
Polling can miss metadata-preserving content edits. Native streams remain lossy hints and make no transaction-log or hard real-time promise. Bun events remain unqualified. The local FSEvents-service stall remains explicitly unqualified; see the follow-up proof above.