fix: guard inherited terminal config against stale surfaces

Merged
AU
8mo ago
+253-21

Summary

  • Fixes #2024.
  • Add debug-only regression coverage for split creation and new terminal creation when the inheritance source wrapper still holds a freed native Ghostty surface pointer.
  • Track runtime surface ownership, quarantine stale or mis-owned pointers before inherited-config/font lookups, and route both workspace and new-workspace inheritance through the guarded access path.
  • Keep the regression in a two-commit shape: commit 1 adds the failing regression, commit 2 adds the production fix.

Testing

  • ./scripts/setup.sh
  • ./scripts/reload.sh --tag issue-2024-config-crash
  • Manually verified that the tagged debug app built and launched successfully.
  • Did not run unit/UI tests locally; repo policy says to run them in GitHub Actions / VM.

Demo Video

For UI or behavior changes, include a short demo video (GitHub upload, Loom, or other direct link).

  • Video URL or attachment: N/A

Review Trigger (Copy/Paste as PR comment)

@codex review
@coderabbitai review
@greptile-apps review
@cubic-dev-ai review

Checklist

  • I tested the change locally
  • I added or updated tests for behavior changes
  • I updated docs/changelog if needed
  • I requested bot reviews after my latest commit (copy/paste block above or equivalent)
  • All code review bot comments are resolved
  • All human review comments are resolved

Summary by cubic

Fixes #2024 by guarding inherited terminal config against stale Ghostty surfaces and adding safe fallbacks. Prevents crashes when creating splits or new terminals by validating surface ownership/liveness and using recorded font size when the source is stale.

  • Bug Fixes
    • Track runtime surface ownership in TerminalSurfaceRegistry with pointer→owner UUID; register on create and unregister on teardown/free/deinit.
    • Add liveSurfaceForGhosttyAccess(reason:) to verify registry ownership and liveness; quarantine stale/mis-owned pointers, close the portal, and release callbacks.
    • Route all inheritance through the guarded path, including split/new-terminal, new workspace (TabManager), and font-size probes.
    • Add cmuxSurfacePointerAppearsLive/cmuxPointerAppearsLive checks for surfaces and unretained QuickLook font pointers; verify the surface before font probes.
    • When a source is quarantined, fall back to rooted or last-known font size; add debug-only tests that free the native pointer and confirm split/new-terminal creation succeeds while quarantining the stale wrapper.

Summary by CodeRabbit

  • Bug Fixes

    • Safer terminal surface lifecycle handling: stale or freed native surfaces are quarantined and skipped to prevent crashes during workspace operations.
    • Live-surface access now enforces validation before use, improving reliability of terminal actions and config inheritance.
  • Tests

    • Added debug-only regression tests that simulate freed surfaces to verify quarantine and fallback behavior.