{"record":{"id":"8be589f91505065a","repo":"Hmbown/CodeWhale","slug":"runtime-has-reached-the-pending-dynamic-tool-call","errorCode":null,"errorMessage":"Runtime has reached the pending dynamic tool call limit ({MAX_PENDING_DYNAMIC_TOOL_CALLS})","messagePattern":"Runtime has reached the pending dynamic tool call limit \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":5485,"sourceCode":"            .map(|(_, entry)| entry.request.clone())\n            .collect::<Vec<_>>();\n        user_inputs.sort_by(|left, right| {\n            left.turn_id\n                .cmp(&right.turn_id)\n                .then_with(|| left.id.cmp(&right.id))\n        });\n        (approvals, user_inputs)\n    }\n\n    fn register_pending_dynamic_tool(\n        &self,\n        params: DynamicToolCallParams,\n    ) -> Result<oneshot::Receiver<DynamicToolCallResult>> {\n        let (tx, rx) = oneshot::channel();\n        let (settlement_tx, _settlement_rx) = watch::channel(0);\n        let mut pending = self.pending_dynamic_tools.lock();\n        if pending.len() >= MAX_PENDING_DYNAMIC_TOOL_CALLS {\n            bail!(\n                \"Runtime has reached the pending dynamic tool call limit ({MAX_PENDING_DYNAMIC_TOOL_CALLS})\"\n            );\n        }\n        if pending.contains_key(&params.call_id) {\n            bail!(\"Dynamic tool call '{}' is already pending\", params.call_id);\n        }\n        pending.insert(\n            params.call_id.clone(),\n            PendingDynamicToolEntry {\n                params,\n                sender: Some(tx),\n                settlement_tx,\n                indeterminate: false,\n            },\n        );\n        Ok(rx)\n    }\n","sourceCodeStart":5467,"sourceCodeEnd":5503,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L5467-L5503","documentation":"registering a dynamic tool call is capped at MAX_PENDING_DYNAMIC_TOOL_CALLS concurrent pending calls. When the pending map is full, new registrations bail to bound memory and prevent unbounded settlement queues.","triggerScenarios":"Calling the dynamic-tool-call registration API when pending_dynamic_tools already holds the maximum number of unresolved calls (each awaiting its oneshot result).","commonSituations":"Firing many parallel dynamic tool invocations without awaiting results; a consumer that stopped draining settlement receivers, leaking pending entries; runaway agent loops requesting tools faster than they settle.","solutions":["Await/settle pending dynamic tool calls before registering more","Bound concurrency in your caller (semaphore/chunking) below the limit","Investigate leaked pending entries (undrained receivers) and ensure results are consumed","Retry registration after pending count drops"],"exampleFix":"// before\nfor req in requests {\n    runtime.register_dynamic_tool_call(req).await?; // may hit cap\n}\n// after\nlet sem = Semaphore::new(MAX_PENDING_DYNAMIC_TOOL_CALLS / 2);\nfor req in requests {\n    let _permit = sem.acquire().await;\n    runtime.register_dynamic_tool_call(req).await?;\n}","handlingStrategy":"try-catch","validationCode":"if runtime.pending_dynamic_tool_call_count() >= MAX_PENDING_DYNAMIC_TOOL_CALLS {\n    // drain pending results before registering more\n}","typeGuard":null,"tryCatchPattern":"match runtime.register_dynamic_tool_call(params) {\n    Err(e) if e.to_string().contains(\"pending dynamic tool call limit\") => {\n        settle_pending_calls(&mut pending).await;\n        runtime.register_dynamic_tool_call(params).await?;\n    }\n    other => other?,\n}","preventionTips":["Always await the oneshot receiver for each dynamic tool call","Cap concurrency with a semaphore sized below the limit","Watch for consumers that stop draining settlement receivers (leaks count against the cap)"],"tags":["limit","concurrency","backpressure"],"backgroundTag":"rate-limit-exceeded","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"}