Skip to content

fix(gpui): defer window callbacks AppKit sends while the app is mid-update - #2760

Open
richiemcilroy wants to merge 1 commit into
mainfrom
fix/gpui-deferred-reentrant-callbacks
Open

richiemcilroy wants to merge 1 commit into
mainfrom
fix/gpui-deferred-reentrant-callbacks

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Bug

Every launch, and every time the recording controls window opens, logs ERROR gpui::window: RefCell already borrowed (1–4 per launch). Seen on nightly 0.6.2-nightly.202610200310 (before any of today's gpui changes), nightly …0640 and the 0.6.1 build, with an upgraded user's saved window state.

The text comes from AsyncApp::update_window, whose app.try_borrow_mut() fails because AppKit called a window delegate synchronously while the app was already inside an update. Cap opens and positions windows inside updates (restoring the camera bubble's saved position, placing the recording controls, restoring the main window), and AppKit answers those setFrame: / orderFront: calls on the spot:

AppKit callback (gpui_macos/src/window.rs) gpui closure (gpui/src/window.rs) What was lost
window_did_move on_moved → bounds_changed the window's bounds stayed stale
set_frame_size, update_window_scale_factor on_resize → bounds_changed layout at the old size until the next resize
view_did_change_effective_appearance on_appearance_changed the appearance change
display_layer, the becomes-key frame on_request_frame the frame. With #2740 a stopped window could wait for a frame that never comes

Activation already goes through the foreground executor (window_did_change_key_status), which is why it never showed up.

Fix

  • update_window_or_defer: on_resize, on_moved, on_appearance_changed and on_button_layout_changed now apply their update, and when the only failure is that the app is borrowed, they retry once on the next turn of the run loop. The updates are idempotent (bounds_changed re-reads the platform bounds), so a deferred one converges to the current state. Any other error (window closed, app quitting) is logged as before.
  • on_request_frame: a frame that fails because the app is borrowed now calls FramePacer::missed_frame, which asks for another single frame (FrameRequests::Once) while requests are stopped. A window that closed still returns quietly (fix(gpui): end a frame quietly when its window has already closed #2734).

Tests

New frame_pacer_tests:

  • a_frame_missed_while_stopped_asks_for_another
  • a_frame_missed_while_running_asks_for_nothing

These are gpui crate tests, which Cap CI does not run. They have not been run for this PR, because the Mac this was written on is off-limits for local builds right now. The pacer suite last passed 212/212 on #2740.

CI compiles the patched gpui on macOS (arm and Intel), Linux and Windows. ./scripts/prepare-gpui-dependency.sh verifies the stack, and its tests pass 8/8.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable defects were found.

Summary

Updates the GPUI patch to preserve window notifications that arrive during an app update.

  • Window updates retry when the app is already busy.
  • A missed frame gets another chance to draw.

Review was static. The upstream GPUI checkout was unavailable, so patched builds and tests were not run.

Reviews (1) · Last reviewed commit: "fix(gpui): defer window callbacks AppKit..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cap-status Ready Ready Preview Oct 20, 2026 12:28pm UTC

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

This branch was successfully deployed

2 active deployments
Preview – cap-web — 81180640 Deployed Oct 20, 2026 by vercel[bot]
Preview – cap-status — 81180640 Deployed Oct 20, 2026 by vercel[bot]
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