fix(llmloop): guard nil tool-call arguments map to prevent panic#8
fix(llmloop): guard nil tool-call arguments map to prevent panic#8chethanuk wants to merge 1 commit into
Conversation
|
Warning Review limit reached
Next review available in: 23 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request prevents potential panics by ensuring that tool call arguments that unmarshal to nil (such as when "arguments": null is received) are initialized to a non-nil map before being used. Comprehensive unit tests have been added to verify these edge cases. There are no review comments, so no feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Some OpenAI-compatible gateways emit "arguments": null for tool calls.
json.Unmarshal("null", &args) succeeds and sets the map to nil (JSON
null nils maps regardless of prior value), so the code_comment path
override (args["path"] = newPath) panicked with "assignment to entry
in nil map", killing the per-file subtask.
- internal/llmloop: parse arguments through a shared parseToolArgs
helper that always returns a non-nil map, covering both the known-tool
and dynamic-tool paths.
- internal/llm: the Anthropic history-replay path had the same hazard --
null arguments reset the pre-initialized argsMap to nil, serializing
tool_use input as JSON null, which the API rejects.
Fixes alibaba#382
ae7865c to
850c99d
Compare
Problem
ocr scan(and potentiallyreview) crashes withpanic: assignment to entry in nil mapatinternal/llmloop/loop.goinexecuteToolCall, killing the per-file subtask:Reported with GLM via an OpenAI-compatible endpoint; reproduces at any
--concurrency, but only on files where the model emits the offending tool call — matching the reporter's partial-failure sessions ("5 completed, 4 failed").Root cause
Some OpenAI-compatible gateways emit
"arguments": nullfor tool calls.json.Unmarshal([]byte("null"), &args)returns nil error and leaves the map nil. Thecode_commentpath-override then writes into it:This is the only nil-map write in the tool-call handling surface (audited every
Function.Argumentsunmarshal in the repo), but the dynamic-tool path has the same latent hazard: providers receive a nilargsmap and would panic if they ever write to it.Fix
internal/llmloop/loop.go— both argument-unmarshal sites inexecuteToolCallnow go through a sharedparseToolArgshelper that always returns a non-nil map, so every downstream consumer (ParseComments, providerExecute, thecode_commentpath override) is safe. A null-argscode_commentcall now degrades gracefully to the existing "'comments' array is required" tool-error result, which the model can react to — instead of killing the subtask.internal/llm/client.go— the Anthropic history-replay path had the same latent hazard:argsMapis pre-initialized, butjson.Unmarshal([]byte("null"), &argsMap)resets it to nil (JSONnullsets maps to nil regardless of prior value), sotool_useinput would serialize as JSONnull, which the API rejects. Guarded the same way.Intentional behavior note: for dynamic/MCP tools called with
arguments: null, the wire payload to the MCP server changes from"arguments": nullto"arguments": {}— the standards-conformant encoding (JSON-Schematype: objectvalidators rejectnull).Tests
TestExecuteToolCall_ArgumentsEdgeCases(internal/llmloop):nullargs oncode_comment(the exact panic: assignment to entry in nil map alibaba/open-code-review#382 repro — panics before this fix),{}, valid args (path-override behavior preserved), empty string, malformed JSON, andnullargs on a dynamic tool (assertsExecutereceives a non-nil map).TestBuildAnthropicParams_NullToolCallArguments(internal/llm):null/empty/{}arguments →tool_useinput is always a non-nil object (fails on the nil map before the fix).Both tests verified RED before the fix, GREEN after:
make check,make test(-race),make coverage(81%+, ≥80% gate) andgo build ./cmd/opencodereviewall pass.Fixes alibaba#382