zed-industries/zed · error

The entity must be alive if we have a entity context

Error message

The entity must be alive if we have a entity context

What it means

Context<'a, T>::entity upgrades the stored WeakEntity<T>. A Context only exists while its entity is being updated, so the weak handle must be upgradeable; a panic here means the entity was released mid-update, e.g. it dropped itself (cx.emit into release) or was otherwise removed during its own context's lifetime.

Source

Thrown at crates/gpui/src/app/context.rs:54

        self.app
    }
}

impl<'a, T: 'static> Context<'a, T> {
    pub(crate) fn new_context(app: &'a mut App, entity_state: WeakEntity<T>) -> Self {
        Self { app, entity_state }
    }

    /// The entity id of the entity backing this context.
    pub fn entity_id(&self) -> EntityId {
        self.entity_state.entity_id
    }

    /// Returns a handle to the entity belonging to this context.
    pub fn entity(&self) -> Entity<T> {
        self.weak_entity()
            .upgrade()
            .expect("The entity must be alive if we have a entity context")
    }

    /// Returns a weak handle to the entity belonging to this context.
    pub fn weak_entity(&self) -> WeakEntity<T> {
        self.entity_state.clone()
    }

    /// Arranges for the given function to be called whenever [`Context::notify`] is
    /// called with the given entity.
    pub fn observe<W>(
        &mut self,
        entity: &Entity<W>,
        mut on_notify: impl FnMut(&mut T, Entity<W>, &mut Context<T>) + 'static,
    ) -> Subscription
    where
        T: 'static,
        W: 'static,
    {

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Find code that releases the entity during its own update (self-drop, releasing via a callback)
  2. Avoid dropping the last strong handle to the entity from within its own context callbacks
  3. Use weak_entity() APIs if the entity may legitimately be gone
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui/src/app/context.rs:53 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/c26c75c338a4f5b5. Report an issue: GitHub.