Skip to content

feat(review-pr): add configurable confidence-threshold input - #23

Merged
Sayt-0 merged 2 commits into
mainfrom
feat/review-pr-confidence-threshold
Jun 29, 2026
Merged

Sayt-0 merged 2 commits into
mainfrom
feat/review-pr-confidence-threshold

Conversation

@Sayt-0

@Sayt-0 Sayt-0 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a confidence-threshold input to the review-pr action (and the reusable
workflow) to control the minimum per-finding confidence required to post an
inline review comment. Findings scoring below the threshold are collapsed into
the existing "Lower-confidence findings (not posted inline)" summary instead of
posted inline. Security and high-severity CONFIRMED/LIKELY findings are always
posted regardless of the threshold.

Previously the inline cutoff was hardcoded at MODERATE_THRESHOLD (55). This
change makes that cutoff configurable while keeping the default behavior
identical.

Behavior

Aspect Value
Accepted values band name (strong=80, moderate/medium=55, weak=30) or a number
Numeric range clamped to [30, 100] (the weak floor is the lowest meaningful cutoff, so negligible findings are never posted inline)
Default moderate (55), preserving prior behavior exactly
Below threshold collapsed into the lower-confidence summary (never silently dropped)
Always posted inline security and high-severity CONFIRMED/LIKELY findings (threshold does not apply)
Invalid value falls back to the default; the action logs a warning

Files changed

File Change
src/score-confidence/score-confidence.ts resolvePostThreshold() and a postThreshold option on scoreFinding/scoreFindings; threshold-driven posting disposition
src/score-confidence/index.ts CLI honors a CONFIDENCE_THRESHOLD env var
review-pr/action.yml new input; resolve step (bash mirror of resolvePostThreshold); injects a "Review Configuration" block into the agent prompt
review-pr/agents/pr-review.yaml posting policy uses the configured threshold T (rules 4 and 5); console-mode default T=55
.github/workflows/review-pr.yml new workflow_call input, forwarded to the action
src/score-confidence/__tests__/score-confidence.test.ts tests for the resolver, raise/lower behavior, forced-bypass, clamps, band stability
review-pr/README.md, AGENTS.md documentation

The TS model stays the single source of truth; the bash resolver in the action
and the agent prompt mirror it, consistent with the existing convention.

Validation

  • Unit tests: 630 passing (includes new threshold suites)
  • tsc --noEmit: clean
  • biome ci .: clean (89 files)
  • actionlint: clean
  • tsup build: success
  • Default moderate (55) reproduces the prior dispositions, so existing tests pass unchanged

Notes

  • The input takes effect once the release SHA referenced by review-pr.yml is
    bumped (the reusable workflow pins the action by SHA, same pattern as the
    sibling exclude-paths / max-diff-lines inputs).
  • The change was reviewed across four dimensions (TS model, action/bash wiring,
    agent prompt, tests/docs) with each finding independently verified; the items
    surfaced were low-severity consistency fixes and have been applied.

Add a confidence-threshold input to the PR review action that sets the
minimum per-finding confidence required to post an inline comment. Findings
that score below the threshold are collapsed into the existing
lower-confidence summary instead of posted inline; security and high-severity
CONFIRMED/LIKELY findings are always posted regardless.

The input accepts a band name (strong=80, moderate/medium=55, weak=30) or a
number clamped to [30, 100]. It defaults to moderate (55), which preserves the
prior behavior exactly.

Implementation:
- score-confidence: add resolvePostThreshold() and a postThreshold option on
  scoreFinding/scoreFindings; replace the hardcoded inline cutoff with the
  configurable threshold (clamped so the negligible band is never posted inline
  by the default rule).
- review-pr/action.yml: resolve the input in bash (mirroring resolvePostThreshold)
  and inject it into the agent prompt, which applies it in the posting policy.
- review-pr.yml: expose and forward the new workflow_call input.
- score-confidence CLI honors a CONFIDENCE_THRESHOLD env var.
- Update unit tests, README, and AGENTS.md.
@Sayt-0
Sayt-0 requested a review from derekmisler June 29, 2026 09:32

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

The confidence-threshold input is well-implemented across all four layers:

TypeScript model (score-confidence.ts)
resolvePostThreshold correctly handles all input types — band names (strong/moderate/medium/weak), numeric strings, floats (via Math.round before clamping), NaN, undefined, and null. The clamping to [WEAK_THRESHOLD, 100] ensures the negligible band can never be posted inline by rule 4. The forwarding of postThreshold through scoreFindings → scoreFinding is sound, and the undefined passthrough correctly defers to the ?? DEFAULT_POST_THRESHOLD default inside scoreFinding.

Bash resolver (review-pr/action.yml)
The bash step faithfully mirrors resolvePostThreshold: band-name case arms match their TS equivalents, 10#$NORM forces decimal parsing for numeric strings, [ -lt 30 ]/[ -gt 100 ] clamp correctly, and the :-moderate default handles empty inputs. The read -r NORM <<< "$NORM" trim is equivalent to .trim() (strips leading/trailing ASCII whitespace; preserves internal spaces so "8 0" correctly falls through to the unrecognized branch). The else LABEL=negligible arm after clamping is dead code (SCORE is always ≥ 30) but harmless.

Agent prompt (pr-review.yaml)
The threshold T is clearly exposed in the posting-policy rules and the fallback default (T = 55) is correct for console mode. The format change in the lower-confidence summary template (BAND SCORE/100 instead of weak SCORE/100) is a useful fix — below-threshold findings may now be moderate or strong band when the threshold is raised.

Tests
Cover the full resolver surface (resolvePostThreshold) — band names, aliases, case/whitespace insensitivity, numeric types, clamping, rounding, NaN/null/undefined, and fallbacks — plus scoreFinding threshold raise/lower behavior, band-label stability, forced bypasses (security + high-severity), and scoreFindings forwarding. All assertions are correct.

No bugs were found in the introduced code.

@Sayt-0
Sayt-0 enabled auto-merge (squash) June 29, 2026 09:40

@derekmisler derekmisler 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.

the feature makes sense and the TS implementation looks solid, but the bash resolver in review-pr/action.yml directly contradicts the AGENTS.md convention that all new composite-action logic must live in src/ as TypeScript. resolvePostThreshold already exists and is already bundled, so this should be a thin CLI call rather than a 40-line bash mirror. two small nitpicks below the main comment too.

Comment thread review-pr/action.yml
# ========================================
# BUILD REVIEW CONTEXT
# ========================================
- name: Resolve confidence threshold

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.

issue: AGENTS.md is explicit: "New logic in composite actions must be implemented as TypeScript in src/ with Vitest unit tests, not as inline bash, awk, or other scripting languages embedded in YAML files. Shell steps in action YAML files should only orchestrate calls to dist/*.js tools."

this 40-line bash resolver is a direct violation of that. resolvePostThreshold already exists in src/score-confidence/score-confidence.ts and it's already bundled to dist/score-confidence.js. the right move is to either add a resolve-threshold subcommand to that CLI or expose it via dist/resolve-confidence.js, and then replace this whole step with one line:

THRESHOLD=$(node "$ACTION_PATH/../dist/score-confidence.js" resolve-threshold "$CONFIDENCE_THRESHOLD_INPUT")

the bash version has no test coverage, has behavioral divergences from the TS (e.g. negative numbers like -5 emit a warning in bash but silently default in TS), and now there are three places that need to stay in sync: the TS function, the bash resolver here, and the lookup table in pr-review.yaml. AGENTS.md already called out the two-place problem with "Change one, change both", this adds a third.

Comment thread review-pr/action.yml Outdated
if [ "$SCORE" -ge 80 ]; then LABEL=strong
elif [ "$SCORE" -ge 55 ]; then LABEL=moderate
elif [ "$SCORE" -ge 30 ]; then LABEL=weak
else LABEL=negligible

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.

nitpick (super non-blocking): LABEL=negligible is unreachable. by the time we get here SCORE has been clamped to [30, 100], so the elif [ "$SCORE" -ge 30 ] branch always fires first. the else is dead code.

Comment thread review-pr/action.yml Outdated
required: false
default: "3000"
confidence-threshold:
description: "Minimum confidence for posting a finding as an inline comment. Accepts a band name (`strong`=80, `moderate`/`medium`=55, `weak`=30) or a number 0-100. Findings that score below the threshold (and are not security or high-severity) are collapsed into the lower-confidence summary instead of posted inline; they are never silently dropped. Security findings and high-severity CONFIRMED/LIKELY findings are always posted regardless. Default: moderate (55), which preserves the prior behavior. Numbers are clamped to [30, 100]."

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.

nitpick (super non-blocking): says "a number 0-100" but then two sentences later "Numbers are clamped to [30, 100]". so is the accepted range 0-100 or 30-100? the reusable workflow input description gets this right ("clamped to 30-100"), worth making this consistent so users aren't surprised when 10 becomes 30.

…bash

Replace the bash mirror of resolvePostThreshold() in the review-pr action with a thin call to a new resolve-threshold CLI subcommand, per the AGENTS.md rule that composite-action logic lives in src/ as tested TypeScript and shell steps only orchestrate dist/*.js tools.

- Add describeThreshold() (score, band, recognized) to score-confidence.ts as the single source of truth; resolvePostThreshold now delegates to it.
- Add the resolve-threshold subcommand to dist/score-confidence.js: it sets the score and label step outputs and warns on an unrecognized value via @actions/core, so the action step is a single node invocation.
- Fix the bash/TS divergence: an unrecognized value such as -5 or '8 0' now warns consistently instead of only in bash.
- Remove the unreachable LABEL=negligible branch (gone with the bash block).
- Make the confidence-threshold input description consistent (clamped to 30-100), matching the reusable workflow and README.
- Cover describeThreshold and the resolve-threshold CLI with unit tests; update AGENTS.md and the module docs to drop the bash-mirror references.

@derekmisler derekmisler 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.

ci is green, approving!

@Sayt-0
Sayt-0 merged commit b2713eb into main Jun 29, 2026
8 checks passed
@Sayt-0
Sayt-0 deleted the feat/review-pr-confidence-threshold branch June 29, 2026 20:57
Sayt-0 added a commit that referenced this pull request Jun 30, 2026
Resolve conflict in review-pr/agents/pr-review.yaml: keep the new suggestion-block emission instruction from this branch and adopt main's configurable inline-threshold (T) wording for the lower-confidence summary bullet (from #23).
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