Skip to content

feat(cli): order review and scan findings by severity - #2003

Merged
lizhengfeng101 merged 2 commits into
mainfrom
feat/sort-findings-by-severity
Nov 20, 2026
Merged

lizhengfeng101 merged 2 commits into
mainfrom
feat/sort-findings-by-severity

Conversation

@lizhengfeng101

@lizhengfeng101 lizhengfeng101 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Final ocr review and ocr scan reports group findings by severity instead of listing them in the order parallel workers finish. In text, JSON, and SARIF, findings with missing or unrecognized severity come first, followed by low, medium, high, and critical. Within each group, findings keep their collection order for that run; ties can appear in a different order on another run. SARIF assigns duplicate fingerprint suffixes before sorting, so reordering the report does not change a finding's fingerprint.

The GitHub Action uses a different order when deciding which inline comment to post. With incremental: 'true', it still skips candidates that overlap an existing bot comment. Among the remaining candidates, it considers the most severe first and breaks ties by report order. For example, if a new low and critical finding cover the same line, both remain in the CLI report, but only the critical finding is posted inline. Existing comments are not replaced.

Upgrade note: If your workflow pins the Action to an older revision but leaves ocr_version at its default (latest), upgrade the Action before adopting the new CLI, or pin the CLI until you can. The old incremental publisher keeps the first overlapping candidate, which in the new report can be the less severe finding.

Type of Change

  • New feature

How Has This Been Tested?

  • make check and make test passed locally.
  • Regression tests cover all three output formats, ties, missing and unknown severities, unchanged input order, and duplicate SARIF fingerprints.
  • ocr review reported no findings.

Checklist

  • Formatting and static checks pass.
  • Regression tests and CLI reference documentation are updated.
  • Author self-review of the changes and AI-generated content.
  • Contributor License Agreement signed.

AI disclosure: OpenAI Codex (gpt-6.2-astra) assisted with implementation, tests, and PR preparation. OpenCodeReview (gpt-6.2-astra) performed the automated pre-commit review.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

  • ✅ Successfully posted inline: 1 comment(s)

Comment on lines +33 to +39
for index, comment := range comments {
rank := slices.Index(levels[:], comment.Severity)
if rank < 0 {
rank = len(levels)
}
buckets[rank] = append(buckets[rank], findings[index])
}

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.

bug · medium
Potential panic if len(comments) != len(findings). The function iterates over comments and indexes into findings[index] without verifying both slices have the same length. While current call sites are safe (same slice passed twice, or 1:1 built results), this implicit contract is fragile — a future caller passing mismatched slices would get an index-out-of-range panic. Consider adding a guard or documenting the precondition.

Suggestion:

Suggested change
for index, comment := range comments {
rank := slices.Index(levels[:], comment.Severity)
if rank < 0 {
rank = len(levels)
}
buckets[rank] = append(buckets[rank], findings[index])
}
if len(comments) != len(findings) {
panic(fmt.Sprintf("inCommentSeverityOrder: comments length %d != findings length %d", len(comments), len(findings)))
}
for index, comment := range comments {
rank := slices.Index(levels[:], comment.Severity)
if rank < 0 {
rank = len(levels)
}
buckets[rank] = append(buckets[rank], findings[index])
}

@lizhengfeng101
lizhengfeng101 force-pushed the feat/sort-findings-by-severity branch from d83bc55 to 8a64270 Compare November 19, 2026 12:28

@MuoDoo MuoDoo left a comment

Copy link
Copy Markdown
Collaborator

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 8648ee2 into main Nov 20, 2026
16 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/sort-findings-by-severity branch November 20, 2026 04:54
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.

2 participants