{"record":{"id":"8ef38a67919cfd40","repo":"Hmbown/CodeWhale","slug":"kimi-formula-web-search-exceeded-the-bounded-tool-call-loop","errorCode":null,"errorMessage":"Kimi Formula web search exceeded the bounded tool-call loop","messagePattern":"Kimi Formula web search exceeded the bounded tool-call loop","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/provider_native_search/kimi.rs","lineNumber":212,"sourceCode":"                .context(\"Kimi Formula web-search call omitted arguments\")?;\n            let _: Value = serde_json::from_str(arguments)\n                .context(\"Kimi Formula web-search arguments were not valid JSON\")?;\n            let fiber = client\n                .post_json(\n                    &fiber_url,\n                    &json!({ \"name\": name, \"arguments\": arguments }),\n                    &[],\n                )\n                .await?;\n            messages.push(json!({\n                \"role\": \"tool\",\n                \"tool_call_id\": id,\n                \"content\": formula_fiber_result(&fiber)?,\n            }));\n        }\n    }\n\n    bail!(\"Kimi Formula web search exceeded the bounded tool-call loop\")\n}\n\nfn reserve_native_search_tool_calls(executed: &mut usize, additional: usize) -> Result<()> {\n    let total = executed\n        .checked_add(additional)\n        .context(\"Kimi native web search tool-call count overflowed\")?;\n    if total > MAX_NATIVE_SEARCH_TOOL_CALLS {\n        bail!(\n            \"Kimi native web search exceeded the {MAX_NATIVE_SEARCH_TOOL_CALLS}-call safety limit\"\n        );\n    }\n    *executed = total;\n    Ok(())\n}\n\nfn formula_web_search_tools(payload: &Value) -> Result<Value> {\n    let tools = payload\n        .get(\"tools\")","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/client/provider_native_search/kimi.rs#L194-L230","documentation":"The Kimi Formula (K3) web-search flow is a bounded loop: rounds of function fibers are executed and results fed back until the model answers, capped by the shared MAX_NATIVE_SEARCH_TOOL_CALLS budget (8). If the loop runs out of budget while the model keeps requesting fibers, the client bails to prevent unbounded loops and runaway cost.","triggerScenarios":"search_formula exhausts its loop iterations because the K3 model repeatedly requests web-search fibers and never returns a final answer within the 8-call budget (reserve_native_search_tool_calls rejecting further reservations throws first if the per-round additions exceed the cap).","commonSituations":"Broad queries requiring many search rounds; a K3 model looping on the same query; budget too small for research-style tasks.","solutions":["Narrow or split the search query to reduce required rounds","Increase MAX_NATIVE_SEARCH_TOOL_CALLS if legitimately needed (watch cost/latency)","Check for a model-side loop (identical query repeatedly) and consider retrying the request","Fall back to the built-in native search path or a different model"],"exampleFix":"// before\nbail!(\"Kimi Formula web search exceeded the bounded tool-call loop\")\n// after\nbail!(\"Kimi Formula web search exceeded the bounded tool-call loop after {tool_calls_executed} calls; last query: {last_query}\")","handlingStrategy":"fallback","validationCode":"// estimate rounds and warn early\nif expected_rounds * calls_per_round > MAX_NATIVE_SEARCH_TOOL_CALLS { warn!(\"likely to exceed search budget\"); }","typeGuard":null,"tryCatchPattern":"match provider.search_formula(req).await {\n    Err(e) if e.to_string().contains(\"bounded tool-call loop\") => {\n        eprintln!(\"Formula search exceeded budget; splitting the query\");\n        split_and_search(req).await\n    }\n    other => other,\n}","preventionTips":["Split research-style tasks into multiple bounded searches","Watch for the model re-issuing the same query (loop signature)","Tune MAX_NATIVE_SEARCH_TOOL_CALLS from observed round counts, not guesses"],"tags":["kimi","formula","web-search","loop-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-23T08:17:48.524Z"}