fix: prevent tool_rounds cross-cascade contamination causing hangs

Root cause: proxy.rs eagerly pushed tool rounds via push_tool_round_calls
when intercepting Google's functionCall response. These stale rounds leaked
into LS follow-up requests, producing malformed history that Google timed
out on (60s 'no upstream response').

Changes:
- Remove push_tool_round_calls from proxy.rs response interception
- proxy.rs: use get_tool_rounds (non-destructive) instead of take_tool_rounds
  so accumulated rounds persist across multiple LS requests per cascade
- responses.rs/gemini.rs: build rounds via take+push+set pattern — each
  handler accumulates its own rounds from get_last_function_calls + results
- completions.rs: unchanged (set_tool_rounds replaces from messages)
- clear_tools: also clears tool_rounds to prevent stale data between sessions
- store.rs: add get_tool_rounds (non-destructive clone) method
This commit is contained in:
Nikketryhard
2026-02-16 19:21:03 -06:00
parent 32f02d6456
commit ba96534ead
4 changed files with 31 additions and 14 deletions

View File

@@ -269,14 +269,19 @@ pub(crate) async fn handle_responses(
result: result_value,
});
}
// Attach results to the latest open ToolRound (pushed by proxy.rs)
state
.mitm_store
.attach_tool_round_results(pending)
.await;
// Build a ToolRound from the MITM-captured function calls + client results.
// get_last_function_calls() has the calls from Google's previous response.
// We take existing accumulated rounds and append this new round.
let last_calls = state.mitm_store.get_last_function_calls().await;
let mut rounds = state.mitm_store.take_tool_rounds().await;
rounds.push(crate::mitm::store::ToolRound {
calls: last_calls,
results: pending,
});
state.mitm_store.set_tool_rounds(rounds).await;
info!(
count = tool_results.len(),
"Stored tool results for MITM injection (attached to tool round)"
"Stored tool results for MITM injection (built tool round)"
);
}