Repository navigation
fix(harness): Reap a dropped Session off-thread - #664
Merged
Merged
Conversation
Picking Model API froze the window for the two seconds `shutdown` waits on the child, so the menu was still down when the next pick arrived. `ax-settings pick` now waits for the row to take it. #634 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`turn` handled Shutdown exactly like Cancel - cancel, end the turn, loop - so the message was swallowed and the break came only on the second one `Drop for Wire` posts. `kill_harness_tree` sits after `serve` returns, so `Session::shutdown` paid the full `REAP` whenever a turn was in flight, and `retarget` paid it on the UI thread. Shutdown now returns `Lost`, which `serve` already breaks on, so the kill leaves at once and the dropped Session is reaped inline again. `verify-settings-macos.sh` counted a pick that did not take as a skip, and `skip` does not touch `failures` - so #634 returning printed "all checks passed" and exited 0. #634 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
omesser
force-pushed
the
fix/634-macos-harness-popup-off
branch
from
September 13, 2026 17:50
b252e87 to
e6e7401
Compare
omesser
marked this pull request as ready for review
September 13, 2026 17:50
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.
Why
On macOS Settings, switching the AI source popup back to
Offdid not take.ax-settings pick <pid> Harness Offexited 0, the dump still readclaude, and the nextpick Harness claudedied withthe Harness popup has no option claude.The popup-rebuild theory in the issue is wrong.
form::harness_options()is static and the items are never reordered — that guard was built, disproved against the live window, and removed.The cause is a main-thread stall.
harness::retargetreaps the dropped Session on the calling thread, and its only caller isSettingsSession::apply, which on macOS runs inside the popup's own action — on the UI thread, inside NSMenu tracking.Session::shutdownwaitsREAP(2s) for the child to go, so picking a new source froze the window for two seconds. During that freeze the AX dump read the popup from before the click and the menu was still on screen; the nextpickpressed a popup whose menu was already down against a stalled app, itsAXPresstimed out, the fallback dismissed the menu, and the option search found nothing. Both symptoms, one cause.What changed
The first attempt moved the reap onto a detached thread. Review found that traded the freeze for something worse, because
wire.shutdown()does not kill — it postsMsg::Shutdown, andturn()handled that exactly likeCancel: cancel, end the turn, and loop. The message was swallowed, and the kill waited for the second Shutdown thatDrop for Wireposts. So a detached reap could lose its race with process exit and orphan annpxtree that outlives the app.The fix is a rung lower, and it is the whole change:
src-tauri/src/acp_wire.rs—turn()now returnsErr(TurnError::Lost)onMsg::Shutdown.servebreaks onLost, and that break is the only road tokill_harness_treeinrun. The kill genuinely leaves at once. The in-flight reply is lost by design: every sender ofShutdownis killing the child a line later.src-tauri/src/harness.rs—retargetreaps on the calling thread, as it always did. No detached thread. That is affordable now precisely becausewait_for_exitreturns as fast as the kill does. Fixing the swallow removed the reason for the workaround instead of moving the cost somewhere it could escape.scripts/ax-settings.swift—pickwaits for the popup to read the picked title with its menu gone, sopickmeans "the row took it" rather than "the press returned".scripts/verify-settings-macos.sh— the two source-switchpickfailures are nowfail, notskip.skip()does not incrementfailures, so the script used to print "all checks passed" and exit 0 on exactly the bug it exists to catch. The skips further down are genuine environment skips and stay.This is shared code, so all three renderers get it. GTK and Win32 are
cfg'd out on this Mac and were not built here.How to verify
cargo test -p ai-buddy cargo clippy --workspace --all-targets -- -D warnings411 tests pass, clippy clean.
retarget_does_not_wait_out_a_turn_in_flightis the regression lock. It puts a prompt on the wire with theslowfake, installs the session, and timesretarget(Some(""), false). It asserts three things, not just the timing: that the call returns under 500ms, that the Off pick took, and that the child was really killed — the turn's caller must come backErr, and the session must not readalive.Mutation, run both ways just now: revert
turn()soMsg::Shutdownfalls back into theCancelarm and the test fails withagainst 0.04s with the fix. Four orders of magnitude, so the assert is not wall-clock flaky.
Live, on macOS 26.6.2:
AI_BUDDY_VERIFY_HARNESS=claudedoes not reproduce — claude attaches and the reap is masked.grok(spawns but never answers ACP, so its wire is live) reproduces exactly, including theno optiondeath. After:off-again.txtreadsAXPopUpButton||Model APIwith the full eight-option list intact.Notes
claude"set but not running". If that Harness never spawned,Session::wireisNoneandSession::shutdownreturns at its first guard — no wait, no freeze, so the stall cannot explain it. The live reproduction usedgrok, which did spawn and simply never answered ACP, leaving a live wire and the full 2s. These are plausibly two different preconditions, and theax-settings.swiftpickguard may be what actually fixes the symptom as filed. Flagging rather than closing over it — an issue that closes on the wrong explanation comes back.NSPopUpButtonmenu is a descendant of theAXPopUpButtonin the AX tree. If it is not, thefind(target, where: role == "AXMenu") == nilhalf of the newpickguard is vacuously true and only theAXValuecomparison carries weight.skip→failchange meansverify-settings-macos.shcan now fail where it previously exited 0. That is the point, but it may surface other latent failures on first run.Closes #634
— Claude Code agent, on @omesser's behalf.
🤖 Generated with Claude Code