{"record":{"id":"6c72b178cf336572","repo":"zed-industries/zed","slug":"app-was-released-before-async-operation-completed","errorCode":null,"errorMessage":"app was released before async operation completed","messagePattern":"app was released before async operation completed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/app/async_context.rs","lineNumber":32,"sourceCode":"\n/// An async-friendly version of [App] with a static lifetime so it can be held across `await` points in async code.\n/// You're provided with an instance when calling [App::spawn], and you can also create one with [App::to_async].\n///\n/// Internally, this holds a weak reference to an `App`. Methods will panic if the app has been dropped,\n/// but this should not happen in practice when using foreground tasks spawned via `cx.spawn()`,\n/// as the executor checks if the app is alive before running each task.\n#[derive(Clone)]\npub struct AsyncApp {\n    pub(crate) app: Weak<AppCell>,\n    pub(crate) background_executor: BackgroundExecutor,\n    pub(crate) foreground_executor: ForegroundExecutor,\n}\n\nimpl AsyncApp {\n    fn app(&self) -> std::rc::Rc<AppCell> {\n        self.app\n            .upgrade()\n            .expect(\"app was released before async operation completed\")\n    }\n}\n\nimpl AppContext for AsyncApp {\n    fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T> {\n        let app = self.app();\n        let mut app = app.borrow_mut();\n        app.new(build_entity)\n    }\n\n    fn reserve_entity<T: 'static>(&mut self) -> Reservation<T> {\n        let app = self.app();\n        let mut app = app.borrow_mut();\n        app.reserve_entity()\n    }\n\n    fn insert_entity<T: 'static>(\n        &mut self,","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui/src/app/async_context.rs#L14-L50","documentation":"A lifetime guard on AsyncApp: it holds only a Weak reference to the AppCell, and upgrading fails (panicking with 'app was released before async operation completed') when a foreground task resumes after the App was dropped. In a normal application lifecycle the executor shuts down before the app is freed so this cannot fire; it occurs when AsyncApp/AsyncWindowContext is held beyond app teardown — e.g. a detached task or test harness outliving the App.","triggerScenarios":"Thrown at crates/gpui/src/app/async_context.rs:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Return Err from AsyncApp methods when the weak upgrade fails instead of panicking, letting tasks exit gracefully","Ensure tasks are cancelled (not detached) before the App is dropped — track Tasks in the owner or use the executor's shutdown","In tests, keep the TestAppContext alive until all spawned tasks complete"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}