Skip to content

fix(tool): report an empty code_comment batch instead of success - #1773

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
ydflow:fix/code-comment-empty-batch
Oct 20, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
ydflow:fix/code-comment-empty-batch

Conversation

@ydflow

@ydflow ydflow commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Description

code_comment can parse successfully while filing nothing. parseCommentsInner skips any entry that lacks a non-empty content (or a usable path), and a batch made only of such entries returns (nil, nil, ""). The tool then answered Successfully commented.

Reproduced on current main — before the fix, this printed result="Successfully commented." collected=0:

collector := NewCommentCollector()
p := &CodeCommentProvider{Collector: collector}
result, _ := p.Execute(ctx, map[string]any{
    "comments": []any{map[string]any{"path": "main.go", "message": "nil dereference"}},
})

The entry names a path but uses message where the schema says content, so the only field carrying the finding text is empty (an empty content behaves the same way). The model is told the comment was filed and moves on to task_done; the finding never reaches the collector, and nothing in --format json, the warnings list or the session records shows that it was dropped. The review then reports fewer findings than the model actually produced, with no signal on either side.

What this changes

  • internal/tool/code_comment.go: adds a CommentNoneUsableMsg verdict and returns it from CodeCommentProvider.Execute when the parse succeeded but produced no comment.
  • internal/llmloop/loop.go: returns the same verdict from the tool dispatch the agent loop actually uses. It flows through the existing error branch, so the attempt is recorded in ToolFailures() / the session record and the model gets a retryable error naming the two required fields. The existing consecutive-failure escalation still bounds a model that cannot fix its arguments.

Deliberately unchanged:

  • A batch where only some entries are malformed still succeeds and files the good ones. That tolerance is what the parser's per-entry skip is for; it is covered by an existing test and by a new regression case in this PR.
  • The parser is not made stricter. It stays "extract what you can"; the fix is in the verdict, so an empty result can no longer read back as success.

The empty-array case ("comments": []) already returned an error and is untouched.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • Package tests pass locally
  • Manual testing (describe below)

New tests:

  • internal/tool/code_comment_test.go: an all-dropped batch returns CommentNoneUsableMsg and collects nothing; a partly-dropped batch still returns CommentSucceed and files the good entry.
  • internal/llmloop/loop_test.go: TestExecuteToolCall_CodeCommentWithNoUsableEntryIsReported — the dispatch returns the message, collects nothing, and records exactly one code_comment tool failure.

Commands run on this branch (Windows, Go 1.27.0):

go test ./internal/tool/... ./internal/llmloop/... ./internal/agent/... ./internal/scan/...   # pass
go test ./cmd/opencodereview/ -skip TestLazyFileWriter_PreservesSymlinkTarget                  # pass
go vet ./internal/tool/... ./internal/llmloop/...                                              # clean
go build ./...                                                                                 # pass

TestLazyFileWriter_PreservesSymlinkTarget fails on this machine on the unmodified base commit as well (creating the symlink needs a privilege the shell does not have), so it is unrelated to this change; it is skipped by name above rather than reported as passing.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI disclosure: drafted with AI assistance (WorkBuddy) for wording and for navigating the call sites; I reviewed every line of the diff, ran the commands above myself, and will answer maintainers' questions from my own understanding.

Related Issues

No existing issue: this was found while reading the code_comment dispatch path.

Every entry of a code_comment batch can be dropped for a missing non-empty
'content' while the parse itself succeeds. The tool then answered
'Successfully commented.', so the model moved on to task_done and the
finding was lost with neither side noticing.

Return an explicit error from both entry points (the provider and the
llmloop tool dispatch) so the model can re-send the entry, and keep the
existing tolerance for a partly-bad batch.
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Four comment-only cleanup suggestions to keep the explanation concise and avoid repeating the PR description. No behavior changes.

Comment thread internal/tool/code_comment.go Resolved
Comment thread internal/llmloop/loop.go Resolved
Comment thread internal/llmloop/loop_test.go Resolved
Comment thread internal/tool/code_comment_test.go Resolved

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 375f64c into alibaba:main Oct 20, 2026
18 of 19 checks passed
SaahiilM added a commit to SaahiilM/open-code-review that referenced this pull request Oct 20, 2026
fix(tool): report an empty code_comment batch instead of success (alibaba#1773)
SaahiilM added a commit to SaahiilM/open-code-review that referenced this pull request Oct 20, 2026
fix(tool): report an empty code_comment batch instead of success (alibaba#1773)
SaahiilM added a commit to SaahiilM/open-code-review that referenced this pull request Oct 20, 2026
fix(tool): report an empty code_comment batch instead of success (alibaba#1773)
ydflow added a commit to ydflow/open-code-review that referenced this pull request Oct 31, 2026
A code_comment batch that keeps at least one usable entry parses without
error and files normally, so entries skipped for a missing non-empty
'content' or path are discarded with no record anywhere: the model sees a
plain success and assumes every finding was saved. The fully unusable
batch already takes the CommentNoneUsableMsg failure (alibaba#1773); the partial
case was the remaining silent loss.

parseCommentsInner now reports how many raw entries it skipped, and the
llmloop code_comment path records a comment_entries_dropped run warning
carrying the dropped/total count, matching how comment_args_repaired is
surfaced for schema violations. A batch with no usable entry still takes
the failure path, where the error already names the required fields.
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.

3 participants