{"record":{"id":"6dc68873bf88ac90","repo":"astral-sh/ruff","slug":"document-controller-not-available-at-uri","errorCode":null,"errorMessage":"Document controller not available at `{uri}`","messagePattern":"Document controller not available at `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_server/src/session/index.rs","lineNumber":352,"sourceCode":"    }\n\n    pub(super) fn client_settings(&self, key: &DocumentKey) -> Option<Arc<ClientSettings>> {\n        let uri = self.uri_for_key(key)?;\n        let WorkspaceSettings {\n            client_settings, ..\n        } = self.settings_for_uri(uri)?;\n        Some(client_settings.clone())\n    }\n\n    fn document_controller_for_key(\n        &mut self,\n        key: &DocumentKey,\n    ) -> crate::Result<&mut DocumentController> {\n        let Some(uri) = self.uri_for_key(key).cloned() else {\n            anyhow::bail!(\"Tried to open unavailable document `{key}`\");\n        };\n        let Some(controller) = self.documents.get_mut(&uri) else {\n            anyhow::bail!(\"Document controller not available at `{uri}`\");\n        };\n        Ok(controller)\n    }\n\n    fn uri_for_key<'a>(&'a self, key: &'a DocumentKey) -> Option<&'a Uri> {\n        match key {\n            DocumentKey::Notebook(path) | DocumentKey::Text(path) => Some(path),\n            DocumentKey::NotebookCell(uri) => self.notebook_cells.get(uri),\n        }\n    }\n\n    fn settings_for_uri(&self, uri: &Uri) -> Option<&WorkspaceSettings> {\n        if let Ok(path) = uri.to_file_path() {\n            self.settings_for_path(&path)\n        } else {\n            // If there's only a single workspace, use that configuration for an untitled document.\n            if self.settings.len() == 1 {\n                tracing::debug!(","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_server/src/session/index.rs#L334-L370","documentation":"In `document_controller_for_key`, after the key maps to a URI, the server fetches a mutable controller from `self.documents`. If the URI is known but has no controller entry, the index is inconsistent and the server bails. This is the update-path counterpart of error 85.","triggerScenarios":"Calling `update_text_document` or `update_notebook_document` with a key whose URI exists in the key-to-URI mapping but is absent from `self.documents`.","commonSituations":"Desynchronized index state after failed or partial document opens; close removed the controller but left the mapping; concurrent modification bugs in server internals.","solutions":["Restart the Ruff server to rebuild the document index","Reopen the affected document via didOpen, then resend changes","If hacking on ruff_server, audit insert/remove paths so URI mappings and controllers are updated together"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = session.update_text_document(&key, changes, ver, enc) { if e.to_string().contains(\"Document controller not available\") { reopen_document(key); retry_update(); } }","preventionTips":["Reopen documents via didOpen whenever the server reports missing state","Restart the server to rebuild the index after persistent inconsistencies","When embedding ruff_server, ensure open paths insert both the URI mapping and controller together"],"tags":["lsp","documents","state"],"backgroundTag":"document-not-open","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}