Skip to content

fix(watch): correct macOS startup cleanup and share callback owners - #769

Merged
steipete merged 4 commits into
mainfrom
codex/macos-watch-owner
Oct 1, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/macos-watch-owner

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Failed macOS FSEvents exclusion setup or startup used the normal retirement path, which called FSEventStreamStop on a stream that had never started. Failed setup now invalidates/releases the scheduled stream; successful streams retain stop/invalidate/release retirement.

Each registration owns one immutable Arc<Owner> used as its callback context. Removal keeps that owner alive through stream retirement and both dispatch barriers. Backend::register rejects a duplicate ID with EINVAL before changing the registry, so it cannot free a live callback context. The new regression verifies the original owner and stream identities, continued callback delivery to the original notifier, rejection cleanup, and final retirement. Linux and Windows were checked: neither registration-map insertion exposes a raw pointer into the replaced value; their code is unchanged.

The exclusion stress fixture now observes selected-file event delivery and bounded quiet before its final isolated edit. Backend-overflow attribution, the overflow cap, excluded-path checks, and strict final detail assertions remain intact. This preserves main's #773/#774 watch behavior and its newer test coverage. The rebase conflict was limited to the changelog; the entry now lives under Unreleased → Fixes with the PR link.

The performance hold is lifted after maintainer review: registration/configuration is not a hot path, and all four write-control limits failed alongside the product measurements. Those measurements establish environmental noise, not a material regression attributable to this change; no performance improvement is claimed.

Validation: all 186 Rust workspace tests passed, and the repository's configured Clippy command passed with warnings denied. The broader all-targets Clippy invocation found 14 existing byte-character-slice lint errors in unrelated archive tests. JavaScript/WASM and native release builds passed. Local native event tests are unreliable on this Mac: selected writes receive no native hints and the real-event latency check fails while fseventsd is busy. Hosted exact-head CI, including CodeQL and both macOS native lanes, is the landing gate. The final review and CI outcome are recorded in the landing comment.

@clawsweeper

clawsweeper Bot commented Sep 29, 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. 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 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 7:47 PM ET / 23:47 UTC (Revision 5).

ClawSweeper review

What this changes

The branch changes macOS watch-stream cleanup and callback ownership, and adds lifecycle and selected-file observation tests.

Merge readiness

✅ Ready for maintainer review

Keep this PR open. Current main and the latest tagged release still use the incorrect failed-start cleanup path, so the repair remains useful. I found no discrete introduced defect.

Priority: P2
Reviewed head: 49f0a35bb7fb29f7e8f2ff8ed3f9725b0c113fff

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with substantial lifecycle coverage and no identified blocking defect supports a normal good PR rating.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The recorded MEMBER proof exemption applies. Synthetic tests exercise the changed macOS registration, startup, callback, and retirement paths; the captured discussion reports unreliable local native event delivery and pending hosted macOS checks. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The recorded MEMBER proof exemption applies. Synthetic tests exercise the changed macOS registration, startup, callback, and retirement paths; the captured discussion reports unreliable local native event delivery and pending hosted macOS checks. No stored-data contract changes.
Evidence reviewed 10 items Repository policy: The full root policy calls for conservative filesystem-boundary review and focused platform-specific regression coverage.
Current-main failure path: Failed exclusion setup or stream startup dispatches retire, which unconditionally calls FSEventStreamStop.
Latest tagged release: The v0.21.3 source retains the same failed-start retirement path; the proposed repair has not shipped in that release.
Findings None None.
Security None None.

How this fits together

The watch API receives scopes beneath a guarded filesystem Root. On macOS, FSEvents sends advisory hints to the native watcher; guarded scans decide which invalidations reach the application.

flowchart TD
 A[Root and watch scopes] --> B[macOS stream setup]
 B --> C{Stream started?}
 C -->|Yes| D[Stable callback owner]
 D --> E[Pending event hints]
 E --> F[Guarded scan]
 F --> G[Application invalidation]
 C -->|No| H[Invalidate and release]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test lines production −26 net, tests +692 net The native implementation contracts while added tests exercise distinct lifecycle and observation cases.

Technical review

Best possible solution:

Keep guarded scans authoritative for published path detail while landing the focused macOS stream-lifecycle repair.

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

Yes, at source level: current main calls Stop when exclusion setup or startup fails before a successful Start. This read-only review did not execute that failure path.

Is this the best way to solve the issue?

Yes. Separating cleanup for unstarted streams from active-stream retirement addresses the FSEvents lifecycle error while preserving guarded reconciliation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded macOS watcher reliability repair without evidence of a widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The recorded MEMBER proof exemption applies. Synthetic tests exercise the changed macOS registration, startup, callback, and retirement paths; the captured discussion reports unreliable local native event delivery and pending hosted macOS checks. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

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

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 (4 earlier review cycles)
  • reviewed 2026-09-29T19:06:17.578Z sha 791164f :: blocked before merge. :: none
  • reviewed 2026-09-29T19:37:34.704Z sha 027a6a5 :: blocked before merge. :: none
  • reviewed 2026-09-29T20:15:37.634Z sha 027a6a5 :: blocked before merge. :: none
  • reviewed 2026-09-30T23:23:33.322Z sha a29ecfb :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 29, 2026
@steipete
steipete force-pushed the codex/macos-watch-owner branch from 027a6a5 to a29ecfb Compare September 30, 2026 23:18
@steipete
steipete marked this pull request as ready for review September 30, 2026 23:18
@steipete
steipete requested a review from a team as a code owner September 30, 2026 23:18
@steipete

Copy link
Copy Markdown
Contributor Author

The performance hold is lifted: registration/configuration is not a hot path, and all four write-control limits failed along with the product measurements, so that experiment does not establish a material regression attributable to this PR.

Added an explicit duplicate-ID rejection before the macOS owner-map insertion. Its regression proves the original owner and stream stay intact, the original callback still delivers, and retirement completes correctly. Linux/Windows do not have the corresponding borrowed-context replacement hazard and are unchanged. The exclusion fixture retains strict overflow attribution and final selected-file assertions after rebasing onto #773/#774.

Candidate a29ecfb53efda4e3c5f5daa7a129976916dbb8b4: 186 Rust tests, configured Clippy, JS/native builds, and independent P0–P2 review passed. Local event proof finished 268 passed / 7 failed / 14 skipped with absent FSEvents delivery; the broad local check also encountered worker/timeouts and was stopped. Landing remains gated on exact-head hosted CI, including CodeQL and both macOS native lanes.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Sep 30, 2026
@steipete
steipete force-pushed the codex/macos-watch-owner branch from a29ecfb to 49f0a35 Compare September 30, 2026 23:40
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Final candidate 49f0a35bb7fb29f7e8f2ff8ed3f9725b0c113fff is rebased onto current main through #770; all four PR patches are unchanged by that rebase. The performance hold is lifted for the reasons above, and the duplicate-ID guard preserves the original callback owner and active stream, as covered by its regression.

All exact-head checks are green: CI, including both macOS native lanes; CodeQL; coverage; ancestor scopes; and benchmarks. The Windows native lane passed on its first retry after the PowerShell thread-census helper hit its 30-second timeout with no output. No admin bypass is needed. Local Rust tests, configured Clippy, builds, and P0–P2 review passed; hosted macOS supplies the event proof because this Mac's FSEvents delivery is unreliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant