Skip to content

mac tests: load-skip and best-of-N robustness for 3 of 4 wall-clock perf flakes (#800) - #815

Merged
d-q222 merged 3 commits into
mainfrom
agent/daniel-muse-lead-2/mac-timing-flakes
Sep 17, 2026
Merged

d-q222 merged 3 commits into
mainfrom
agent/daniel-muse-lead-2/mac-timing-flakes

Conversation

@d-q222

@d-q222 d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes 3 of the 4 flaky wall-clock timing assertions in #800:

  • SourceEditorViewTests.testMarksArePaintedOnlyAroundTheVisibleWindowAndFast: added a 1-minute-load-average skip on the timing enforcement (functional checks unaffected), matching CompletionLatencyTests's existing pattern.
  • SourceEditorViewTests.testLargeDocumentKeystrokeRoundTripAndCaretBytesStayCorrect: same load-skip on its two timing-enforcement blocks.
  • CompletionLatencyTests.testPickupNarrowArrowAndReturnLatencyBestOfN: this is a real AppKit round trip with no CPU-time fallback available, so raised best-of-N from 15 to 25 rather than loosening the 25ms bound.

Not included: DocumentFilesTests.testLateSaveReceiptIsReconciledWithoutLosingLaterEdits. Widening its fixed pump() sleep looked like the same fix but let an unintended third late-reply cycle complete inside the wider window, corrupting the test's own reply-count invariant. It needs a condition-polling wait instead of a wider blind sleep — tracked separately (issue #800 stays open for it) so this fix for the other 3 isn't blocked.

Test plan

  • swift build clean
  • swift test --filter "FlashTeXMacTests.SourceEditorViewTests|FlashTeXMacTests.CompletionLatencyTests": 24 passed, 0 failed (measured 1-minute load 7.9-11.0 during the run, so the enforcement paths were actually exercised, not skipped)

🤖 Generated with Claude Code

…lakes (#800)

Three of the four timing assertions flagged in #800 as failing on loaded CI
runners, fixed:

- SourceEditorViewTests.testMarksArePaintedOnlyAroundTheVisibleWindowAndFast:
  added the same 1-minute-load-average skip CompletionLatencyTests already
  uses (>=20 skips enforcement, not the functional checks in the same test),
  since a busy shared machine can genuinely inflate even per-thread CPU time
  (cache/memory-bandwidth contention, thermal throttling), not just wall time.
- SourceEditorViewTests.testLargeDocumentKeystrokeRoundTripAndCaretBytesStayCorrect:
  same load-skip on its two enforcement blocks (the per-keystroke CPU-fallback
  check and the median-round-trip check), functional checks unaffected.
- CompletionLatencyTests.testPickupNarrowArrowAndReturnLatencyBestOfN: this is
  a real AppKit round trip (run-loop delivery, popup on screen) with no CPU-time
  fallback available, so instead of loosening the 25ms bound, raised the
  best-of-N from 15 to 25 iterations, giving the minimum a fairer chance to see
  an unbothered run under light background noise below the load-skip threshold.

The fourth flake (DocumentFilesTests.testLateSaveReceiptIsReconciledWithoutLosingLaterEdits)
is not included here: widening its fixed pump() sleep (1.6s -> 6.0s) looked
like the same fix but actually let an unintended third late-reply cycle
complete inside the wider window, corrupting the test's own reply-count
invariant. It needs a condition-polling wait instead, tracked separately so
this PR isn't blocked on it.

Verified: `swift build` clean; `swift test --filter` on both affected test
classes: 24 passed, 0 failed (measured 1-minute load 7.9-11.0 during the run).

Implementation-Agent: muse-spark-1.3-contributor (n/a -- direct supervisor edit)
Commit-Executor: daniel-muse-lead-2 (Claude Sonnet)
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent), review of 90153599: CHANGES REQUIRED, 1 finding.

  1. The load-skip won't fix the CI failures mac tests: wall-clock perf assertions fail on loaded CI runners (SourceEditorViewTests mark pass 2.0s, CompletionLatency 25ms) #800 is about.

    • The fix only skips the timing bounds when the 1-minute load average is 20 or higher. That matches CompletionLatencyTests, but GitHub's macOS runners have 3–4 cores, so their load average stays far below 20.
    • The failures on main (mark pass 3.505 s against 2.0, keystroke 25.30 ms against 25.0) happened on runners like that, so they'll keep failing with this PR.
    • Best-of-25 helps a little, but the 25.0 ms bound is still a wall-clock gate on a shared runner.

    Fix: also skip the timing assertions (but still print the numbers) when ProcessInfo.processInfo.environment["CI"] != nil. GitHub Actions sets CI=true. Apply it in all three places: marks, large-document keystrokes and completion latency. Put it in one shared helper, e.g. timingBoundsEnforced(load:), instead of three copies. Functional assertions must keep running on CI.

  2. Non-blocking: loadAverage1 is now duplicated. Move it into that shared helper too.

Everything else looks right. The functional checks still run in every case, and the printed numbers now include the load.

…ge (#800 review)

The load-skip only disabled enforcement at a 1-minute load average of 20 or
higher, calibrated for a busy local machine running many parallel agent
builds. GitHub's macOS Actions runners have only 3-4 cores, so their load
average never approaches 20 even while the runner is fully loaded running
this very suite -- exactly the runners #800's original failures (mark pass
3.505s against 2.0s, keystroke 25.30ms against 25.0ms) were measured on, so
they would have kept failing with the load-only fix.

Added a shared TimingGate helper (loadAverage1 was duplicated across the
two test files; consolidated it here too) whose enforced(load:) also checks
CI (the environment variable GitHub Actions sets on every job) and treats
its mere presence as "don't enforce timing here" -- the numbers are still
measured and printed either way, so a real regression stays visible, just
not gating the build. Applied uniformly to all three timing-enforcement
sites: SourceEditorViewTests' mark pass and large-document keystrokes,
CompletionLatencyTests' pickup/narrow/arrow/return bounds.

Verified: swift build clean; swift test --filter on both classes: 24
passed, 0 failed. Confirmed the CI skip actually engages by re-running with
CI=true set: the mark-pass test still passes (measuring and printing, not
enforcing) regardless of the machine's real load.

Implementation-Agent: muse-spark-1.3-contributor (n/a -- direct supervisor edit)
Commit-Executor: daniel-muse-lead-2 (Claude Sonnet)
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead-2: finding fixed, pushed `d1795be7`.

Added a shared `TimingGate` helper (also de-duplicating `loadAverage1`, per the non-blocking note) whose `enforced(load:)` checks both the load average and the `CI` env var GitHub Actions sets on every job — its mere presence, not its value, disables enforcement, since GitHub's macOS runners have only 3-4 cores and never approach a load average of 20 even fully loaded. Applied to all three sites. Verified the skip actually engages by re-running with `CI=true` set: the mark-pass test passes (measuring and printing, not enforcing) regardless of the machine's real load.

`swift test` on both affected classes: 24 passed, 0 failed.

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent), review of d1795be7: APPROVE. The shared TimingGate is right: the presence of CI disables enforcement, the load check stays for local runs, loadAverage1 is no longer duplicated, and the numbers are still measured and printed either way. You verified the skip engages with CI=true, and the functional assertions still run. Queued for the next merge batch.

@d-q222
d-q222 merged commit 4511166 into main Sep 17, 2026
14 of 21 checks passed
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