{"record":{"id":"f4780cbbe24497f4","repo":"Hmbown/CodeWhale","slug":"sub-agent-token-budget-exhausted-for-scope-scope","errorCode":null,"errorMessage":"Sub-agent token budget exhausted for scope {scope_id}: {spent}/{limit} tokens spent, {remaining} remaining. Wait for the parent/Workflow to summarize results or start a fresh agent run.","messagePattern":"Sub-agent token budget exhausted for scope (.+?): (.+?)/(.+?) tokens spent, (.+?) remaining\\. Wait for the parent/Workflow to summarize results or start a fresh agent run\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":5014,"sourceCode":"        parent_run_id: Option<&str>,\n        requested_budget: Option<u64>,\n    ) -> Result<Option<AgentUsageBudgetScope>> {\n        let scope = if let Some(limit) = positive_token_budget(requested_budget) {\n            Some((worker_id.to_string(), limit))\n        } else if let Some(parent_scope) = self.inherited_budget_scope(parent_run_id) {\n            Some(parent_scope)\n        } else {\n            self.default_token_budget\n                .map(|limit| (worker_id.to_string(), limit))\n        };\n\n        let Some((scope_id, limit)) = scope else {\n            return Ok(None);\n        };\n        let spent = self.aggregate_budget_spent(&scope_id);\n        let remaining = limit.saturating_sub(spent);\n        if remaining < MIN_SUBAGENT_SPAWN_TOKEN_RESERVE {\n            return Err(anyhow!(\n                \"Sub-agent token budget exhausted for scope {scope_id}: {spent}/{limit} tokens spent, {remaining} remaining. Wait for the parent/Workflow to summarize results or start a fresh agent run.\"\n            ));\n        }\n        Ok(Some(AgentUsageBudgetScope {\n            scope_id,\n            limit,\n            spent,\n            remaining,\n        }))\n    }\n\n    fn attach_budget_scope(&mut self, worker_id: &str, scope: AgentUsageBudgetScope) {\n        let Some(record) = self.worker_records.get_mut(worker_id) else {\n            return;\n        };\n        record.usage.token_budget = Some(scope.limit);\n        record.usage.budget_scope = Some(scope.scope_id.clone());\n        record.usage.budget_spent_tokens = Some(scope.spent);","sourceCodeStart":4996,"sourceCodeEnd":5032,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/subagent/mod.rs#L4996-L5032","documentation":"Error \"Sub-agent token budget exhausted for scope {scope_id}: {spent}/{limit} tokens spent, {remaining} remaining. Wait for the parent/Workflow to summarize results or start a fresh agent run.\" thrown in Hmbown/CodeWhale.","triggerScenarios":"Thrown at crates/tui/src/tools/subagent/mod.rs:5014 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wait for the parent/Workflow to summarize results — the scope's spent tokens already cover the work done","Start a fresh agent run under a new scope if more work is genuinely needed","Raise the requested_budget (or the default token budget) when spawning the agent if the task legitimately needs more tokens"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}