Skip to content

fix(sdk): nudge instead of finishing on a malformed-function-call content leak (gemini/OpenRouter)#2

Open
Viz-gov wants to merge 1 commit into
upstream_merge/2026-06-30from
fix/malformed-function-call-content-nudge
Open

fix(sdk): nudge instead of finishing on a malformed-function-call content leak (gemini/OpenRouter)#2
Viz-gov wants to merge 1 commit into
upstream_merge/2026-06-30from
fix/malformed-function-call-content-nudge

Conversation

@Viz-gov

@Viz-gov Viz-gov commented Jun 30, 2026

Copy link
Copy Markdown

Problem

gemini-3.5-flash (and other Gemini models) intermittently hit Gemini's MALFORMED_FUNCTION_CALL finish reason — especially on tool-heavy / multimodal turns. When served via OpenRouter's OpenAI-compat layer, that native reason is remapped to a normal finish_reason="stop" (exposed only as native_finish_reason), and a scrap of the botched call leaks into the message content (e.g. "5", "}", "000Z").

classify_response then sees non-blank content + no tool call → CONTENT_handle_content_response, which sets execution_status = FINISHED. The episode ends on what is really a fumbled tool call. Empty / reasoning-only turns are already recovered by _send_corrective_nudge, but a non-empty stray token slips straight through and silently kills the run.

Fix

In _handle_content_response, if the only visible content is an implausibly-short fragment (≤12 chars, single line) with no tool call, treat it as a malformed-function-call leak and send the existing corrective nudge instead of finishing. Substantive text answers are unaffected.

Evidence

Task auth-service-latency-investigation (multi-app-200, gemini-3.5-flash via OpenRouter, OpenHands SDK):

reward steps
before (3/3 prior runs) 0.0 dead at 4 (bare "5")
with this patch 0.625 278

The leak still occurs ~30× in the run — every one is now caught and nudged, and the agent recovers and completes the task. Canyon (text-only, no images) never tripped it, consistent with the multimodal trigger.

Notes / follow-ups

…dge instead of finishing on junk no-tool-call turn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant