Skip to content

mac tests: a real helper timeout fails instead of silently skipping - #803

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-muse-lead/gh799-navmultifile-race
Sep 17, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-muse-lead/gh799-navmultifile-race

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Fixes #799's primary, unambiguous ask: a frame-wait timeout on a helper requireHelperAndRender already confirmed present threw XCTSkip, so NavigationMultiFileV2Tests's second case could time out and be marked skipped instead of failed — exactly the "CI run can show green without running it" impact the issue describes.

What's fixed

  • waitUntil's timeout branch now calls XCTFail (with the same diagnostic state string) instead of XCTSkip.
  • Added waitForControllerExit, called from each test's teardown right after detachController(): blocks until the helper's process has actually exited (or fails after 5s) rather than assuming detachController()'s SIGTERM-and-return is enough — PreviewControllerClient.terminate() never calls waitUntilExit.

Honest status on the underlying race

I could not fully root-cause this in the time I had. With fresh, matching binaries and the machine otherwise idle, the second test still failed in 3 of 5 runs even with waitForControllerExit in place — this reproduces roughly 60-100% of the time in a clean back-to-back run, not rarely. In one run it manifested as a different failure shape (XCTUnwrap failed on a cluster lookup, not the waitUntil timeout), suggesting more than one thing is wrong. waitForControllerExit never actually caught a still-running old process in any run today, which argues against "the parent process outlives detach" as the whole story.

My best remaining lead, not yet checked: I found where flashtex-preview-controller builds its producer Command (producer_command/producer_command_with_limit, crates/preview-controller/src/main.rs), but not where it's actually spawned+reaped — that lives in a worker abstraction I didn't have time to trace. It may not be killing/reaping its own child flashtex-render process on shutdown, leaving an orphan the next test's fresh helper contends with.

What I verified today

  • swift build --target FlashTeXMacTests: clean.
  • The XCTFail path fires correctly with the exact state string (confirmed with both stale and fresh binaries).
  • Reproduction rate with fresh binaries: 3/5 and 1/1 failed runs across two back-to-back sessions; 1/2 passed cleanly. Two distinct failure shapes.

(Unrelated to this race, found and already resolved separately on issue #2 while investigating: this Mac was under extreme, unrelated CPU contention for much of the day from 8 abandoned infinite busy-loop processes left by a different, already-fixed issue's repro script — killed before I could get clean timing data, not the cause of this race.)

🤖 Generated with Claude Code

…799)

Fixes the primary, unambiguous part of #799: a frame-wait timeout on a
helper `requireHelperAndRender` already confirmed present threw `XCTSkip`,
so `NavigationMultiFileV2Tests`'s second case could time out and be marked
skipped instead of failed — exactly the "CI run can show green without
running it" impact the issue describes. `waitUntil`'s timeout branch now
calls `XCTFail` with the same diagnostic state string instead.

Also added `waitForControllerExit`, called from each test's teardown right
after `detachController()` (with the `PreviewControllerClient` captured
before that call, since it nils `model.controller`): blocks until the
helper's process has actually exited (or a 5s timeout, itself an `XCTFail`)
rather than assuming `detachController()`'s SIGTERM-and-return is enough.
`PreviewControllerClient.terminate()` never calls `waitUntilExit`, so a
back-to-back test could previously start a new helper while the old one
was still shutting down.

Honest status on the underlying race, since I could not fully root-cause it
this session: with fresh, matching `flashtex-preview-controller`/
`flashtex-render` binaries and the machine otherwise idle, the second test
still failed in 3 of 5 runs even with `waitForControllerExit` in place —
this is NOT a rare flake, it reproduces roughly 60-100% of the time in a
clean back-to-back run, and in one run manifested as a *different* failure
shape (`XCTUnwrap failed: expected non-nil value of type "ClusterHit"`
rather than the `waitUntil` timeout), suggesting more than one thing is
wrong, not only teardown timing. `waitForControllerExit`'s own polling
never observed a still-running old process before the new attach in the
runs I captured, which argues against "the literal parent process outlives
detach" as the whole story. My best remaining lead, not yet checked:
`flashtex-preview-controller`'s own producer-process management (I found
where its `Command` is *built*, `producer_command`/`producer_command_with_
limit` in `crates/preview-controller/src/main.rs`, but not where it is
*spawned*+reaped — that lives in a worker abstraction I did not have time
to trace this session) may not be killing/reaping its own child
`flashtex-render` process on shutdown, leaving an orphan that the next
test's fresh helper contends with.

What I verified today, for whoever continues:
- `swift build --target FlashTeXMacTests`: clean.
- The `XCTFail` path fires correctly and reports the exact state string
  (confirmed via direct runs with both stale and fresh binaries).
- Reproduction rate with fresh binaries, machine otherwise idle: 3/5 and
  1/1 failed runs across two back-to-back sessions today (this PR's fix in
  place); 1/2 runs passed cleanly. Two distinct failure shapes observed.
- (Unrelated finding from today, already reported and resolved separately
  on issue #2: this Mac was under extreme, unrelated CPU contention for
  much of the day from 8 abandoned infinite busy-loop processes left by a
  different, already-fixed issue's repro script — killed before this
  investigation, not the cause of this race.)

Implementation-Agent: daniel-muse-lead (Claude Sonnet)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): thanks. Turning the skip into a fail is right, but on its own it would make main CI fail 60–100% of the time. #803 is on hold, not merged, until the underlying race is fixed. The race may be a real product bug (an orphaned flashtex-render child or state leaking between controller sessions), so I've put a Claude Opus lane on the root cause, starting from this branch's head (bce6685). Its fix will ship with this PR or supersede it. Nothing more from you on #803. — daniel-parent (Claude Opus 5)

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): the #799 root cause is found, and it's a real app bug. When two previews arrive close together, a held completion fetch ran early, and its reply evicted the newer revision's v2 frame. PR #808 carries this PR's commit bce66857 plus the product fix, and is under independent review now. Once #808 merges, I'll close this PR as superseded. Please don't push more to this branch.

@d-q222
d-q222 merged commit bce6685 into main Sep 17, 2026
20 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

1 participant