Revert owned userdata leasing and restore synchronous teardown

Merged
LA
4mo ago
+227-444

Reverts https://github.com/manaflow-ai/ghostty/pull/140 while preserving the bounded renderer drain from https://github.com/manaflow-ai/ghostty/pull/135 and https://github.com/manaflow-ai/ghostty/pull/136 that fixes https://github.com/manaflow-ai/cmux/issues/8808.

PR 140 changed the embedder contract by adding atomic userdata leases around every host callback. That broad ownership layer is unnecessary if ghostty_surface_free keeps its established contract: stop renderer and IO callbacks synchronously before returning.

This PR restores borrowed callback userdata, keeps an outer surface allocation alive only for an in-flight app action, and always tears down the live core synchronously. The regression test is a separate commit before the fix.

Validation:

  • Zig 0.15.2 formatting passed on a 48 GB fleet Mac
  • focused embedded teardown, action lifetime, and redraw tests passed
  • full GitHub checks required before merge

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

Reverts owned userdata leasing and restores synchronous surface teardown. ghostty_surface_free now stops renderer and IO before returning and serializes teardown with cross-thread actions, while keeping the bounded renderer drain that fixes cmux issue 8808.

  • Bug Fixes

    • Teardown is synchronous and waits for actions running on other threads before destroying core state.
    • Reentrant free on the action thread skips the wait; only the outer allocation is retained until the callback returns.
    • Keeps PTY tee callback fields synchronized with the IO setter.
    • Adds tests for retained-action teardown and cross-thread free during redraw.
  • Migration

    • Removes ghostty_userdata_release_cb and ghostty_surface_new_with_owned_userdata from the C API.
    • Use ghostty_surface_new and manage callback userdata yourself.
    • Callbacks now receive the original userdata directly; no internal leases.