{"record":{"id":"5c616a862612cc8f","repo":"Hmbown/CodeWhale","slug":"cannot-resume-agent-agent-id-sub-agent-depth-li","errorCode":null,"errorMessage":"Cannot resume agent {agent_id}: sub-agent depth limit reached (current {}, max {})","messagePattern":"Cannot resume agent (.+?): sub-agent depth limit reached \\(current (.+?), max (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":6291,"sourceCode":"                build_resume_prompt(&agent.prompt, checkpoint, followup_text),\n                agent.assignment.clone(),\n                agent.allowed_tools.clone(),\n                agent.model.clone(),\n                agent.fork_context,\n                agent.workspace.clone(),\n                claim,\n                preserved_profile,\n                child_route,\n            )\n        };\n        let mut runtime = runtime.background_runtime();\n        if let Some((parent, depth, max_depth)) = saved_identity {\n            runtime.parent_agent_id = parent;\n            runtime.spawn_depth = depth;\n            runtime.max_spawn_depth = runtime.max_spawn_depth.min(max_depth);\n        }\n        if runtime.spawn_depth > runtime.max_spawn_depth {\n            return Err(anyhow!(\n                \"Cannot resume agent {agent_id}: sub-agent depth limit reached (current {}, max {})\",\n                runtime.spawn_depth,\n                runtime.max_spawn_depth\n            ));\n        }\n        runtime.context.workspace = workspace;\n        // Rebind the child's saved provider pin (#6046). The resumed runtime\n        // is derived from the caller, whose active provider can differ from\n        // the provider the child was spawned under; without this rebind the\n        // saved model is validated against the caller's provider and rejected\n        // as a foreign model for a direct provider. `bind_spawn_provider` is\n        // a no-op when the pin already matches, so same-provider children are\n        // unaffected. Borrow the receipt: it is moved into the spawn options\n        // below.\n        if let Some(saved_route) = child_route.as_ref() {\n            bind_spawn_provider(&mut runtime, &saved_route.provider_id).map_err(|error| {\n                anyhow!(\n                    \"Cannot resume agent {agent_id} on its saved provider '{}': {error}\",","sourceCodeStart":6273,"sourceCodeEnd":6309,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L6273-L6309","documentation":"When resuming a sub-agent, its saved spawn identity (parent, depth, max depth) is restored onto the runtime. If the restored depth exceeds the (clamped) maximum spawn depth, resume is refused to prevent an interrupted child from re-entering the tree deeper than the configured limit.","triggerScenarios":"Calling resume on an agent whose saved `spawn_depth` is greater than `min(runtime.max_spawn_depth, saved max_depth)`. Typically after the operator lowered `[subagents] max_spawn_depth` between the original spawn and the resume, or when resuming a deeply nested child near the absolute cap.","commonSituations":"Config tightening after an interruption; a child spawned at depth N whose parent chain now enforces a smaller max; replaying a saved session recorded under a larger depth budget.","solutions":["Raise `[subagents] max_spawn_depth` in the Workflow config to at least the child's saved depth shown in the error.","Instead of resuming, spawn the remaining work as a shallower sibling agent.","Let the parent agent handle the work directly rather than re-nesting."],"exampleFix":"// before\n[subagents]\nmax_spawn_depth = 2\n\n// after\n[subagents]\nmax_spawn_depth = 4  # >= saved child depth reported by resume error","handlingStrategy":"validation","validationCode":"// pre-flight before resume\nlet depth_ok = saved_depth <= max_spawn_depth_from_config();\nif !depth_ok { raise_max_spawn_depth(saved_depth); }","typeGuard":null,"tryCatchPattern":"match agents.resume(agent_id) {\n    Err(e) if e.to_string().contains(\"depth limit reached\") => {\n        // respawn at shallower depth or bump [subagents] max_spawn_depth\n        spawn_shallow_fallback(task)\n    }\n    other => other?,\n}","preventionTips":["Keep [subagents] max_spawn_depth stable across interrupt/resume cycles","Track child spawn depth in workflow tooling before delegating","Avoid deep recursive delegation patterns"],"tags":["subagent","resume","depth-limit","config"],"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-23T08:17:48.524Z"}