Collapse spinner-frame terminal titles at the source to fix Pi "Working…" freeze (#6507)

Closed
AU
2mo ago
+293-13

Fixes #6507

Symptom

After Pi (or any coding agent) runs in a cmux terminal, the second and later prompts get stuck indefinitely at "Working…", and macOS Console logs repeated SwiftUI faults from the cmux process:

NSHostingView is being laid out reentrantly while rendering its SwiftUI content.
This is not supported and the current layout pass will be skipped.

Root cause

This is the same reentrant-layout fault family as #4735 ("burst of NSHostingView reentrant-layout faults" → wedged UI) and #6291 (spinner titles make the sidebar unresponsive).

When an agent or CLI tool animates its terminal title with a leading Unicode Braille spinner glyph on every animation frame (e.g. ⠋ Working…, ⠙ Working…, ⠹ Working…, …), Ghostty forwards each frame as a distinct .ghosttyDidSetTitle post. There is no dedup at the source, so every frame fans out to:

  • TabManager.enqueuePanelTitleUpdate (panel-title coalescer), and
  • WindowToolbarController command-text updater, and
  • a sidebar re-render (the workspace row title changed).

A steady 10–30 fps spinner therefore thrashes the main-thread layout. On macOS 15.x (and intermittently 26.x) that surfaces as the reentrant NSHostingView faults above; the wedged main thread makes the terminal stop repainting and queued work back up, so the agent looks frozen at "Working…" even though its process is alive (matching the reporter's cmux top, which showed Pi still running).

Note: the reporter's cmux tree snapshot shows a settled title (π - cmux-orchestrator). cmux tree captures the title after it coalesces — it does not show the per-frame churn that floods the layout path while the agent is mid-turn.

Fix

GhosttyNSView now runs each raw title through a per-surface TerminalTitleChurnFilter inside the already-deferred main-actor title post (the DispatchQueue.main.async was already there as a reentrancy guard):

  1. Collapse — strip the leading run of Braille spinner glyphs (U+2800–U+28FF) plus the whitespace separating them from their label, so every animation frame maps to the same stable string.
  2. Dedup — drop a frame whose stable label equals the one last dispatched for that surface, so a steady spinner posts once instead of once per frame.

Both reductions are lossless for the settled title the user actually reads. The collapse is scoped to Braille on purpose: unlike |, /, -, *, ▶, ●, …, Braille patterns never legitimately lead a human-readable terminal title, so stripping them can't corrupt a real one. This is the single highest-leverage chokepoint — killing the churn here stops it reaching both the panel-title coalescer and the toolbar updater, and the sidebar re-render.

This generalizes the analysis in #6291 with a per-surface dedup layer and lands it at the .ghosttyDidSetTitle source.

Tests

Two-commit red/green per repo policy (CI proves the test catches the bug):

  • Commit 1 adds TerminalTitleChurnFilterTests plus a deliberately no-op collapseSpinnerFrames → the suite goes red.
  • Commit 2 adds the real collapse + source dedup → green.

Coverage: braille spinner frames collapse to one stable label; a steady spinner emits exactly one dispatch; distinct labels stay distinct; non-leading braille and plain titles are preserved (trim only); pure-spinner frames don't blank a prior label; identical titles dedup. The new test file is wired into cmux.xcodeproj (verified by lint-pbxproj-test-wiring.sh).

Reproduction note

The reentrant-layout fault is macOS-15.7.8-timing-dependent (the #4735 reporter likewise could not give a 100% reliable repro), and this machine runs macOS 26, so I could not reproduce the end-to-end freeze locally. The fix targets a confirmed contributor to the documented fault family with a deterministic unit test for the churn-reduction logic; it does not touch typing-latency-sensitive or portal hot paths.

Localization

No user-facing static strings changed — the only behavioral change is to dynamic terminal-title content (stripping spinner glyphs from what's displayed), which is not a localized UI string. No Localizable.xcstrings / web message-catalog entries needed.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Collapses animated Braille spinner frames in terminal titles and dedups per surface on the main actor to stop cmux freezing at “Working…” and reduce SwiftUI reentrant layout churn (fixes #6507). Only stable labels are dispatched; pure spinner frames are dropped, and dispatch order is preserved.

  • Bug Fixes
    • Added TerminalTitleChurnFilter in CmuxTerminalCore (@MainActor): strips leading Braille (U+2800–U+28FF) + separator whitespace; preserves plain titles and non‑leading Braille; drops glyph‑only frames; per‑surface dedup keyed by surface UUID. Tests in CmuxTerminalCoreTests.
    • Integrated into GHOSTTY_ACTION_SET_TITLE: capture tabId/surfaceID, enqueue raw titles, and drain via a single @MainActor FIFO task to keep callback order and prevent reentrant layout; filter in GhosttyNSView; post only non‑nil stable titles; re‑dispatch on surface change.

Summary by CodeRabbit

  • Bug Fixes
    • Reduced unnecessary terminal title updates by stabilizing animated spinner-driven titles and coalescing rapid per-surface title changes.
    • Improved title-change notifications by suppressing duplicate consecutive titles and preventing transient blank titles, while still dispatching real changes.
  • Tests
    • Added unit tests to verify spinner glyph title stabilization, suppression of redundant/blank emissions, and correct deduplication behavior across repeated titles and different terminal surfaces.