Skip to content

fix(backend): round-trip Vertex functionCall through the gateway - #13671

Merged
Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
Git-on-my-level:fix/13666-vertex-functioncall-roundtrip
Sep 13, 2026
Merged

Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
Git-on-my-level:fix/13666-vertex-functioncall-roundtrip

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

What changed and why

Gateway Vertex generateContent already forwarded OpenAI tools to Gemini, but _vertex_to_openai_response / _vertex_to_openai_stream_chunk copied text only. Company-paid desktop Insight/Task (sendImageToolLoop) only act on functionCall, so after #12337 hopped them through the gateway they got HTTP 200s with billed tokens and emitted zero Advice Generated / Task Extracted (#13666). JSON-schema Memory/Suggestion still worked because they parse text.

This round-trips Vertex functionCall parts to OpenAI tool_calls (and finish_reason: tool_calls), including functionCall-only candidates. Desktop BFF translation already maps that back to Gemini. No client change. Do not flip OMI_LLM_GATEWAY_FEATURE_MODE.

Closes #13666

Product invariants affected

none

How it was verified

backend/.venv/bin/python -m pytest \
  backend/tests/unit/test_llm_gateway_vertex_provider.py \
  backend/tests/unit/test_desktop_gemini_gateway.py -q

36 passed, including the new functionCall-only generateContent and SSE regressions.

Could not exercise live prod desktop Insight/Task in this PR; that path is the GKE LLM gateway. After merge, ship llm-gateway (not Cloud Run-only) so desktop-backend's existing hop sees the translator.

Tests

test_vertex_function_call_only_response_emits_openai_tool_calls and test_vertex_function_call_sse_emits_openai_tool_call_delta in backend/tests/unit/test_llm_gateway_vertex_provider.py. A Vertex candidate with only functionCall (no text) must emit OpenAI tool_calls. That is the test that would have stayed red on #12337.

Failure class (fixes)

Failure-Class: new

Failure-class transition narrative (only when needed)

Violated contract: an OpenAI-compatible Vertex adapter that advertises function tools must return those tool calls, not a 200 with empty/text-only content. Canonical guard: response + SSE normalizers emit tool_calls from Gemini functionCall parts; the two new hermetic tests are the prevention artifact. Registry file: .github/failure-classes/FC-gateway-vertex-drops-function-calls.json.

Review in cubic

Desktop Insight/Task only act on Gemini functionCall parts. The BasedHardware#12337
OpenAI-compatible Vertex adapter forwarded tools on the request and
dropped them on the 200 response, which zeroed Advice Generated and
Task Extracted.

Failure-Class: new

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Confidence score: 3/5

  • backend/llm_gateway/gateway/vertex_wire.py marks split Vertex function-call SSE chunks as terminal and restarts indexes at 0 for each event, which can cause the desktop BFF to clear its pending call state; preserve chunk continuity across events and add coverage for split parallel and function-call responses.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/llm_gateway/gateway/vertex_wire.py">

<violation number="1" location="backend/llm_gateway/gateway/vertex_wire.py:473">
P2: When Vertex splits parallel function calls or a function-call response across SSE events, this chunk is marked terminal immediately and every event restarts indexes at 0. The desktop BFF therefore clears its pending calls after the first event and drops or overwrites subsequent calls. Preserve call indexes across the stream and emit `tool_calls` only on the actual terminal Vertex event, or buffer the function-call parts until termination.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

finish_reason = (
_vertex_finish_reason(raw_finish_reason, has_tool_calls=bool(tool_calls)) if raw_finish_reason else None
)
if finish_reason is None and tool_calls:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When Vertex splits parallel function calls or a function-call response across SSE events, this chunk is marked terminal immediately and every event restarts indexes at 0. The desktop BFF therefore clears its pending calls after the first event and drops or overwrites subsequent calls. Preserve call indexes across the stream and emit tool_calls only on the actual terminal Vertex event, or buffer the function-call parts until termination.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/llm_gateway/gateway/vertex_wire.py, line 473:

<comment>When Vertex splits parallel function calls or a function-call response across SSE events, this chunk is marked terminal immediately and every event restarts indexes at 0. The desktop BFF therefore clears its pending calls after the first event and drops or overwrites subsequent calls. Preserve call indexes across the stream and emit `tool_calls` only on the actual terminal Vertex event, or buffer the function-call parts until termination.</comment>

<file context>
@@ -455,10 +465,23 @@ def _vertex_to_openai_stream_chunk(
+    finish_reason = (
+        _vertex_finish_reason(raw_finish_reason, has_tool_calls=bool(tool_calls)) if raw_finish_reason else None
+    )
+    if finish_reason is None and tool_calls:
+        finish_reason = 'tool_calls'
+    if not text and not tool_calls and finish_reason is None and usage is None:
</file context>

@Git-on-my-level
Git-on-my-level merged commit 43111e5 into BasedHardware:main Sep 13, 2026
39 checks passed
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.

Desktop Advice Generated / Task Extracted exact-zero since 2026-09-01 21:00Z (Insight/Task via desktop Gemini proxy)

1 participant