fix: clear stale tool state in completions handler to prevent hang

Tool definitions stored in MitmStore from /v1/responses requests were
persisting and getting injected into /v1/chat/completions requests.
This caused Gemini to return functionCalls instead of text, and since
the completions handler has no function call handling logic, it would
poll forever waiting for text that never came.

Fix: clear active_tools, active_tool_config, and has_active_function_call
at the start of handle_completions. Also add clear_active_function_call()
method to MitmStore.
This commit is contained in:
Nikketryhard
2026-02-14 23:10:45 -06:00
parent 786987116b
commit 7e16a7b892
2 changed files with 11 additions and 0 deletions

View File

@@ -78,6 +78,12 @@ pub(crate) async fn handle_completions(
}
};
// Clear any stale tool definitions from other endpoints (e.g. /v1/responses)
// to prevent them leaking into completions requests. The completions endpoint
// does not support our custom tool call flow, so tools must never be injected.
state.mitm_store.clear_tools().await;
state.mitm_store.clear_active_function_call();
let token = state.backend.oauth_token().await;
if token.is_empty() {
return err_response(

View File

@@ -252,6 +252,11 @@ impl MitmStore {
self.has_active_function_call.load(Ordering::SeqCst)
}
/// Force-clear the active function call flag (used to reset stale state).
pub fn clear_active_function_call(&self) {
self.has_active_function_call.store(false, Ordering::SeqCst);
}
/// Check if there are pending function calls for a cascade.
pub async fn has_pending_function_calls(&self, cascade_id: &str) -> bool {
let pending = self.pending_function_calls.read().await;