Repository navigation
fix(linux): stop promoting a split survivor by reparenting it - #39
Merged
Merged
Conversation
A split session whose PRIMARY pane shell exited crashed with a SIGSEGV in
`gtk_widget_get_request_mode`. `closePrimaryPane` promoted the survivor by
clearing both `GtkPaned` slots and re-adding the survivor's host:
gtk_paned_set_start_child(paned, nil)
gtk_paned_set_end_child(paned, nil) // sole ref dropped
gtk_paned_set_start_child(paned, W(survivorHost)) // freed memory relinked
A GTK4 container owns the only reference to a sunk child, so clearing the slot
finalized the host and the re-add linked freed memory into the live tree; the
next frame-clock layout called through a class pointer `g_type_free_instance`
had NULLed. The exception is a container's FOCUS child, which carries a second
reference — which is why the crash only reproduced with the primary focused,
and why it looked intermittent.
Holding a reference across the reparent stops the crash but leaves the promoted
pane BLANK: unparenting a live `GtkGLArea` unrealizes it, GTK destroys its
`GdkGLContext`, and the re-add realizes a new one while libghostty keeps drawing
into the dead one — `GhosttySurface` connects `realize` but no `unrealize`, and
`realize()`'s `createSurface()` no-ops on a live surface, so `refresh()` cannot
repair it. Measured: 0.0 ink, and a byte-identical framebuffer after typing.
So promotion no longer reparents at all. A pane host's paned slot is fixed for
its lifetime: `collapseSplit` frees the DEAD host's slot and shows the survivor,
and `layoutSplit` is the single placement site, deriving the slot pairing from
GTK rather than storing it. A second promotion alternates slots with the same
code. Measured after the change: 0.470 ink, 0.0049 repaint diff.
Because the primary can now occupy the end slot, two role-named contracts had to
follow the model rather than the screen: `splitRatio` converts through
`panedFraction` at all three GTK boundaries so it always means the primary's
share (it previously inverted after a promotion, mis-aiming `--split-ratio` and
`--grow-primary` and coming back mirrored after a relaunch), and `focusPane`
splits into a physical `left:` overload for the arrow keys and palette and a
model `wantSplit:` overload for the dashboard, notification reveal and Ctrl+1/2.
Two related visibility faults are fixed alongside: promoting from a maximized
primary, and closing a maximized split, each left a hidden pane host with no
later `layoutSplit` pass to re-show it — an empty content area over a live shell.
`withWidgetRefHeld` is the one scoped ref hold for any remaining reparent;
`grep -rn withWidgetRefHeld` is the site inventory. The hand-rolled ref/unref
pairs in the zoom and pane-overlay paths are converted to it.
Coverage: a new `split-primary-exit` AT-SPI scenario drives the crash path over
the control API through a re-split and a second promotion, pinning pane identity
by the spawn-baked `AGTERM_PANE_ID`. It must focus the left pane before `exit` —
with the split focused the focus-child reference hides the bug and the scenario
passes on a broken build. `GhosttySurface` now logs when a GLArea is re-realized
over a live surface, which is the only automated signal for the blank-pane class
(AT-SPI asserts structure, never pixels), and the runner gains a `GTK_IS_WIDGET`
assertion tripwire.
Terminal zoom blanks its surface the same way, unchanged on builds predating
this work. It is out of scope here and filed in docs/backlog/.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
melonamin
force-pushed
the
linux-paned-reparent-pr
branch
from
September 3, 2026 02:31
54c4265 to
4dbad33
Compare
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 crash
A split session whose primary pane shell exited crashed with a SIGSEGV in
gtk_widget_get_request_mode.closePrimaryPanepromoted the survivor by clearing bothGtkPanedslots and re-adding the survivor's host:A GTK4 container owns the only reference to a sunk child, so clearing the slot finalized the host and the re-add linked freed memory into the live tree; the next frame-clock layout called through a class pointer
g_type_free_instancehad NULLed. Confirmed against a coredump: panedstart_childa dead pointer,end_childNULL, preceded by sixGTK_IS_WIDGETassertion failures.The exception is a container's focus child, which carries a second reference — which is why this only reproduced with the primary focused, and why it looked intermittent.
Why the obvious fix isn't the fix
Holding a reference across the reparent stops the crash but leaves the promoted pane blank. Unparenting a live
GtkGLAreaunrealizes it, GTK destroys itsGdkGLContext, and the re-add realizes a new one while libghostty keeps drawing into the dead one —GhosttySurfaceconnectsrealizebut nounrealize, andrealize()'screateSurface()no-ops on a live surface, sorefresh()cannot repair it. Measured on that build: 0.0 ink, and a byte-identical framebuffer after typing into the pane.So promotion no longer reparents at all. A pane host's paned slot is fixed for its lifetime:
collapseSplitfrees the dead host's slot and shows the survivor.layoutSplitis the single placement site and derives the slot pairing from GTK (gtk_paned_get_end_child(paned) == primaryWidget) rather than storing it, so a second promotion alternates slots with the same code.Measured after the change: 0.470 ink, 0.0049 repaint diff.
Consequences that had to be handled
Because the primary can now occupy the end slot, two role-named contracts had to follow the model rather than the screen:
splitRatioconverts throughpanedFractionat all three GTK boundaries so it always means the primary's share. Previously it inverted after a promotion, which mis-aimed--split-ratioand--grow-primaryand came back mirrored after a relaunch.focusPanesplits into a physicalleft:overload (arrow keys, palette) and a modelwantSplit:overload (dashboard, notification reveal,Ctrl+1/Ctrl+2, matching upstream macOS).Two related visibility faults are fixed alongside: promoting from a maximized primary, and closing a maximized split, each left a hidden pane host with no later
layoutSplitpass to re-show it — an empty content area over a live shell.withWidgetRefHeldis the one scoped ref hold for any remaining reparent, andgrep -rn withWidgetRefHeldis the site inventory. The hand-rolled ref/unref pairs in the zoom and pane-overlay paths are converted to it. The rule is recorded in.claude/rules/main-loop.md, with the GLArea consequence owned bylibghostty.md.Coverage
split-primary-exitAT-SPI scenario drives the crash path over the control API through a re-split and a second promotion, pinning pane identity by the spawn-bakedAGTERM_PANE_ID. It must focus the left pane beforeexit— with the split focused, the focus-child reference hides the bug and the scenario passes on a broken build.GhosttySurfacelogs when a GLArea is re-realized over a live surface. This is the only automated signal for the blank-pane class, which AT-SPI cannot see (it asserts structure, never pixels).GTK_IS_WIDGETassertion tripwire.Known and out of scope
docs/backlog/linux-zoom-blanks-the-surface.mdwith two candidate fixes.--pane left|right) is unchanged.Testing
swift buildclean;agterm-linuxandagtermCoreunit tests at their pre-existing baselines;make lintzero findings;split-primary-exit,split-exit,dashboard-modal,hidden-toolbarand the full AT-SPI suite run, with all failures matching the recorded pre-existing list for this host. Painting was verified by framebuffer capture in an isolated Xvfb instance, since no automated test can assert it.Note
notification-focusis flaky on the development host in a way that bisects to a file it never executes (adding a blank line flips it green) — a binary-layout timing cliff on atime.sleep(1.0)readiness, not a regression from this change. CI is the authority.make test-appis the macOS-hosted gate and was not runnable here.🤖 Generated with Claude Code