Repository navigation
fix(linux): stop theme changes deadlocking the app mailbox - #46
Conversation
With many sessions open, a theme change froze the app: the main thread fed theme OSC 10/11 into every surface, each feed pushed color_change into libghostty's 64-slot app mailbox with a .forever fallback, and only the main thread drains that mailbox. - Theme colors reach surfaces only through config; the host feeds, the feed helpers and themeOSC/themeResetOSC are removed. - The OSC 11 latch overlay carries only opacity and font (macOS umputun#312), selected by the new LinuxBackgroundOverlayPolicy. - libghostty patch: drop ghostty_surface_feed; under must_draw_from_app_thread, renderer_health pushes .instant and a PendingHealth value is retried from App.tick after the drain. - AT-SPI scenario theme-many-sessions guards the hang and the color cases; control calls take a per-call timeout. - libghostty.md records the config-only path and the app mailbox rule. Claude-Session: https://claude.ai/code/session_01UXsFSAnftzk65uhqTTKixZ
2107d72 to
0808b7a
Compare
|
A field report that looks like this same hang, but without any theme change. Issues are off on this repo, so I'm posting it here; this PR seems the right home. Setup: agterm-linux Symptom (about 02:00, found at 06:15): the control socket stopped answering,
I couldn't get a backtrace ( This PR's analysis fits: a main-thread |
Problem
On Linux, changing the theme with many sessions open can freeze agterm for good. The window stops repainting and the control socket stops answering, starting with
theme setitself. It reproduced with 12 sessions in 5 of 5 manual runs and with 16 in the regression harness; the exact threshold depends on timing.The cause is that the main thread waits on itself.
applySettingsfed theme OSC 10/11 into every surface. Each feed pushedcolor_changeinto libghostty's 64-slot app mailbox with a.foreverfallback. Only the main thread drains that mailbox, inghostty_app_tick. With enough surfaces the mailbox fills, the push blocks, and nothing is left to drain it.Fix
Theme colors now reach surfaces only through config, as they do on macOS. The main thread no longer pushes a blocking message into its own mailbox.
LinuxSettingsController.applySettings, the creation feed, and the overlay feed inGhosttySurfaceare gone. So areGhosttySurface.feed,GhosttyApp.currentThemeOSC, andthemeOSC/themeResetOSC.ghostty_app_update_configalready propagates the theme to every surface.background=, which re-seeded the terminal default, so OSC 111 reset to the program's color instead of the theme. While the latch is set, the overlay now carries only opacity and font, matching the macOS fix in umputun/agterm#312 for umputun/agterm#309. The choice lives in a new pureLinuxBackgroundOverlayPolicywith unit tests.linux/patches/ghostty-embedded-opengl.patch):ghostty_surface_feedAPI is removed. It existed only in this patch.renderer_healthwas the other main-thread.foreverproducer: on Linux GL,frameCompletedruns on the main thread. Undermust_draw_from_app_threadit now pushes.instantand records the value as pending.App.tickretries pending values afterdrainMailbox. The latest pending value wins, and an older success never clears a newer one. Metal and every other path keep the original.foreverpush.PendingHealth.zighelper with 7 Zig tests against a real 64-slotBlockingQueue.0ba6250. CI's libghostty cache is keyed on the patch hash, so CI rebuilds once.Testing locally:
setup-linux.shkeeps any complete vendored libghostty, andverify-linux-vendor-cache.shdoes not check patch contents. Removeagterm-linux/vendor/ghostty(the link or directory itself) and rerunscripts/setup-linux.shbefore testing, or you test the old library. ThenAGTERM_ATSPI_SCENARIO=theme-many-sessions scripts/test-linux-ui.shruns the reproducer.Behavior changes besides the hang
session background clearreturns to the theme. Before, it stayed on the old color. A live program override is not cleared by config, the same as on macOS.Guarding against regressions
theme-many-sessions, in the full suite:tree, every call bounded at 4s.linux-port(b1ea700f) it fails at the hang step:theme setnever answers, also with a 30s bound.control_json/raw_control_jsontake a per-call timeout, and aTimeoutExpiredis reported as aFAIL:line instead of a traceback..claude/rules/libghostty.mdrecords the config-only theme path and the rule that nothing on the Linux main thread may push.foreverinto the app mailbox.Testing
In the CI image (Swift 6.3.2, zig 0.16.0), with libghostty rebuilt from the new patch:
swift test: AgtermLinux 453 passed, agtermCore 3846 passed.swiftlint lint --strict: clean.scripts/test-linux-ui.sh: 41 scenarios passed, 0 failed.scripts/test-linux-resources.shandscripts/verify-linux-vendor-cache.sh: pass.zig build test -Dapp-runtime=none -Dtest-filter="PendingHealth: ": 78/78, of which 7 are new.libghostty.sohave the same sha256, and neither exportsghostty_surface_feed.Hang check (three theme changes, each followed by
tree):b1ea700f)theme setPixel check under Xvfb (llvmpipe,
prefer-dark), reading renderer-drawn pixels. Each cell is background / foreground (a reverse-video row) / palette red. The program's OSC 11 color is#aa0000, and the session color is#335577. These are representative rows; the full runs also show the Dracula foreground fix on a second session and on an Atom → Dracula switch.At 85% opacity, the two builds' backgrounds differ only in the session-color-cleared and OSC 11 rows. Foreground and red rows keep each build's full-opacity values.
Not verified: a theme preview in the picker followed by cancel, and a live system light/dark switch with a theme pair configured.
Known limitations, not addressed here
Merges cleanly with #45.
🤖 Generated with Claude Code
https://claude.ai/code/session_01UXsFSAnftzk65uhqTTKixZ