Skip to content

fix(native): fix re-entrant settings close, updates test teardown, and settle offscreen captures - #466

Merged
rynfar merged 1 commit into
nativefrom
fix/native-bug202-settings-close
Nov 20, 2026
Merged

rynfar merged 1 commit into
nativefrom
fix/native-bug202-settings-close

Conversation

@rynfar

@rynfar rynfar commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Part of #202

Summary

  1. Fix re-entrant Entity<SettingsView>::update panic on Settings close (apps/native/crates/app/src/settings/mod.rs):
    • SettingsView::on_close ran inside an active SettingsView entity update and called finish_close(window, cx), which called view.update(cx, ...) on the same SettingsView entity to cancel appearance_ui.import, panicking with cannot update t3_native::settings::SettingsView while it is already being updated.
    • Split clear_closed_host(window, cx) and SettingsView::cancel_pending_import(&mut self, cx) so external callers (close, tests via finish_close) still update SettingsView to cancel pending imports before clearing Host, while SettingsView::on_close cancels pending imports directly on &mut self without re-borrowing the entity.
  2. Fix HeadlessAppContext AppState handle leak in updates::tests (apps/native/crates/app/src/updates/tests.rs):
    • updates::tests::disconnected_saved_environment_uses_saved_label dropped HeadlessAppContext without stopping the AppState pump or draining parked tasks, triggering GPUI's LeakDetector panic.
    • Added state.update(&mut cx, |state, _| state.stop_pump()); drop(_loaded); drop(state); cx.run_until_parked(); teardown so updates::tests passes 11/11 under --features snapshot.
  3. Investigate #202 and harden offscreen capture settling (apps/native/crates/app/src/snapshot.rs):
    • Audited pinned zeronsh/zui (667d0aaf9531d2d1b2d0674a5e55f977df1b09f6):
      • Ruled out monochrome glyph eviction (MetalAtlas::remove only runs via Window::drop_image for polychrome_textures), LineLayoutCache (immutable Arc<LineLayout> two-frame swap), and Scene::replay / BoundsTree / BatchIterator primitive loss. Verified multi-page monochrome atlas overflow (3 textures), locale switching (-AppleLocale lt_LT / ug_CN), Local ACP dark/light scroll, and split .cached() sidebar + ThreadView + scrollable Markdown preview.
      • Identified two concrete offscreen-capture settling hazards in snapshot.rs: (a) the final capture issued a single window.refresh() immediately before cx.capture_screenshot(window) without draining on_next_frame callbacks (simulate_next_frame) or re-refreshing if a draw/effect queued follow-up work; (b) --motion-frames called capture_screenshot directly after pump without window.refresh().
      • Also noted upstream zeronsh/zui (667d0aa) offscreen hazards that require an upstream zui patch (hence Part of #202 rather than closing): MacWindow::render_to_image (gpui_macos/src/metal_renderer.rs:657-748) uses a live CAMetalLayer (set_maximum_drawable_count(2)) on an orderFront_ offscreen NSWindow without an objc::rc::autoreleasepool wrapper (unlike MetalRenderer::draw) or blit.synchronize_resource for non-unified GPUs (unlike render_scene_to_image), while MacWindow::frame_requester still arms CVDisplayLink when visible; and TestWindow::window_handle (gpui/src/platform/test/window.rs:50) is unimplemented!(), blocking full-app migration (gpui_component::Root / Input) to HeadlessAppContext / MetalHeadlessRenderer.
    • Added settle_and_capture in snapshot.rs (bounded simulate_next_frame + run_until_parked + full window.refresh(), preserving selection, virtualization, and all bounded caches) and window.refresh() before each --motion-frames readback.
    • Added deterministic --features snapshot regression test snapshot::tests::offscreen_capture_retains_static_and_cached_text_after_scroll_and_refresh verifying that a .cached() static sidebar and populated ThreadView retain visible non-background text pixels across preview scroll (both cached replay and full refresh) and Light/Dark theme cycling, with zero .png artifacts committed.

Verification

  1. vp fmt --check apps/native/parity/LEDGER.md: PASS
  2. node apps/native/scripts/gen-theme.ts --check: PASS
  3. node apps/native/conformance/generate.ts --check: PASS
  4. node --test apps/native/parity/sync.test.ts: 47 passed, 0 failed
  5. CARGO_INCREMENTAL=0 cargo clippy --manifest-path apps/native/Cargo.toml --workspace --all-targets -- -D warnings: PASS (0 warnings)
  6. CARGO_INCREMENTAL=0 cargo test --manifest-path apps/native/Cargo.toml -p t3-core: 1,883 unit + 8 conformance = 1,891 passed, 0 failed
  7. CARGO_INCREMENTAL=0 cargo test --manifest-path apps/native/Cargo.toml -p t3-client -- --test-threads=1: 171 passed, 0 failed
  8. T3_NATIVE_HOME=$(mktemp -d) CARGO_INCREMENTAL=0 cargo test --manifest-path apps/native/Cargo.toml -p t3-native -- --test-threads=1: 222 passed, 0 failed
  9. T3_NATIVE_HOME=$(mktemp -d) CARGO_INCREMENTAL=0 cargo test --manifest-path apps/native/Cargo.toml -p t3-native --features snapshot -- --test-threads=1 updates::tests snapshot: 23 passed, 0 failed (11/11 updates::tests + new #202 regression test)
  10. CARGO_INCREMENTAL=0 cargo build --manifest-path apps/native/Cargo.toml -p t3-native: PASS

Built with Antigravity

@rynfar
rynfar merged commit 4975bee into native Nov 20, 2026
2 checks passed
@rynfar
rynfar deleted the fix/native-bug202-settings-close branch November 20, 2026 09:04
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.

1 participant