Skip to content

fix(watch): use kqueue for macOS entry scopes - #753

Merged
steipete merged 3 commits into
mainfrom
fix/macos-shallow
Sep 28, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/macos-shallow

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Entry scopes anchored above a busy macOS subtree previously received recursive FSEvents traffic from unrelated descendants. That traffic could exhaust pending detail or trigger native overflow even when none of the selected entries changed. Entry scopes now use identity-checked kqueue descriptors for the admitted parent and, when present, the entry itself. Guarded scans re-arm replacements and finish transport admission before publishing readiness.

Parent activity requests a coalesced scan without filenames or pathname-budget pressure. Entry descriptors deliver content and attribute changes; symlink descriptors observe the link itself using O_EVTONLY | O_SYMLINK. Registration retains at most two descriptors per entry scope, counts them in health pressure, and fails explicitly on descriptor exhaustion. The shared hub blocks on kqueue and command wakes without native timers, and removal remains joined.

Tree scopes at every depth retain FSEvents, tree-only anchors, and the existing exclusion paths. Root identity and guarded pathname admission remain authoritative.

Reproduction and measurements

The hosted regression churns an unselected deep subtree beneath the entry anchor. Historical main is pinned at ff0bfa4f74f09a1bf08bd1ed9c1bce83d2fde45d; the candidate is 3ee42e2d7770e8d14a37e04bebebe9d4bec9c754. Each measurement lasted approximately 8.5 seconds.

Runner Historical entry overflows Candidate entry overflows Entry poll control Candidate depth-1 tree overflows
macos-15 (arm64) 104 0 0 66
macos-15-intel 28 0 0 31
windows-latest 75 106 0 59

Candidate macOS entry workloads sustained 15,653 operations/second on arm64 and 5,451 on Intel. Both delivered all nine selected-change phases: creation, content, file attributes, directory attributes, symlink retarget, symlink attributes after re-arm, deletion, recreation, and content after re-arm.

Windows measurements use its unchanged transport. Shallow tree scopes still receive recursive traffic and can overflow; those results are recorded without changing their transport or suppressing loss notifications. No Windows transport, version, or changelog changes are included.

Validation

All runs below are green on the exact candidate head:

  • Full CI: all platform lanes, including both macOS native architectures, Windows, Linux GNU/musl, Rust tests, and package checks.
  • Coverage.
  • CodeQL: JavaScript/TypeScript and Actions scans passed after readiness.
  • Ancestor regression and measurements: historical storm, zero candidate macOS entry overflows, poll controls, and remaining tree/Windows measurements.
  • Watch stress: all five runners; scale, fan-out, churn, lifecycle, adversarial, idle, short soak, 10-minute soak, and 500 seeds per mode with zero model failures.
  • Independent macOS 15.7.7 Tart proof: 11 Rust watch tests; 207 watch tests passed with 14 platform skips; pnpm check passed with 16,569 tests and package validation; 500 poll + 500 event model seeds passed. The VM and lease are retired.
  • Codex autoreview through P2: the implementation and both follow-ups are scoped-clean. The startup correction ensures the guarded handover completes before readiness; its exact-count test accounts for the additional macOS event pass.

Ready for coordinator review. Do not merge as part of this work order.

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 28, 2026, 6:30 AM ET / 10:30 UTC (Revision 4).

ClawSweeper review

What this changes

The branch uses identity-checked kqueue descriptors for macOS entry watches, retains FSEvents for tree watches, and adds documentation, regression coverage, and a comparative workflow.

Merge readiness

⛔ Blocked before merge - 8 items remain

Current main and v0.21.1 still expose macOS entry scopes to recursive FSEvents traffic, so this PR addresses a distinct remaining problem. The hosted comparison supports the repair, while filesystem safety and upgrade compatibility still need resolution.

Priority: P2
Reviewed head: 3ee42e2d7770e8d14a37e04bebebe9d4bec9c754
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong hosted before-and-after evidence supports the idea, but guarded admission and auto-mode compatibility still limit patch readiness.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The linked exact-head hosted workflow exercises public watch() with a real macOS filesystem churn workload: the PR reports 104 and 28 baseline entry overflows versus zero after the change on arm64 and Intel, with nine selected-change phases delivered. No stored-data contract changes; upgrade-capacity compatibility remains a separate merge concern.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The linked exact-head hosted workflow exercises public watch() with a real macOS filesystem churn workload: the PR reports 104 and 28 baseline entry overflows versus zero after the change on arm64 and Intel, with nine selected-change phases delivered. No stored-data contract changes; upgrade-capacity compatibility remains a separate merge concern.
Evidence reviewed 10 items Repository policy: The fully read policy requires shared guarded helpers for filesystem opens and an Unreleased entry for user-visible fixes.
Current main still uses FSEvents for entries: The stream-path calculation includes entry-scope parent anchors; the kqueue transport is absent.
Latest release still uses FSEvents: v0.21.1 registers an FSEvents stream for the watched Root; it does not contain this entry transport.
Findings 3 actionable findings [P1] Preserve auto-mode availability on descriptor exhaustion
[P2] Route kqueue descriptor opens through guarded admission
[P3] Add the watch fix under Unreleased
Security Needs attention Separate native path-admission implementation: Direct child openat calls create a second implementation of beneath-Root descriptor admission, leaving its behavior under swaps and aliases unproven against the shared guard.

How this fits together

The watch subsystem receives selected paths beneath an admitted filesystem Root. Native events prompt guarded scans, which publish advisory invalidations to callers.

flowchart LR
  A[Admitted Root and scopes] --> B[Guarded scan]
  B --> C{Scope kind}
  C -->|Entry| D[kqueue descriptors]
  C -->|Tree| E[FSEvents stream]
  D --> F[Guarded reconciliation]
  E --> F
  F --> G[Caller invalidations]
Loading

Decision needed

Question Recommendation
When macOS entry registration exhausts file descriptors, should auto mode switch to guarded polling or fail readiness? Preserve auto availability: Fall back to bounded guarded polling on descriptor exhaustion in auto mode while explicit events mode still fails.

Why: The branch changes the availability contract for existing auto-mode users, and the PR body describes failure without an explicit acceptance of that upgrade tradeoff.

Before merge

  • Preserve auto-mode availability on descriptor exhaustion (P1) - The new entry registration can throw EMFILE, which is mapped to helper-failed; auto mode only falls back for helper-unavailable. Existing entry watchers that worked through FSEvents can therefore fail readiness. This compatibility finding is raised late: the relevant code is unchanged since the first reviewed head.
  • Route kqueue descriptor opens through guarded admission (P2) - The introduced child openat walk implements a second path-admission boundary despite the repository's shared-guard policy. Centralize the literal no-follow watcher case and cover a path swap.
  • Add the watch fix under Unreleased (P3) - This documents a user-visible macOS watch fix, but Unreleased is empty. Add one concise fix entry as required by the repository policy.
  • Resolve security concern: Separate native path-admission implementation - Direct child openat calls create a second implementation of beneath-Root descriptor admission, leaving its behavior under swaps and aliases unproven against the shared guard.
  • Resolve merge risk (P1) - The separate raw descriptor-opening path has no focused swap regression demonstrating equivalence with shared guarded admission.
  • Resolve merge risk (P2) - Existing macOS auto-mode entry subscriptions can now fail readiness on descriptor exhaustion where the FSEvents transport worked; the intended fallback and upgrade behavior have not been approved or qualified.
  • Complete next step (P2) - Decide auto-mode EMFILE behavior, centralize guarded descriptor admission with swap coverage, qualify fresh and upgrade behavior, and add the Unreleased fix entry.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Preserve auto-mode availability on descriptor exhaustion — src/watch-native.ts:50-53
  • [P2] Route kqueue descriptor opens through guarded admission — native/src/watch_kqueue.rs:85-87
  • [P3] Add the watch fix under Unreleased — docs/watch.md:79
  • [medium] Separate native path-admission implementation — native/src/watch_kqueue.rs:87
Agent review details

Security

Needs attention: The new watcher duplicates security-sensitive native path admission outside the shared guarded helper; no reachable escape was established.

Review metrics

Metric Value Why it matters
Code growth production +464 lines, tests +75 lines The new native transport accounts for most production growth and has a stated overflow-reduction purpose.
Hosted macOS entry overflows arm64 104→0; Intel 28→0 The linked exact-head workflow and PR measurements directly address the reported recursive-event pressure.

Merge-risk options

Maintainer options:

  1. Repair admission and preserve auto availability (recommended)
    Use shared guarded descriptor admission, cover a path swap, and verify polling fallback plus fresh and upgraded packages.
  2. Accept descriptor capacity failure
    After the guarded-open repair, explicitly approve EMFILE readiness failure for auto mode with documented operator impact and upgrade proof.

Technical review

Best possible solution:

Keep kqueue for entry scopes, centralize literal no-follow descriptor admission, preserve a usable auto-mode path under descriptor exhaustion, and verify fresh and upgraded package behavior.

Do we have a high-confidence way to reproduce the issue?

Yes. The exact-main macOS baseline in the linked ancestor workflow overflowed under deep unselected churn, while the candidate reported zero entry overflows on both macOS architectures.

Is this the best way to solve the issue?

Not yet. The kqueue split addresses the observed pressure, but descriptor admission should share the guarded filesystem boundary and auto-mode capacity behavior needs an explicit compatibility choice.

Full review comments:

  • [P1] Preserve auto-mode availability on descriptor exhaustion — src/watch-native.ts:50-53
    The new entry registration can throw EMFILE, which is mapped to helper-failed; auto mode only falls back for helper-unavailable. Existing entry watchers that worked through FSEvents can therefore fail readiness. This compatibility finding is raised late: the relevant code is unchanged since the first reviewed head.
    Confidence: 0.9
    Late finding: first raised on code an earlier review cycle already covered.
  • [P2] Route kqueue descriptor opens through guarded admission — native/src/watch_kqueue.rs:85-87
    The introduced child openat walk implements a second path-admission boundary despite the repository's shared-guard policy. Centralize the literal no-follow watcher case and cover a path swap.
    Confidence: 0.88
  • [P3] Add the watch fix under Unreleased — docs/watch.md:79
    This documents a user-visible macOS watch fix, but Unreleased is empty. Add one concise fix entry as required by the repository policy.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ff0bfa4f74f0.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The linked exact-head hosted workflow exercises public watch() with a real macOS filesystem churn workload: the PR reports 104 and 28 baseline entry overflows versus zero after the change on arm64 and Intel, with nine selected-change phases delivered. No stored-data contract changes; upgrade-capacity compatibility remains a separate merge concern.

Label justifications:

  • P2: This is a bounded but meaningful fix for noisy macOS entry watches.
  • merge-risk: 🚨 compatibility: Descriptor exhaustion can change an existing auto-mode subscription from available to failed at readiness.
  • merge-risk: 🚨 availability: Retained per-entry descriptors introduce a new resource-limit failure for watch subscriptions.
  • merge-risk: 🚨 security-boundary: The new native path walker bypasses the repository's shared guarded-open helper.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): The linked exact-head hosted workflow exercises public watch() with a real macOS filesystem churn workload: the PR reports 104 and 28 baseline entry overflows versus zero after the change on arm64 and Intel, with nine selected-change phases delivered. No stored-data contract changes; upgrade-capacity compatibility remains a separate merge concern.
  • proof: sufficient: Contributor real behavior proof is sufficient. The linked exact-head hosted workflow exercises public watch() with a real macOS filesystem churn workload: the PR reports 104 and 28 baseline entry overflows versus zero after the change on arm64 and Intel, with nine selected-change phases delivered. No stored-data contract changes; upgrade-capacity compatibility remains a separate merge concern.

Evidence

Security concerns:

  • [medium] Separate native path-admission implementation — native/src/watch_kqueue.rs:87
    Direct child openat calls create a second implementation of beneath-Root descriptor admission, leaving its behavior under swaps and aliases unproven against the shared guard.
    Confidence: 0.87

What I checked:

  • Repository policy: The fully read policy requires shared guarded helpers for filesystem opens and an Unreleased entry for user-visible fixes. (AGENTS.md:25, 3ee42e2d7770)
  • Current main still uses FSEvents for entries: The stream-path calculation includes entry-scope parent anchors; the kqueue transport is absent. (src/watch-stream.ts:20, ff0bfa4f74f0)
  • Latest release still uses FSEvents: v0.21.1 registers an FSEvents stream for the watched Root; it does not contain this entry transport. (native/src/watch_macos.rs:178, 305ff575ce13)
  • Introduced descriptor admission: The new macOS path walker opens each child with direct libc openat and checks the final descriptor identity, separate from the shared guarded-open implementation. (native/src/watch_kqueue.rs:87, 3ee42e2d7770)
  • Existing guarded-open boundary: The Unix layer already owns beneath-Root opening and verification logic. (native/src/unix.rs:1455, 3ee42e2d7770)
  • Auto-mode capacity behavior: Entry registration propagates descriptor-open errors; auto mode falls back only for helper-unavailable, so EMFILE becomes a readiness failure. (src/watch-native.ts:50, 3ee42e2d7770)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Move descriptor opening into shared guarded admission and add a focused path-swap regression.
  • Settle EMFILE behavior for auto mode and verify fresh and upgraded package behavior.
  • Add one concise Unreleased watch-fix entry.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-28T09:39:29.687Z sha 6d5870e :: blocked before merge. :: [P3] Add the user-facing watch fix to Unreleased
  • reviewed 2026-09-28T09:45:13.211Z sha 5abee57 :: blocked before merge. :: [P3] Add the watch behavior fix under Unreleased
  • reviewed 2026-09-28T09:56:15.610Z sha 3ee42e2 :: blocked before merge. :: [P2] Route kqueue descriptor opens through guarded admission | [P3] Add the watch fix under Unreleased

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@steipete
steipete marked this pull request as ready for review September 28, 2026 10:21
@steipete
steipete requested a review from a team as a code owner September 28, 2026 10:21
@clawsweeper clawsweeper Bot added the proof: sufficient Contributor real behavior proof is sufficient. label Sep 28, 2026
@steipete
steipete merged commit 6a22d19 into main Sep 28, 2026
61 of 62 checks passed
@steipete
steipete deleted the fix/macos-shallow branch September 28, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant