Skip to content

feat(review): expose filtered comments in JSON output - #979

Open
Gongyl01 wants to merge 1 commit into
alibaba:mainfrom
Gongyl01:feat/filtered-comments
Open

feat(review): expose filtered comments in JSON output#979
Gongyl01 wants to merge 1 commit into
alibaba:mainfrom
Gongyl01:feat/filtered-comments

Conversation

@Gongyl01

Copy link
Copy Markdown
Contributor

Description

REVIEW_FILTER_TASK removes comments that the diff proves to be incorrect. These comments are currently removed from the collector and disappear from the final result, making filter decisions difficult to inspect.

This PR preserves removed comments and exposes them through an optional top-level filtered_comments field in JSON output. Each entry contains:

  • the original review comment
  • resolved line numbers
  • the filter's reasoning when available

The field is omitted when no comments are removed. Existing comments semantics, summary counts, publishing behavior, and session persistence remain unchanged. Filtered comments are available only in the current JSON output and are not returned by ocr session comments or the viewer.

The JSON output contract is documented in all supported languages.

Type of Change

  • New feature
  • Documentation update

How Has This Been Tested?

  • make test passes locally
  • Added unit tests for collection, reason handling, line resolution, and JSON output

Checklist

  • Self-reviewed
  • Tests added and passing
  • Documentation updated

Related Issues

N/A

@Gongyl01
Gongyl01 marked this pull request as ready for review August 17, 2026 09:50
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • ❌ Failed to post inline: 1 comment(s)

bug · medium

📄 cmd/opencodereview/shared.go (L421-L426)

⚠️ GitHub could not post this as an inline comment: Lines 421-426 could not be resolved (outside PR diff hunks)

Potential Issue: Filtered comments lost in early return path

When the review completes but produces no comments (len(comments) == 0) and no manifest, the code takes an early return via outputJSONNoFiles() which doesn't accept or emit the filtered comments. This could happen if the filter removed ALL comments that were generated.

The filtered comments would be silently dropped in this scenario, which contradicts the feature's purpose of keeping dropped findings visible.

💡 Suggested Change

Before:

if machineReadable && manifest == nil && len(comments) == 0 && ag.FilesReviewed() == 0 {
		if outputFormat == "json" {
			return outputJSONNoFiles(traceID, llmIdentity)
		}
		return outputSARIF(nil, Version, ag.Warnings(), manifest)
	}

After:

if machineReadable && manifest == nil && len(comments) == 0 && ag.FilesReviewed() == 0 {
		if outputFormat == "json" {
			var filtered []agent.FilteredComment
			if p, ok := ag.(filteredCommentsProvider); ok {
				filtered = resolveFilteredLines(p.FilteredComments(), ag.Diffs())
			}
			return outputJSONNoFiles(traceID, llmIdentity, filtered)
		}
		return outputSARIF(nil, Version, ag.Warnings(), manifest)
	}

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