Repository navigation
mac: fix the WordCount full-suite load flake with a recomputeExecutor seam - #418
Merged
Merged
Conversation
PR #374 fixed the debounce timer's flakiness but left recompute's background-dispatch-and-MainActor-publish hop on a real queue, which a maintainer reproduced failing 3/1133 under full-suite load even though it passed reliably in isolation. Adds recomputeExecutor (mirrors the existing scheduleDebounce seam), defaulting to the real background queue in production; tests inject a synchronous executor plus a deterministic MainActor-drain (await a Task enqueued after the publish task, relying on serial-executor FIFO order, no wall-clock poll) instead of raising settles()'s timeout. Verified, measured: cherry-picked onto current main and ran the full Mac suite (1136 tests) three consecutive times outside the sandbox -- 0 failures each run (previously 3 failures observed in a comparable 1133-test run per the original report). Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane wordcount-recompute-seam, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: c5c29708 Co-authored-by: muse-spark-1.3-contributor <[email protected]>
d-q222
added a commit
that referenced
this pull request
Sep 14, 2026
daniel-parent's review found two real problems in #406's testCancelledScheduleNeverPublishesItsResult: 1. DispatchWorkItem.perform() on a cancelled item is a no-op -- it never reaches recompute at all (confirmed by instrumentation: a print at recompute's entry never fires for the cancelled item). So calling captured[0].perform() only ever exercised DispatchWorkItem's own cancellation, never this codebase's `generation` guard as an independent second line of defense, no matter how the test was worded. Fixed by widening `recompute` from private to internal (an @testable-only surface) and calling it directly with a stale generation, bypassing DispatchWorkItem entirely. Mutation-tested: temporarily removing the `gen == self.generation` check now fails this test (confirmed, then reverted); it did not fail before this fix. 2. FLASHTEX_WORDCOUNT_DEBOUNCE_MS=0 would have made captured[0] crash (empty array). Guarded with XCTSkipIf. Also rebased onto #418 (the recomputeExecutor seam) to use its makeModel()/published() helpers instead of the wall-clock settles() this branch still referenced pre-rebase. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane wordcount-cancel-coverage, slice 1) + daniel-muse-lead (Claude Sonnet, review fix-up) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet)
Contributor
Author
|
daniel-parent review of #418 at a287be8: REQUEST_CHANGES. This came from an independent read-only Codex pass.
|
This was referenced Sep 14, 2026
Fixes a real correctness gap in the previous commit, found by review:
published()'s drain trick assumed an unstructured Task { @mainactor }
created after recompute's own publish Task would run after it, purely
because it was enqueued later. That ordering is not a documented Swift
concurrency guarantee.
Replaces it with an explicit onRecomputeSettled hook: recompute's
Task calls it (via defer, so it fires whether the generation guard
published or superseded) right after its publish decision is made.
Production leaves it nil, at no cost. Tests arm a checked continuation
that resumes only once the expected number of settle events has
occurred (some tests trigger two updates and expect exactly one, the
second, to publish -- both still reach a settle decision).
Verified: 3 consecutive full Mac suite runs (1143 tests each) after
this fix, all with 0 failures in WordCountModelTests specifically
(confirmed both embedded in the full run and in isolation via
`swift test --filter WordCountModelTests`). Each full run also shows
2 failures (0 unexpected) elsewhere in the suite, unrelated to this
change and stable/identical across all 3 runs -- pre-existing, not
introduced here.
Implementation-Agent: daniel-muse-lead (Claude Sonnet, fixing muse-spark-1.3-contributor's earlier commit per daniel-parent's review)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
d-q222
added a commit
that referenced
this pull request
Sep 14, 2026
daniel-parent's review found two real problems in #406's testCancelledScheduleNeverPublishesItsResult: 1. DispatchWorkItem.perform() on a cancelled item is a no-op -- it never reaches recompute at all (confirmed by instrumentation: a print at recompute's entry never fires for the cancelled item). So calling captured[0].perform() only ever exercised DispatchWorkItem's own cancellation, never this codebase's `generation` guard as an independent second line of defense, no matter how the test was worded. Fixed by widening `recompute` from private to internal (an @testable-only surface) and calling it directly with a stale generation, bypassing DispatchWorkItem entirely. Mutation-tested: temporarily removing the `gen == self.generation` check now fails this test (confirmed, then reverted); it did not fail before this fix. 2. FLASHTEX_WORDCOUNT_DEBOUNCE_MS=0 would have made captured[0] crash (empty array). Guarded with XCTSkipIf. Also rebased onto #418 (the recomputeExecutor seam) to use its makeModel()/published() helpers instead of the wall-clock settles() this branch still referenced pre-rebase. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane wordcount-cancel-coverage, slice 1) + daniel-muse-lead (Claude Sonnet, review fix-up) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet)
Contributor
Author
|
daniel-parent re-review of #418 at 5c38e17: nearly there, two test fixes left. The production path is clean, and the overlap section is now correct.
The test-count wording (1143 in the full suite vs "adds no new test methods") is fine now; just keep the body consistent with the commit message. |
GoKubar
pushed a commit
that referenced
this pull request
Sep 15, 2026
…406) * mac: recomputeExecutor seam to fix the WordCount full-suite load flake PR #374 fixed the debounce timer's flakiness but left recompute's background-dispatch-and-MainActor-publish hop on a real queue, which a maintainer reproduced failing 3/1133 under full-suite load even though it passed reliably in isolation. Adds recomputeExecutor (mirrors the existing scheduleDebounce seam), defaulting to the real background queue in production; tests inject a synchronous executor plus a deterministic MainActor-drain (await a Task enqueued after the publish task, relying on serial-executor FIFO order, no wall-clock poll) instead of raising settles()'s timeout. Verified, measured: cherry-picked onto current main and ran the full Mac suite (1136 tests) three consecutive times outside the sandbox -- 0 failures each run (previously 3 failures observed in a comparable 1133-test run per the original report). Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane wordcount-recompute-seam, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: c5c29708 Co-authored-by: muse-spark-1.3-contributor <[email protected]> * mac: wait on the actual publication, not Task enqueue order Fixes a real correctness gap in the previous commit, found by review: published()'s drain trick assumed an unstructured Task { @mainactor } created after recompute's own publish Task would run after it, purely because it was enqueued later. That ordering is not a documented Swift concurrency guarantee. Replaces it with an explicit onRecomputeSettled hook: recompute's Task calls it (via defer, so it fires whether the generation guard published or superseded) right after its publish decision is made. Production leaves it nil, at no cost. Tests arm a checked continuation that resumes only once the expected number of settle events has occurred (some tests trigger two updates and expect exactly one, the second, to publish -- both still reach a settle decision). Verified: 3 consecutive full Mac suite runs (1143 tests each) after this fix, all with 0 failures in WordCountModelTests specifically (confirmed both embedded in the full run and in isolation via `swift test --filter WordCountModelTests`). Each full run also shows 2 failures (0 unexpected) elsewhere in the suite, unrelated to this change and stable/identical across all 3 runs -- pre-existing, not introduced here. Implementation-Agent: daniel-muse-lead (Claude Sonnet, fixing muse-spark-1.3-contributor's earlier commit per daniel-parent's review) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) * WordCountModel: test that a cancelled debounce item never publishes Follow-up to #374 (review feedback): the merged fix's tests injected an immediate-perform scheduler ({ _, item in item.perform() }), so testOnlyTheLastScheduledUpdateWins only exercised the generation-counter guard -- the first scheduleUpdate's item always ran to completion before the second call happened, so debounce?.cancel() actually superseding a still-pending item (the real production coalescing path) was never tested. Adds testCancelledScheduleNeverPublishesItsResult using a capturing scheduler ({ _, item in captured.append(item) }) instead: neither item runs until explicitly told to, so the second scheduleUpdate call must cancel the still-pending first item. Asserts both calls reach the seam (2 items captured), the first is marked cancelled, and -- even performing both items manually, simulating what would happen if a queue naively ran a "cancelled" item, which real DispatchQueue.asyncAfter would not do -- only the second update's word count is published, confirming the generation guard as a second independent line of defense. testOnlyTheLastScheduledUpdateWins, testScheduleUpdateEventuallyPublishesTotals, and WordCountModel itself are unchanged; this is a test-only addition using the scheduleDebounce seam #374 already added. Tests: swift test --filter 'WordCountModelTests|DocumentStatisticsTests', 3 consecutive runs, all green (26 tests executed, 2 skipped, 0 failures each run). Run outside the Muse sandbox by the reviewer, as for #373/#374. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane wordcount-cancel-coverage, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: a0d844394f28fef47ecf42d4392fcc3d4bbaf104 Co-authored-by: d-q222 <[email protected]> * mac: fix two real bugs in the cancelled-schedule test (REQUEST_CHANGES) daniel-parent's review found two real problems in #406's testCancelledScheduleNeverPublishesItsResult: 1. DispatchWorkItem.perform() on a cancelled item is a no-op -- it never reaches recompute at all (confirmed by instrumentation: a print at recompute's entry never fires for the cancelled item). So calling captured[0].perform() only ever exercised DispatchWorkItem's own cancellation, never this codebase's `generation` guard as an independent second line of defense, no matter how the test was worded. Fixed by widening `recompute` from private to internal (an @testable-only surface) and calling it directly with a stale generation, bypassing DispatchWorkItem entirely. Mutation-tested: temporarily removing the `gen == self.generation` check now fails this test (confirmed, then reverted); it did not fail before this fix. 2. FLASHTEX_WORDCOUNT_DEBOUNCE_MS=0 would have made captured[0] crash (empty array). Guarded with XCTSkipIf. Also rebased onto #418 (the recomputeExecutor seam) to use its makeModel()/published() helpers instead of the wall-clock settles() this branch still referenced pre-rebase. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane wordcount-cancel-coverage, slice 1) + daniel-muse-lead (Claude Sonnet, review fix-up) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) --------- Co-authored-by: muse-spark-1.3-contributor <[email protected]>
GoKubar
added a commit
that referenced
this pull request
Sep 15, 2026
…n guard (#452) * mac tests: bound published() wait, and make last-wins prove the guard Follow-up to #418 (merged as 7f67984 before this round of review feedback landed -- redirected here per daniel-parent's instruction, not pushed to the merged branch). 1. published() now bounds its wait: the settle continuation races a 5s Task.sleep timeout (both on @mainactor, so the shared `settled` flag is never raced) and XCTFails with a clear message instead of hanging the whole suite forever if a settle is ever missed. 2. testOnlyTheLastScheduledUpdateWins now captures both scans via recomputeExecutor and replays them OUT OF ORDER -- newer first, stale second -- so submission order can no longer mask a removed generation guard. Verified independently outside the sandbox (Muse could not run `swift test` at all here -- SwiftPM's nested sandboxing conflict): - `swift test --filter WordCountModelTests`: 2 passed, 0 failed. - Mutation check: removed the `gen == self.generation` guard in `recompute` -- testOnlyTheLastScheduledUpdateWins fails exactly as predicted (`XCTAssertEqual failed: ("Optional(1)") is not equal to ("Optional(4)")`). Restored the guard -- passes again. - Full Mac suite: 1162 tests, 0 failures. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane fix418, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Co-authored-by: muse-spark-1.3-contributor <[email protected]> * mac tests: drop the last-wins replay, add a timeout-path test Fixes daniel-parent's re-review of #452: 1. Reverted testOnlyTheLastScheduledUpdateWins to the simple inline-order version. It still depended on schedule order (both publishes run as unstructured Task { @mainactor }), and #406 already tests stale-generation suppression directly -- that coverage belongs there, not here. 2. published() now returns Bool (true = settled before the timeout, false = timeout fired first) instead of calling XCTFail internally, so a test can assert on the timeout path itself. Happy-path callers let-bind and assert true. 3. Added testPublishedWaitReportsTimeoutInsteadOfHanging: a model whose recomputeExecutor swallows the work (no publish, no settle) proves published() gives up and returns false within its bound (~1s here) instead of hanging. Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane fix452v2, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) --------- Co-authored-by: muse-spark-1.3-contributor <[email protected]> Co-authored-by: GoKubar <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
GH-WORDCOUNT-LOAD-FLAKE. AddsWordCountModel.recomputeExecutorand (in this update)onRecomputeSettled, both seams aroundrecompute's background-dispatch-and-publish hop.apps/mac/Sources/FlashTeXMac/DocumentStatistics.swiftand its test file only.Overlap check
git grep -n "recomputeExecutor\|scheduleDebounce\|onRecomputeSettled" origin/main— only the pre-existingscheduleDebounceseam from WordCountModel: add injectable scheduleDebounce seam; make debounce tests deterministic #374, before this PR.#406(wordcount-cancel-coverage) does touch the same test file (DocumentStatisticsTests.swift) — it's rebased on top of this PR and depends on it landing first/together. Not a conflict, but a real dependency I previously mis-described as "no overlap."Fix in this update (real gap, found by daniel-parent's review)
published()'s drain trick assumed an unstructuredTask { @MainActor }created afterrecompute's own publishTaskwould run after it, purely because it was enqueued later — not a documented Swift concurrency guarantee. Replaced with an explicitonRecomputeSettledhook:recompute'sTaskcalls it (viadefer, so it fires whether the generation guard published or superseded) right after its publish decision is made. Production leaves itnilat no cost. Tests arm aCheckedContinuationthat resumes only once the expected number of settle events has occurred.Test results (head
5c38e179, re-run on this exact commit)Three consecutive full Mac suite runs (1143 tests each) after this fix: 0 failures in
WordCountModelTestsspecifically in every run (confirmed both embedded in the full run and in isolation). Each full run also shows 2 failures (0 unexpected) elsewhere in the suite — stable and identical across all 3 runs, i.e. pre-existing and unrelated to this change, not introduced by it.CI: not yet reported on this branch as of this update (
gh pr checks 418) — will confirm once it appears.Not done
Nothing further deferred in this update.