{"record":{"id":"d0b7a4663c82b0e9","repo":"Hmbown/CodeWhale","slug":"scope-inventory-reached-its-bound-delete-narrower-scopes","errorCode":null,"errorMessage":"Scope inventory reached its bound; delete narrower scopes explicitly","messagePattern":"Scope inventory reached its bound; delete narrower scopes explicitly","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/native_memory.rs","lineNumber":586,"sourceCode":"                }\n                count += batch.len();\n                after = batch.last().map(|m| m.id.clone());\n            }\n        }\n        Ok(count)\n    }\n    pub fn delete_all(&self, scope: Option<MemoryScope>, workspace_id: Option<&str>) -> Result<()> {\n        let scopes = match scope {\n            Some(MemoryScope::Global) => vec![Self::owner_scope()],\n            Some(MemoryScope::Workspace) => vec![Self::workspace_scope(\n                workspace_id.ok_or_else(|| anyhow!(\"workspace id required\"))?,\n            )?],\n            None => {\n                let store = self.open_structured()?;\n                let owner = Access::operator(vec![Self::owner_scope()])?;\n                let mut scopes = store.local_scope_inventory(&owner)?;\n                if scopes.len() >= 10000 {\n                    bail!(\"Scope inventory reached its bound; delete narrower scopes explicitly\");\n                }\n                if scopes.is_empty() {\n                    scopes.push(Self::owner_scope());\n                }\n                scopes\n            }\n        };\n        let access = Access::operator(scopes)?;\n        let mut store = self.open_structured()?;\n        loop {\n            let batch = store.list(&access, None, 500)?;\n            if batch.is_empty() {\n                break;\n            }\n            for m in batch {\n                match store.get(&access, &m.id) {\n                    Ok(current) => {\n                        store.forget(&access, &current.id, current.revision)?;","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/native_memory.rs#L568-L604","documentation":"delete_all with no explicit scope list inventories every local scope under the operator's owner scope to delete them all. The store caps that inventory at 10,000 scopes; hitting the cap means a blanket delete would be unsafe or ambiguous, so the operation refuses and asks the caller to delete narrower scopes explicitly.","triggerScenarios":"Calling delete_all with scope=None when store.local_scope_inventory returns >= 10,000 scopes under the owner scope.","commonSituations":"Very large or long-lived memory stores where an agent created thousands of per-task or per-workspace scopes; runaway scope creation by automated tooling.","solutions":["Call delete_all with an explicit, narrower list of scopes instead of None.","Delete scopes in batches: enumerate scopes yourself, group them, and delete each group.","Audit what is creating so many scopes and reduce scope granularity.","If the bound is genuinely too small for your workload, raise the bound in code and document the change."],"exampleFix":"// before\nmemory.delete_all(None)?; // Scope inventory reached its bound\n// after\nmemory.delete_all(Some(vec![workspace_scope_hash]))?;","handlingStrategy":"validation","validationCode":"let store = memory.open_structured()?;\nlet owner = Access::operator(vec![owner_scope()])?;\nif store.local_scope_inventory(&owner)?.len() >= 10000 {\n    // enumerate and delete narrower scopes explicitly instead\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer explicit scope lists over scope=None blanket deletes.","Monitor scope count growth in long-lived stores.","Delete obsolete scopes periodically instead of letting them accumulate.","Avoid creating one scope per task/run in automated tooling."],"tags":["memory","limit","delete","safety-guard"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}