zed-industries/zed · error

All windows should be off the stack when flushing effects

Error message

All windows should be off the stack when flushing effects

What it means

An executor invariant during effect flushing: when GPUI flushes deferred effects (new-entity observers, etc.) it asserts the window stack is empty — every window pushed for effect execution has been popped. The expect fires if a window was pushed but not popped (an effect handler leaked its window context or errored mid-way), meaning effect flush ran while a window context was still active — an internal framework bug, not application logic.

Source

Thrown at crates/gpui/src/app.rs:1857

                } else {
                    true
                }
            });
    }

    fn apply_refresh_effect(&mut self) {
        for window in self.windows.values_mut() {
            if let Some(window) = window.as_deref_mut() {
                window.refreshing = true;
                window.invalidator.set_dirty(true);
            }
        }
    }

    fn apply_notify_global_observers_effect(&mut self, type_id: TypeId) {
        self.pending_global_notifications.remove(&type_id);
        self.global_observers
            .clone()
            .retain(&type_id, |observer| observer(self));
    }

    fn apply_defer_effect(&mut self, callback: Box<dyn FnOnce(&mut Self) + 'static>) {
        callback(self);
    }

    fn apply_entity_created_effect(
        &mut self,
        entity: AnyEntity,
        tid: TypeId,
        window: Option<WindowId>,
    ) {
        // Seed the entity's current window from its creation context so
        // `with_window` resolves correctly before the entity has ever been
        // rendered.
        if let Some(id) = window {
            self.current_window_by_entity.insert(entity.entity_id(), id);

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Use a guard object (Drop pops the window) so a panic or early return in an effect handler cannot leave a window on the stack
  2. Recover by popping the stale window and logging the imbalance instead of aborting
  3. Add tests that run effect flush after handlers that early-return, catching stack imbalance in CI
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui/src/app.rs:1820 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/b4d378cd1b24a3c1. Report an issue: GitHub.