Skip to content

fix(watch): stop spurious overflow for excluded and unselected paths - #724

Merged
steipete merged 6 commits into
mainfrom
codex/fix-watch-live-overflow-20260927
Sep 27, 2026
Merged

steipete merged 6 commits into
mainfrom
codex/fix-watch-live-overflow-20260927

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Excluded build output and unrelated siblings could trigger whole-scope watch overflow, repeatedly waking Config-style entry subscriptions. Retain excluded path/kind records, ignore guarded unselected hints, remove the 25 ms scan-duration rule, and retry bounded native callback batches. Genuine backend loss and exhausted detail budgets still invalidate every scope.

macOS uses guarded canonical selected anchors and up to eight shallow exclusion paths, with joined stream replacement followed by reconciliation. Windows uses 1 MiB buffers on confirmed local volumes and 64 KiB on network or unclassified volumes. Root identity checks, generation fencing, guarded-only detail, and identity-based alias admission remain intact.

The Config test also needed a correct setup boundary: FSEvents can deliver coalesced ItemCreated activity after ready. Instrumented evidence captured flags 0x19100 for config.json with equal before/after fingerprints and no selected writes during sibling churn. The test now observes a sentinel selected edit and drains trailing events before measurement; its assertion during churn remains strictly empty. Admitted hints remain conservative for ABA/metadata-preserving activity, as documented. Unseen, already-gone spellings do not establish a selected identity or a complete transient history.

Final hosted counts at d416a447dced837f83580d90867089f030516b48:

Hosted platform A1 events / backend flags A1 poll A2 events A2 poll
Linux (ubuntu-latest) 0 / 0 0 0 0
macOS (macos-15) 0 / 0 0 0 0
macOS Intel (macos-15-intel) 0 / 0 0 0 0
Windows (windows-latest) 0 / 0 0 0 0

Every A1 case had zero spurious overflow and resumed detailed delivery. A2 remained quiet during 3,072 sibling operations; A3 retained detail through deterministic 40 ms passes.

Validation:

  • Exact-head CI is green across all lanes, including arm64, Intel, Windows 2022, Node 26, and no-openat2. Coverage, mutation-policy proof, and benchmarks are green.
  • The hosted macos-15 native job passed 20 event-mode and 20 poll-mode repetitions, with --retry=0. A fresh Crabbox Tart VM independently passed 20 + 20; the development Mac also passed 20 + 20.
  • A shortened-drain diagnostic reproduction captured the late setup creation during churn, reproducing the exact structural invalidation with unchanged fingerprints. The ordinary 150 ms fixture run passed 20 repetitions but still observed setup creation hints after ready in 11 runs, proving the old delay was not a queue-drain contract.
  • Private bounded diagnostics record native directory/name/flags and scan fingerprints on failure. Native flag coalescing/retry and conservative equal-snapshot admission have focused regression coverage. Isolated full-PR Codex review is clean.
  • Prior Linux AWS qualification passed 1.69 million churn operations, adversarial and the separate two-minute soak-short, plus 500 model seeds per mode with zero failures. The full hour-long soak was not substituted or claimed.

No changelog edit: the release coordinator owns the 0.21.1 notes.

@steipete
steipete requested a review from a team as a code owner September 27, 2026 07:08
@clawsweeper

clawsweeper Bot commented Sep 27, 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. proof: sufficient Contributor real behavior proof is sufficient. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 27, 2026, 6:12 AM ET / 10:12 UTC (Revision 7).

ClawSweeper review

What this changes

The branch filters excluded and unselected watch activity, retains bounded event detail through slow scans, changes macOS stream selection and Windows buffer sizing, and adds tests, CI coverage, and documentation.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep this PR open. Current main still has the reported overflow behavior, and this branch offers a distinct fix. Two previously reported macOS correctness gaps remain, and the user-visible fix still lacks the required Unreleased note.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Real cross-platform watcher evidence supports the central fix, but two macOS correctness findings and an unresolved Windows resource tradeoff limit merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The PR reports source-built native watch runs on hosted Linux, macOS, and Windows, a macOS VM run, and a real Linux filesystem-churn trace showing excluded-path isolation and detailed delivery afterward. The linked hosted run passed at earlier head e1fa088; final alias admission changes have source tests, while the macOS handover defects remain separate correctness blockers. Snapshot maps are runtime-only, so no stored-data compatibility change applies.
Patch quality 🦐 gold shrimp (3/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR reports source-built native watch runs on hosted Linux, macOS, and Windows, a macOS VM run, and a real Linux filesystem-churn trace showing excluded-path isolation and detailed delivery afterward. The linked hosted run passed at earlier head e1fa088; final alias admission changes have source tests, while the macOS handover defects remain separate correctness blockers. Snapshot maps are runtime-only, so no stored-data compatibility change applies.
Evidence reviewed 12 items Current-main behavior: Current main still converts an unclassified macOS pathname to whole-scope overflow; the branch changes that behavior.
Current-main slow-scan rule: Current main drops detail when a hinted scan exceeds the coalescing window; the branch removes this rule.
Exact-Root event gap: The changed macOS event handler returns when the event pathname equals the slash-suffixed Root prefix's base path. The guarded scan separately fingerprints Root metadata, so an ordinary Root mode event can be lost until a later scan.
Findings 3 actionable findings [P2] Invalidate exact-Root FSEvents metadata hints
[P2] Start the replacement stream before retiring the old one
[P3] Record the watch behavior fix under Unreleased
Security None None.

How this fits together

The watch API accepts paths and exclusions beneath an admitted filesystem Root. Operating-system events prompt guarded scans, which send bounded invalidations to subscribers.

flowchart LR
A[Caller scopes and exclusions] --> C{Selected activity?}
B[Admitted Root] --> D[Guarded reconciliation]
E[OS watch events] --> C
E -->|backend loss| D
C -->|yes| D
C -->|no| F[Quiet subscription]
D --> G[Bounded invalidation]
G --> H[Subscriber callback]
Loading

Decision needed

Question Recommendation
Should 1 MiB per local Windows watch become the default before concurrent-subscription memory and event-loss measurements are available? Defer the larger buffer: Keep the previous 64 KiB local buffer in this fix and revisit the increase with concurrent-watch measurements.

Why: The patch changes an existing per-subscription resource cost sixteenfold; accepting that default requires a maintainer resource-budget judgment.

Before merge

  • Invalidate exact-Root FSEvents metadata hints (P2) - For an empty-path Root scope, an ordinary FSEvents metadata event at the Root pathname fails the slash-suffixed prefix check and is dropped. scanWatch fingerprints Root mode, but the subscriber may wait for the periodic scan. Send this exact path through guarded Root invalidation and cover it with a macOS regression test.
  • Start the replacement stream before retiring the old one (P2) - Every anchor or exclusion change removes the active FSEvents stream before starting its replacement. A selected edit restored during that interval leaves neither a hint nor a snapshot difference; replacement startup failure also leaves no active stream. Keep the old stream active until the replacement starts, then test the handover.
  • Record the watch behavior fix under Unreleased (P3) - The new documented overflow behavior is user-visible, but CHANGELOG.md has no pending watch-fix entry. The repository policy requires one; the PR body's release-coordinator statement is not an explicit waiver. Add a concise entry or obtain release-owner acceptance.
  • Resolve merge risk (P1) - Each local Windows watch now retains 1 MiB instead of 64 KiB. With many subscriptions this can materially increase process memory, and the supplied proof does not establish a concurrent Windows memory bound or the event-loss benefit of the larger default.
  • Complete next step (P2) - Repair exact-Root macOS event handling and the stream handover, resolve the Windows buffer default, and add the Unreleased note or obtain explicit release-owner acceptance before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P2] Invalidate exact-Root FSEvents metadata hints — native/src/watch_macos.rs:139-140
  • [P2] Start the replacement stream before retiring the old one — native/src/watch_macos.rs:233-234
  • [P3] Record the watch behavior fix under Unreleased — docs/watch.md:66-72
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code and test delta production +423/-105; tests +392/-13 The production growth supports the cross-platform watcher change and carries substantial focused test coverage.
Local Windows watch buffer 64 KiB to 1 MiB per watch (16×) The larger retained allocation matters when applications create many subscriptions.

Merge-risk options

Maintainer options:

  1. Preserve the prior Windows allocation (recommended)
    Restore the 64 KiB local Windows buffer while landing the selection and callback fixes; measure concurrent use before increasing it.
  2. Accept a measured larger default
    Keep the 1 MiB buffer only after the owner reviews its concurrent memory cost and observed event-loss improvement.

Technical review

Best possible solution:

Keep the scope-filtering fix while preserving exact-Root events and continuous macOS observation, use a measured Windows memory budget, and record the user-visible fix under Unreleased.

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

Yes. Current-main source retains the reported overflow and slow-scan rules, while the PR supplies real watcher scenarios and reports baseline failures; the two macOS merge blockers are source-reproducible but were not executed in this read-only review.

Is this the best way to solve the issue?

No. Filtering unselected activity and retaining bounded detail fit the existing watch contract, but exact-Root hints and events during macOS stream replacement still need coverage.

Full review comments:

  • [P2] Invalidate exact-Root FSEvents metadata hints — native/src/watch_macos.rs:139-140
    For an empty-path Root scope, an ordinary FSEvents metadata event at the Root pathname fails the slash-suffixed prefix check and is dropped. scanWatch fingerprints Root mode, but the subscriber may wait for the periodic scan. Send this exact path through guarded Root invalidation and cover it with a macOS regression test.
    Confidence: 0.94
  • [P2] Start the replacement stream before retiring the old one — native/src/watch_macos.rs:233-234
    Every anchor or exclusion change removes the active FSEvents stream before starting its replacement. A selected edit restored during that interval leaves neither a hint nor a snapshot difference; replacement startup failure also leaves no active stream. Keep the old stream active until the replacement starts, then test the handover.
    Confidence: 0.91
  • [P3] Record the watch behavior fix under Unreleased — docs/watch.md:66-72
    The new documented overflow behavior is user-visible, but CHANGELOG.md has no pending watch-fix entry. The repository policy requires one; the PR body's release-coordinator statement is not an explicit waiver. Add a concise entry or obtain release-owner acceptance.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.89

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The PR addresses noisy watch invalidations, but its remaining macOS gaps affect a bounded observation workflow.
  • merge-risk: 🚨 compatibility: The changed macOS handler drops exact-Root metadata hints and stream replacement introduces an interval without event coverage.
  • merge-risk: 🚨 availability: The local Windows buffer default increases retained memory sixteenfold per subscription without concurrent-watch measurements.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (logs): The PR reports source-built native watch runs on hosted Linux, macOS, and Windows, a macOS VM run, and a real Linux filesystem-churn trace showing excluded-path isolation and detailed delivery afterward. The linked hosted run passed at earlier head e1fa088; final alias admission changes have source tests, while the macOS handover defects remain separate correctness blockers. Snapshot maps are runtime-only, so no stored-data compatibility change applies.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports source-built native watch runs on hosted Linux, macOS, and Windows, a macOS VM run, and a real Linux filesystem-churn trace showing excluded-path isolation and detailed delivery afterward. The linked hosted run passed at earlier head e1fa088; final alias admission changes have source tests, while the macOS handover defects remain separate correctness blockers. Snapshot maps are runtime-only, so no stored-data compatibility change applies.

Evidence

What I checked:

  • Current-main behavior: Current main still converts an unclassified macOS pathname to whole-scope overflow; the branch changes that behavior. (native/src/watch_macos.rs:91, 8b6ed73b4394)
  • Current-main slow-scan rule: Current main drops detail when a hinted scan exceeds the coalescing window; the branch removes this rule. (src/watch.ts:266, 8b6ed73b4394)
  • Exact-Root event gap: The changed macOS event handler returns when the event pathname equals the slash-suffixed Root prefix's base path. The guarded scan separately fingerprints Root metadata, so an ordinary Root mode event can be lost until a later scan. (native/src/watch_macos.rs:139, d416a447dced)
  • Root metadata contract: An empty-path scope records a fingerprint of the admitted Root, including directory mode. (src/watch-scan.ts:200, d416a447dced)
  • Stream replacement gap: Reconfiguration removes the live FSEvents stream before creating and starting its replacement. The following guarded pass can detect persistent changes, but cannot reconstruct an edit restored during the interval. (native/src/watch_macos.rs:233, d416a447dced)
  • Windows allocation change: Local Windows watches now allocate a 1 MiB buffer per anchor instead of main's 64 KiB; concurrent subscription memory has not been quantified in the supplied proof. (native/src/watch_windows.rs:25, d416a447dced)

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.

  • Restore exact-Root macOS invalidation and cover selected activity during stream replacement.
  • Measure concurrent Windows watch memory and event loss, or retain the previous buffer size.
  • Add an Unreleased watch-fix note or obtain explicit release-owner acceptance.

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 (6 earlier review cycles)
  • reviewed 2026-09-27T07:12:42.346Z sha bdb0d15 :: blocked before merge. :: [P3] Add an Unreleased note for the watch behavior fix
  • reviewed 2026-09-27T07:31:19.096Z sha d0a8972 :: blocked before merge. :: [P2] Preserve Root-path FSEvents as a guarded invalidation | [P3] Add an Unreleased note for the watch behavior fix
  • reviewed 2026-09-27T07:59:40.195Z sha e1fa088 :: blocked before merge. :: [P2] Preserve exact Root-path FSEvents as a guarded invalidation | [P3] Record the user-visible watch fix under Unreleased
  • reviewed 2026-09-27T08:27:00.946Z sha e1fa088 :: blocked before merge. :: [P2] Preserve exact Root-path FSEvents as a guarded invalidation | [P3] Record the user-visible watch fix under Unreleased
  • reviewed 2026-09-27T08:52:25.404Z sha 35185bd :: blocked before merge. :: [P2] Preserve exact-Root FSEvents as a guarded invalidation | [P3] Record the watch behavior fix under Unreleased
  • reviewed 2026-09-27T09:50:37.936Z sha 16214a4 :: blocked before merge. :: [P2] Preserve exact-Root FSEvents as a guarded invalidation | [P2] Cover the gap before replacing the macOS stream | [P3] Record the watch behavior fix under Unreleased

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. 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 27, 2026
@steipete
steipete merged commit c2f5297 into main Sep 27, 2026
48 checks passed
@steipete
steipete deleted the codex/fix-watch-live-overflow-20260927 branch September 27, 2026 10:31
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. 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