alibaba / alibaba/open-code-review

fix(llm): preserve opaque tool-call fields across OpenAI-compatible turns

Open
#947 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
24.4k
Forks
1.8k
Avg merge
1d 19h
Merged PRs (30d)
116

Description

## Version

OCR v1.9.4 and current `main` (`b8bee971849d1fee2536e91a6b716168ccb9ed29`).

## Problem

Some OpenAI-compatible providers attach opaque metadata to assistant tool calls that must be echoed unchanged on later turns. Vertex AI's OpenAI-compatible Gemini endpoint returns a thought signature under `tool_calls[].extra_content`. OCR maps the response to its own `ToolCall` with only `id`, `type`, and `function`, so the next request drops `extra_content` and the provider rejects it with HTTP 400.

This affects normal repository tools: turn one can call `file_read`, but turn two fails before the model can continue the review.

## Reproduction

1. Configure the OpenAI Chat Completions protocol against Vertex AI's OpenAI-compatible endpoint with Gemini 3.
2. Run a review that causes a repository tool call.
3. The first completion succeeds and returns `tool_calls[].extra_content.google.thought_signature`.
4. OCR executes the tool but omits `extra_content` from the assistant tool-call history.
5. The second completion returns HTTP 400.

A provider-independent reproduction is a two-request fake OpenAI server: return an unknown `extra_content` object on the first tool call, then require it on the second request.

## Expected behavior

OCR should preserve unknown, valid JSON fields from provider-returned function tool calls and echo them on subsequent turns. Reserved standard fields (`id`, `type`, `function`) must remain owned by OCR, malformed data must not be forwarded, and opaque fields should not be written to normal review/session logs.

## Proposed fix

Keep the unknown tool-call fields as non-serialized raw JSON on OCR's internal `ToolCall`, then use the OpenAI SDK's supported `SetExtraFields` mechanism when rebuilding assistant history. Add an end-to-end adapter regression test that proves an opaque nested field survives response mapping and the next request.

Contributor guide

Open the contributing guide

Research direction

Start at the OpenAI-compatible adapter's response mapping and the code that rebuilds assistant tool-call history; inspect how ToolCall currently retains only standard fields. Add the adapter regression test described in the issue using a two-request fake OpenAI server, and verify that a nested opaque field survives the second request without appearing in normal logs.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.