{"record":{"id":"c337654e0e5f3104","repo":"zed-industries/zed","slug":"buffer-edited-while-formatting-aborting","errorCode":null,"errorMessage":"Buffer edited while formatting. Aborting","messagePattern":"Buffer edited while formatting\\. Aborting","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/project/src/lsp_store.rs","lineNumber":16544,"sourceCode":"\n    fn update_status(&self, server_name: LanguageServerName, status: language::BinaryStatus) {\n        self.language_registry.update_lsp_binary_status_for_entity(\n            self.status_source_id(),\n            server_name,\n            status,\n        );\n    }\n\n    fn registered_lsp_adapters(&self) -> Vec<Arc<dyn LspAdapter>> {\n        self.language_registry\n            .all_lsp_adapters()\n            .into_iter()\n            .map(|adapter| adapter.adapter.clone() as Arc<dyn LspAdapter>)\n            .sorted_by_key(|adapter| adapter.name())\n            .collect()\n    }\n\n    async fn language_server_download_dir(&self, name: &LanguageServerName) -> Option<Arc<Path>> {\n        let dir = self.language_registry.language_server_download_dir(name)?;\n\n        if !dir.exists() {\n            smol::fs::create_dir_all(&dir)\n                .await\n                .context(\"failed to create container directory\")\n                .log_err()?;\n        }\n\n        Some(dir)\n    }\n\n    async fn read_text_file(&self, path: &RelPath) -> Result<String> {\n        let entry = self\n            .worktree\n            .entry_for_path(path)\n            .with_context(|| format!(\"no worktree entry for path {path:?}\"))?;\n        let abs_path = self.worktree.absolutize(&entry.path);","sourceCodeStart":16526,"sourceCodeEnd":16562,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/project/src/lsp_store.rs#L16526-L16562","documentation":"lsp_store applies formatting as one undo transaction: after the first edits establish a text::TransactionId, every follow-up batch goes through extend_formatting_transaction, which requires the buffer's topmost undo transaction to still be that same formatting transaction (crates/project/src/lsp_store.rs:15219). If any other edit landed in between, the ids no longer match and the remaining edits are aborted so stale formatting never clobbers user edits.","triggerScenarios":"Something edits the buffer between the first formatting edit and a later extend_formatting_transaction call - typically the user typing while format-on-save is still applying LSP edits, or a second language server racing to format the same buffer.","commonSituations":"Slow language servers returning edits in several responses while the user keeps typing; format-on-save combined with aggressive auto-save; prettier and a linter both configured to format.","solutions":["Re-trigger the format/save - the next attempt starts a fresh transaction","Avoid editing while format-on-save is in flight; the abort is by design and harmless","If it recurs constantly, check that two language servers are not both formatting on save, and disable format_on_save for one of them"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match format_buffer(buffer, cx).await {\n    Err(e) if e.to_string().contains(\"Buffer edited while formatting\") => {\n        // user typed mid-format; re-run once against the now-current buffer\n        format_buffer(buffer, cx).await\n    }\n    other => other,\n}","preventionTips":["Treat this abort as a signal to retry, not a bug to fix","Configure exactly one formatter per buffer to avoid racing transactions","Debounce format-on-save so edits and format requests rarely interleave"],"tags":["formatting","lsp","buffer","race-condition","undo-transaction"],"backgroundTag":"optimistic-concurrency-conflict","analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}