{"record":{"id":"a9aa7aa1fd53bd6a","repo":"Hmbown/CodeWhale","slug":"sub-agent-depth-limit-reached-child-depth-absolute-max","errorCode":null,"errorMessage":"Sub-agent depth limit reached (child depth {}, absolute max {})","messagePattern":"Sub-agent depth limit reached \\(child depth (.+?), absolute max (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":6854,"sourceCode":"        assignment: SubAgentAssignment,\n        allowed_tools: Option<Vec<String>>,\n        options: SubAgentSpawnOptions,\n        precomputed_delivery_evidence: Option<DeliveryEvidence>,\n    ) -> Result<SubAgentResult> {\n        // Every manager-spawned runtime carries the fleet governor, so the\n        // spawned agent and its whole descendant tree report 429s/successes\n        // to the adaptive scheduler. Runtimes built outside a manager (tests,\n        // tool-only runtimes) keep `governor: None`.\n        runtime.governor = Some(Arc::clone(&self.governor));\n\n        self.cleanup(COMPLETED_AGENT_RETENTION);\n\n        self.check_admission_capacity()?;\n        runtime.max_spawn_depth = runtime\n            .max_spawn_depth\n            .min(runtime.worker_profile.max_spawn_depth);\n        if runtime.spawn_depth > runtime.max_spawn_depth {\n            return Err(anyhow!(\n                \"Sub-agent depth limit reached (child depth {}, absolute max {})\",\n                runtime.spawn_depth,\n                runtime.max_spawn_depth\n            ));\n        }\n        // A continuation/fork keeps the source's allowance as well as its\n        // current parent's allowance. The manifest edge preserves this after\n        // reload and for descendant accounting.\n        if let Some(preserved) = options.preserve_runtime_profile.as_ref() {\n            runtime.spawn_depth = runtime.spawn_depth.max(preserved.spawn_depth);\n            runtime.max_spawn_depth = runtime.max_spawn_depth.min(preserved.max_spawn_depth);\n            runtime.worker_profile.max_steps =\n                narrow_model_steps(runtime.worker_profile.max_steps, preserved.max_steps);\n            runtime.worker_profile.wall_time_secs = narrow_optional_limit(\n                runtime.worker_profile.wall_time_secs,\n                preserved.wall_time_secs,\n            );\n            runtime.worker_profile.wall_deadline_ms = narrow_optional_limit(","sourceCodeStart":6836,"sourceCodeEnd":6872,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L6836-L6872","documentation":"During sub-agent admission, the runtime's max spawn depth is clamped to the worker profile's limit; if the child's would-be depth exceeds that absolute max, spawn is refused. This is the fresh-spawn counterpart of the resume-path depth check.","triggerScenarios":"Spawning a sub-agent whose computed `spawn_depth` exceeds `min(runtime.max_spawn_depth, worker_profile.max_spawn_depth)` — e.g. a grandchild spawned at depth greater than the configured `max_spawn_depth`, or a worker profile with a tighter depth cap.","commonSituations":"Deeply nested agent chains (child spawning child spawning child); a worker profile configured with a small `max_spawn_depth`; recursive task delegation that never bottoms out.","solutions":["Flatten the delegation: have a shallower agent perform or spawn the work.","Raise `max_spawn_depth` in `[subagents]` or in the relevant worker profile.","Check for runaway recursive spawning and add a termination condition to the delegating prompt/logic."],"exampleFix":"// before\n[worker_profiles.researcher]\nmax_spawn_depth = 1\n\n// after\n[worker_profiles.researcher]\nmax_spawn_depth = 3","handlingStrategy":"validation","validationCode":"fn can_spawn_at(depth: usize, cfg: &SubagentsConfig, profile: &WorkerProfile) -> bool {\n    depth <= cfg.max_spawn_depth.min(profile.max_spawn_depth)\n}","typeGuard":null,"tryCatchPattern":"match spawn_child(task) {\n    Err(e) if e.to_string().contains(\"depth limit reached\") => run_inline(task), // do it yourself, no child\n    other => other?,\n}","preventionTips":["Keep delegation chains shallow; track current depth before spawning","Align worker profile max_spawn_depth with [subagents] max_spawn_depth","Give recursive delegation a hard termination condition"],"tags":["subagent","depth-limit","spawn","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"}