Skip to content

harden quit teardown and scale-change font reload#241

Merged
forketyfork merged 2 commits intomainfrom
fix/quit-teardown-lifetime
Feb 24, 2026
Merged

harden quit teardown and scale-change font reload#241
forketyfork merged 2 commits intomainfrom
fix/quit-teardown-lifetime

Conversation

@forketyfork
Copy link
Owner

@forketyfork forketyfork commented Feb 23, 2026

Solution

This hardens two shutdown and resize lifecycles that were vulnerable on error paths.
The runtime now guarantees UI teardown executes at most once, even when both errdefer and defer are active in the same scope.
Font reload during scale changes is now transactional: both replacement fonts are initialized first, and only then are old resources swapped out and released.
Window resize handling is also routed through one ordered path (reload-if-needed, then resize) so changed-scale and unchanged-scale events follow the same control flow.
Targeted tests were added for one-shot teardown, transactional swap behavior, and scale-change resize sequencing including reload failure handling.

Also bumps the zwanzig dependency from v0.10.0 to v0.11.0. Build verified to pass.

Issue linkage: no issue yet for this hotfix fast-path; linkage will be added during mandatory cleanup.

Test plan

  • Launch the app with persisted sessions, open overlays (for example reader/recent folders), then quit via both window close and quit shortcut; verify shutdown completes without a crash.
  • Trigger DPI scale changes (for example by moving between displays with different scaling), then keep interacting with terminals and quit; verify rendering remains stable and no crash occurs.

Issue: Quitting after the session persistence rollout caused crash reports during shutdown, and a follow-up run surfaced another quit-time failure. We also needed a focused audit for similar lifecycle hazards in runtime teardown and resize paths.
Solution: Add a one-shot guard so UI teardown cannot run twice across mixed error and normal unwind paths, and keep persistence finalization explicit at runtime end. Make scale-change font reload transactional so new fonts are acquired before old ones are released, then run resize through a single ordered reload/resize flow. Add targeted runtime tests that lock in teardown guard behavior, transactional swap semantics, and resize behavior for changed, unchanged, and failing reload paths.
@forketyfork forketyfork requested a review from Copilot February 23, 2026 16:51
@forketyfork forketyfork marked this pull request as ready for review February 23, 2026 16:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens runtime shutdown and window-resize/scale-change lifecycles by making UI teardown one-shot, making font reload transactional, and routing resize logic through a single ordered path to avoid error-path resource hazards.

Changes:

  • Add a one-shot teardown guard to ensure UiRoot.deinit() executes at most once across mixed errdefer/defer unwind paths.
  • Refactor DPI scale-change handling to transactionally reload terminal/UI fonts (initialize both first, then swap/deinit old) and unify resize sequencing.
  • Make persistence finalization explicit at the end of run() (with errdefer for error exits), and add targeted unit tests plus architecture notes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/app/runtime.zig Implements guarded UI teardown, transactional font swapping, unified scale-change resize flow, and adds unit tests for the new helpers.
docs/ARCHITECTURE.md Documents the shutdown ordering, one-shot teardown guard, explicit persistence finalization, and transactional font reload/resize sequencing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Issue: The zwanzig dependency was pinned to v0.10.0 and needed updating to the latest release.
Solution: Updated the URL and hash in build.zig.zon to v0.11.0 using zig fetch --save and confirmed the build passes with the new version.
@forketyfork forketyfork merged commit 3d8a530 into main Feb 24, 2026
4 checks passed
@forketyfork forketyfork deleted the fix/quit-teardown-lifetime branch February 24, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants