Skip to content

gpui: Defer thermal/keyboard state updates when app is borrowed#49189

Merged
morgankrey merged 2 commits intomainfrom
fix/refcell-thermal-state-retry
Feb 14, 2026
Merged

gpui: Defer thermal/keyboard state updates when app is borrowed#49189
morgankrey merged 2 commits intomainfrom
fix/refcell-thermal-state-retry

Conversation

@morgankrey
Copy link
Contributor

Follow-up to #49187.

Instead of silently skipping updates when try_borrow_mut fails, this PR defers the update by spawning it on the foreground executor. This ensures the state change is eventually processed after the current borrow completes.

This addresses the feedback: "if we pull something out of the event queue asynchronously and the state we want to update is unavailable, either we should put it back in the queue or if that doesn't work, retry in a loop."

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 14, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Feb 14, 2026
Follow-up to #49187. Always spawn the update on the foreground
executor instead of borrowing the app directly in the callback.
This avoids RefCell panics when macOS fires these callbacks
asynchronously while the app is already borrowed.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@morgankrey morgankrey force-pushed the fix/refcell-thermal-state-retry branch from ace1b32 to c27dc9f Compare February 14, 2026 20:19
Adds a non-exhaustive rules file for the GPUI crate, starting with
the platform callback pattern: defer work via ForegroundExecutor
rather than borrowing AppCell directly, since macOS can fire these
callbacks asynchronously while the app is already borrowed.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@morgankrey morgankrey merged commit 99a558f into main Feb 14, 2026
27 checks passed
@morgankrey morgankrey deleted the fix/refcell-thermal-state-retry branch February 14, 2026 20:54
@marcocondrache
Copy link
Contributor

@notpeter sorry for the direct ping, could you please check this fixes the issue on your Intel machine? So I can eventually close the fix I've already had: #49086

@notpeter

This comment was marked as outdated.

@marcocondrache
Copy link
Contributor

@notpeter thank you so much. Yes we need somebody to cherry pick this to the preview channel!

@notpeter
Copy link
Contributor

notpeter commented Feb 15, 2026

Update: new crash for the code which was introduced in this PR.

zed/crates/gpui/src/app.rs

Lines 757 to 762 in 99a558f

.spawn(async move {
let mut cx = app.borrow_mut();
cx.thermal_state_observers
.clone()
.retain(&(), move |callback| (callback)(&mut cx));
})

ERROR [crashes] thread 'main' panicked at /Users/runner/work/zed/zed/crates/scheduler/src/executor.rs:388:13:
local task polled by a thread that didn't spawn it. Task spawned at crates/gpui/src/app.rs:757:26...
ERROR [crashes] triggering a crash to generate a minidump...

@bennetbo
Copy link
Member

/cherry-pick preview

@bennetbo
Copy link
Member

/cherry-pick stable

@zed-zippy
Copy link
Contributor

zed-zippy bot commented Feb 16, 2026

🍒💥 Cherry-pick did not succeed
https://github.com/zed-industries/zed/actions/runs/22054023356

@zed-zippy
Copy link
Contributor

zed-zippy bot commented Feb 16, 2026

🍒💥 Cherry-pick did not succeed
https://github.com/zed-industries/zed/actions/runs/22054031353

marcocondrache added a commit to marcocondrache/zed that referenced this pull request Feb 16, 2026
bennetbo pushed a commit that referenced this pull request Feb 16, 2026
…ed" (#49251)

Reverts #49189
Reverts #49187

#49189 introduces a panic
(#49189 (comment),
#49181 (comment))
#49187 It's wrong since it leads to missing updates

The original crash should be fixed with #49086

cc: @bennetbo 

Release Notes:

- N/A
rtfeldman pushed a commit that referenced this pull request Feb 17, 2026
Follow-up to #49187.

Instead of silently skipping updates when `try_borrow_mut` fails, this
PR defers the update by spawning it on the foreground executor. This
ensures the state change is eventually processed after the current
borrow completes.

Release Notes:

- N/A
rtfeldman pushed a commit that referenced this pull request Feb 17, 2026
…ed" (#49251)

Reverts #49189
Reverts #49187

#49189 introduces a panic
(#49189 (comment),
#49181 (comment))
#49187 It's wrong since it leads to missing updates

The original crash should be fixed with #49086

cc: @bennetbo 

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants