Repository navigation
fix: drain app mailbox while freeing terminal surfaces - #819
Merged
umputun merged 1 commit intoOct 27, 2026
Merged
Conversation
bot-rogerthat
force-pushed
the
fix/surface-mailbox-shutdown
branch
2 times, most recently
from
October 26, 2026 15:19
0fef913 to
d7dbcfe
Compare
bot-rogerthat
marked this pull request as ready for review
October 26, 2026 15:49
umputun
requested changes
Oct 26, 2026
umputun
left a comment
Owner
There was a problem hiding this comment.
one ordering issue left in the patch, plus a few small setup/doc things.
scripts/ghostty-patches/0001-drain-mailbox-during-surface-teardown.patch:324-drain.finish()runs beforeself.renderer.deinit(), but up to 3 Metal frames can still be in flight after the renderer thread joins. On a health changeframeCompleted(renderer/generic.zig:1915) pushesrenderer_healthinto the app mailbox with.foreverbeforereleaseFrame, andSwapChain.deinitwaits for those permits on the main thread, so a GPU error near a close while other surfaces refill the mailbox freezes every window again. Fix: movedrain.finish()to right afterself.renderer.deinit()and widen the README wording to cover in-flight frames. Upstream 14444 has the same ordering, so it is worth noting there too.scripts/ghostty-patches/README.md:13- "remove the patch" as written breaks setup: with no*.patchleft,setup.sh:36fails on the unmatched glob underset -euo pipefail. Pls spell out the removal: either keepGHOSTTY_STAMP="$GHOSTTY_REV"or restore both the stamp comparison (setup.sh:69) and the write (setup.sh:181), and drop the digest line and the apply loop. Also say that 14444 only counts as equivalent once its drain also outlivesrenderer.deinit().scripts/setup.sh:160- the Zig teardown test build adds about 4 minutes to every cold libghostty build, on every machine and every CI cache miss. Pls move it to the README regeneration steps next togit apply --checkandzig fmt --check, the same wayscripts/zmx-patches/README.mdhandleszig build test, and drop the README line saying the tests run during the source build. The Release teardown harness in CI stays as is.ARCHITECTURE.md:62and thesetup.sh:12-15header still describe an unpatched build that only a revision change rebuilds. Pls mention the patch step and the patch digest in the stamp.docs/backlog/surface-free-deadlock-waits-on-a-ghostty-pin-bump.md- with the backport in, the item still reads as an open freeze. Pls retitle it to the remaining work: drop the backport once a pin carries an equivalent fix, with the three CI cases as the re-test.
bot-rogerthat
marked this pull request as draft
October 26, 2026 20:31
bot-rogerthat
force-pushed
the
fix/surface-mailbox-shutdown
branch
from
October 26, 2026 20:31
d7dbcfe to
78dce42
Compare
bot-rogerthat
force-pushed
the
fix/surface-mailbox-shutdown
branch
from
October 26, 2026 21:06
78dce42 to
63bd2da
Compare
bot-rogerthat
marked this pull request as ready for review
October 26, 2026 21:31
umputun
added a commit
that referenced
this pull request
Oct 27, 2026
The symlink and build-stamp lines extended in #819 ran to about 120 columns and left a stray fragment, against the file's semantic-line width. Rewrapped with no wording change.
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.
Closing a busy terminal surface can freeze every agterm window. The app thread joins the surface's workers while one of those workers is blocked posting into the full 64-slot app mailbox, which only the app thread drains. The captured 0.37.0 hang was traced to
processExitCommonposting.child_exitedwith.forever. One- and eight-producer title-spam cases also hang on the installed Release; the eight-idle-surface control passes.Backport the teardown drain from ghostty-org/ghostty#14444 to the pinned
683d8dblibghostty. A temporary consumer keeps the mailbox moving until the closing surface's workers and in-flight Metal frames have finished, preserving other surfaces' messages for the next app tick. This also lets a frame completion report a health change before releasing its swap-chain permit. The backport retains the pin's redraw messages, removes stale deferred messages across consecutive closes, frees owned payloads when discarding messages, and bounds the final drain so continuing output cannot keep it alive indefinitely.setup.shand the GhosttyKit cache include the patch digest. The patch README describes how to run the Zig teardown regressions when updating the patch; CI closes a surface in isolated Release instances with one title producer, eight title producers, and eight idle surfaces. Remove the backport once the pin includes an equivalent upstream fix.The full CI run passed for the final revision, including the Release build, all three surface-close scenarios, unit tests, strict SwiftLint, 45 session-host fixtures and 1,435 hosted tests with eight skips. The Zig teardown tests, including a simulated frame completion blocked on the mailbox, passed in a separate validation run against the identical patch. That run reached its 30-minute job limit during the later hosted tests; the final run passed after removing the temporary Zig invocation from
setup.sh.Related to ghostty-org/ghostty#14245