Skip to content

test(native): anchor watcher test bounds to an observed native delivery (HACK-2748) - #1284

Merged
roodboi merged 2 commits into
nextfrom
claude-lead/watcher-burst-flake
Nov 27, 2026
Merged

roodboi merged 2 commits into
nextfrom
claude-lead/watcher-burst-flake

Conversation

@roodboi

@roodboi roodboi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

HACK-2748

Root cause

Both native watcher tests gave the watcher 8 s, counted from the change, to report it. FSEvents promises delivery, not latency, so that bound measured the host rather than the watcher.

Evidence from the failing run (macOS, full --all-features suite):

  • The burst test's FSEvents stream registered with fseventsd. Then nothing arrived for the whole 8 s, and the watcher was dropped 8.1 s later when the assertion failed. The next test's watcher got its rename 0.28 s after it registered.
  • That run was not a one-off. The project contract binary took about 1.1 s (median of 215 retained runs on the same Mac). Over its last 14 runs that day it rose steadily to between 2 s and 9.7 s. In the process's FSEvents timeline, the two watcher tests were the slow part: the burst test took 1.8 to 6.9 s, and the single-rename test took 0.17 to 3.8 s. On that Mac a one-file rename sometimes took seconds to arrive, so an 8 s window for a burst was a latency assumption.
  • That Mac's data volume was at 99% use at the time of the investigation. This may have slowed delivery, but I haven't proven it.

I checked whether the watcher can actually lose a burst. I found no evidence that it can:

Check Result
30 bursts beside 18 CPU burners and 6 filesystem burners, with a raw FSEvents stream recording beside the real SourceWatcher All delivered. The first raw event came 0 to 17 ms after the burst started. Bursts themselves took up to 25 s under that load.
15 bursts beside a 16-thread filesystem flood, and 15 beside a thread that keeps creating and dropping watchers All delivered. No dropped-event flags.
Watch armed, then one write straight away: 300 runs each with a raw stream and with SourceWatcher, with and without load 0 missed. The fseventsd add_client log line falls inside FSEventStreamStart, so the watch is armed before SourceWatcher::new returns.
A stalled client flooded until fseventsd drops events fseventsd sends UserDropped | MustScanSubDirs for both watched roots. notify passes both as rescans, so the watcher wakes with reconcile_required.
notify purging events when it stops a stream FSEventsPurgeEventsForDeviceUpToEventId fails for non-root users (it is logged as failed in every run), so one stream cannot purge another's events.
File descriptors inherited by other tests' children (HACK-2743/2745) Does not apply. The watcher holds no file descriptors, only Mach ports and an in-process channel.

Change (test only)

Each test now arms two watchers on the source root: an independent control first, then the watcher under test. After the change, the test waits for the control. The control's delivery is the observed event. From that point the watcher under test must report the change within the original 8 s. The host's own delivery gets a 120 s hang guard. This is not a product contract: production source sync --watch has no latency bound and keeps waiting.

The test still proves what it proved before. A watcher that arms late or drops the change still fails. As a mutation check, I pointed the watcher under test at a sibling directory, and both tests failed in 8.4 s with the watcher missed a change the control observed after 50ms. The burst test still checks source_changed and the complete 256-file inventory.

The single-rename test had the same 8 s pattern and the same latency on that Mac, so it uses the same helper.

Evidence

  • cargo +1.97.1 fmt --check: clean.
  • Clippy -D warnings, default features and --all-features, all targets: clean.
  • Both watcher tests 20 times in a row beside 18 CPU and 6 filesystem burners: 20/20 passed, 0.8 to 1.2 s per run.
  • Full --all-features --no-fail-fast runtime-core suite on macOS, with next merged in: 34 binaries, 3031 passed, 2 failed, 189 ignored. project_contract passed 81/81 in 1.07 s, including both watcher tests. The 2 failures are outside this change, and each passes when run alone:
    • provider::registry_credentials::tests::helper_descendants_holding_stdout_cannot_extend_the_bounded_wait: helper recorded no descendant (registry_credentials.rs:628).
    • graph_cli::relay::tests::review_digest_binds_configuration_and_live_listener_generation: AddrInUse (relay.rs:506).
  • An earlier full run on the branch before next was merged in stopped at the HACK-2743 FIFO tests, which fix(native): make the hostname authority FIFO and Caddy-stop tests deterministic (HACK-2743) #1281 has since fixed.
  • After merging next: both watcher tests 20/20 again under the same load, and fmt and both clippy runs clean.
  • Secret scan of the diff: no leaks. bun run privacy:check after staging: ok.

Remaining gap

notify 8.2.0 ignores the return value of FSEventStreamStart. If registration fails, the result is a watch that silently never fires. That Mac's log for the last 3 days shows no FSEvents registration errors, so this did not cause the failure, and this PR does not change it.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

roodboi and others added 2 commits November 26, 2026 17:48
…ry (HACK-2748)

The native watcher tests gave the watcher 8 s from the change to report it. FSEvents
promises delivery, not latency: on a loaded Mac the same tests spent seconds waiting
for one rename, and in one full-suite run nothing from the burst arrived within 8 s.
That bound measured the host, not the watcher.

Each test now arms an independent control watcher first, then the watcher under test.
The control's delivery is the observed event; after it the watcher under test must
report the change within the original 8 s. The host's own delivery gets a 120 s hang
guard; production `source sync --watch` has no latency bound at all.

A watcher that arms late or drops the change still fails: pointing the watcher under
test at a sibling directory fails both tests with "the watcher missed a change the
control observed".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hack-docs Ready Ready Preview Nov 26, 2026 11:10pm UTC

Request Review

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@linear-code

linear-code Bot commented Nov 26, 2026

Copy link
Copy Markdown

HACK-2748

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T23:12:17.947494Z 1f3acb7 Manual request
🔒 Security Review ✅ Completed 2026-11-26T23:13:09.467673Z 1f3acb7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 1f3acb7d2c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 1f3acb7d2c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@roodboi
roodboi merged commit 684fea3 into next Nov 27, 2026
25 checks passed
@roodboi
roodboi deleted the claude-lead/watcher-burst-flake branch November 27, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant