fix(agent-isolation): stop the macOS touch overlay deadlocking on SIGTERM - #1376
Merged
potiuk merged 1 commit intoSep 24, 2026
Merged
Conversation
…TERM The watcher closes the Aqua overlay with SIGTERM the moment the key is touched. The window installed its flag-setting handlers before tk.Tk(), but Aqua Tk's initialisation replaces SIGINT/SIGHUP/SIGTERM with its own handler, which calls Tcl_Exit from inside the signal. Landing while the pulse is mid-redraw, the teardown blocks on the CoreAnimation backing-store lock the interrupted draw holds: the window deadlocks on its own main thread and stays on screen until force-quit (the hang report shows _sigtramp -> TkMacOSXSignalHandler -> Tcl_Exit -> Tk_DestroyWindow -> CABackingStoreInvalidate -> __psynch_mutexwait under CA::Transaction::commit). Take the signals back right after the root exists, and add SIGHUP, so the existing watch_for_stop poll is what closes the window and nothing unsafe runs in signal context. A regression test pins the ordering. Generated-by: Claude Opus 5
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.
The macOS touch overlay sometimes hangs on screen after the key is touched, and only a force-quit gets rid of it.
Cause
The watcher closes the Aqua window with
SIGTERM. The window script installs flag-setting Python handlers for that, but it does so beforetk.Tk(). Aqua Tk's initialisation then replaces SIGINT/SIGHUP/SIGTERM with its ownTkMacOSXSignalHandler, which callsTcl_Exitstraight from signal context.That is not async-signal-safe. The pulse redraws every 33 ms, so the signal often lands mid-draw, inside
CA::Transaction::commit, which holds CoreAnimation's backing-store lock.Tcl_Exitdestroys the windows, the destroy invalidates the view, and that blocks on the same lock. The main thread deadlocks on itself.A macOS hang report shows exactly that chain:
Fix
take_back_signals()installs the flag handlers for SIGTERM, SIGINT and SIGHUP right after the root exists, so Tk's handler is replaced. The existingwatch_for_stoppoll then closes the window, and nothing unsafe runs in signal context.main()no longer installs handlers beforetk.Tk().test_the_aqua_window_takes_termination_signals_back_from_tkpins the ordering. It fails on the old code.Testing
tools/agent-isolation/tests/test_gpg_touch_overlay.py: 93 passed, 7 skipped (the environment has no Tk 8.6 python, andpsis restricted).🤖 Generated with Claude Code