fix: bound renderer mailbox drain turns

Merged
AU
4mo ago
+50-4

Summary

  • bound each renderer wake to the ordinary mailbox depth present at the start of the turn
  • consume coalesced lifecycle state and render before processing work that arrived during that batch
  • explicitly re-wake when producers added work during the drain, since their notifications may coalesce with the active callback

Root cause

https://github.com/manaflow-ai/ghostty/commit/ca21db1bb8361bf5b58a848dd823b6ee24a5d9fa moved visibility/focus/display ID to latest-value slots consumed after the ordinary mailbox. The mailbox loop could consume producer refills indefinitely, starving both the lifecycle take and the render step under continuous terminal echo. This caused https://github.com/manaflow-ai/cmux/issues/8808.

Validation

  • zig build test -Dtest-filter="count snapshots one bounded consumer turn"
  • zig build test -Dtest-filter="surface lifecycle state bypasses"
  • zig build test -Dtest-filter="visibility drain"
  • git diff --check

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Bound the renderer mailbox drain to a per-turn snapshot to prevent starvation and keep lifecycle updates and rendering responsive under sustained input. Fixes visible typing lag during heavy terminal echo.

  • Bug Fixes
    • Added count() to the blocking queue to snapshot length for a bounded consumer turn.
    • Mailbox drain now processes only messages present at turn start; applies latest lifecycle state right after.
    • If producers add work mid-drain, explicitly re-wakes the renderer to avoid coalesced notification loss.
    • Added a unit test to verify bounded-turn behavior.