Skip to content

feat(review): gate AI close on a calibrated, configurable confidence threshold - #1599

Merged
JSONbored merged 1 commit into
mainfrom
feat/ai-review-close-confidence
Jun 27, 2026
Merged

feat(review): gate AI close on a calibrated, configurable confidence threshold#1599
JSONbored merged 1 commit into
mainfrom
feat/ai-review-close-confidence

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

An AI consensus/split defect today carries a hardcoded confidence: 1 (consensusDefectOf / synthesizeDefect), and isConfiguredGateBlocker closes on ai_consensus_defect / ai_review_split whenever aiReviewGateMode === "block"regardless of how confident the reviewers actually were. That is a frequent false-close source: a speculative, low-conviction AI rejection closed PRs just as hard as a certain one.

This calibrates the AI signal and gates the block on a configurable floor:

  • Calibrated per-reviewer confidence (feat(docs): refresh Gittensor-aligned homepage #8): the review prompt now asks each reviewer for a confidence in [0,1] (its probability that its blockers are real defects). parseModelReview parses it with a graceful fallback of 1.0 when absent/unparseable/out-of-range, so behavior degrades to exactly today's. consensusDefectOf(a, b) carries min(a.confidence, b.confidence) (a consensus is only as strong as its weaker reviewer); synthesizeDefect([r]) / a split carry that reviewer's confidence. The confidence is threaded onto the produced ai_consensus_defect / ai_review_split advisory finding (AdvisoryFinding.confidence?).
  • Threshold gate (fix(docs): add explicit favicon metadata #7): new GateCheckPolicy.aiReviewCloseConfidence (default 0.9). The AI branch of isConfiguredGateBlocker now blocks only when aiReviewGateMode === "block" AND finding.confidence >= (aiReviewCloseConfidence ?? 0.9). Below-threshold AI defects stay advisory (visible, never block). A finding with no confidence is treated as 1.0 and always clears the floor — byte-identical to today. All other blocker codes are untouched.
  • Config-as-code: aiReviewCloseConfidence resolves from .gittensory.yml gate.aiReview.closeConfidence through the focus manifest into the effective settings, mirroring exactly how slopGateMinScore / qualityGateMinScore flow (parse + clamp to [0,1] without rounding, serialize/round-trip, resolveEffectiveSettings overlay). No DB migration — it stays on the config-as-code/manifest path, like those minScore thresholds. Documented in docs/review-configuration.md.

Advisory-mode-safe — no live change. aiReviewGateMode defaults to advisory (never blocks), so the live posted gate is unchanged; this only affects the BLOCK path and the dry-run "would-be" verdict.

No issue: small, self-evident hardening of an existing false-close path (the summary explains the rationale).

Scope

  • The PR title follows type(scope): short summary Conventional Commit format.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked an issue, or this is small enough that the summary explains why an issue is not needed.

Validation

  • git diff --check
  • npm run typecheck
  • npm run test:coverage locally — both sides of every new ?? / ternary / threshold comparison covered (ai-review.ts 99.03% stmt / 98.68% branch; advisory.ts 99.3% stmt / 98.03% branch; focus-manifest.ts 99.73% / 99.33%; the new confidence branches in advisory.ts are 100% on both sides).
  • npm run test:ci (full gate, incl. actionlint / migrations / workers / mcp / ui:openapi:check / ui:lint / ui:build) — green.
  • npm audit --audit-level=moderate — 0 vulnerabilities.
  • npm run ui:openapi:check — no drift (config-as-code-only; no API field added).
  • New behavior has unit tests for new branches, the fallback path, and the threshold boundary (both sides).

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. — N/A (no auth/session/CORS surface touched).
  • API/OpenAPI/MCP behavior is updated and tested where needed. — N/A (config-as-code-only; no API/MCP surface; OpenAPI check confirms no drift).
  • UI changes use live API data or real empty/error/loading states. — N/A (no UI change).
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. — docs/review-configuration.md updated; CHANGELOG.md untouched.

Notes

  • No DB migration by design — aiReviewCloseConfidence is an optional, manifest-only field on RepositorySettings (it stays undefined from the DB and is set only by the .gittensory.yml overlay), keeping it on the same config-as-code path as the minScore thresholds.

…threshold

Today an AI consensus/split defect carries a hardcoded confidence: 1 and
isConfiguredGateBlocker closes on ai_consensus_defect / ai_review_split
whenever aiReviewGateMode is block, regardless of how confident the
reviewers actually were — a frequent false-close source.

Each reviewer now emits a calibrated per-rejection confidence in [0,1]
(prompted + parsed, fallback 1.0 when absent/unparseable). A consensus
defect carries min(a, b) (only as strong as the weaker reviewer); a single
reviewer / split carries that reviewer's confidence. An AI defect now blocks
only when aiReviewGateMode is block AND the finding confidence clears a
configurable aiReviewCloseConfidence floor (default 0.9, set via
.gittensory.yml gate.aiReview.closeConfidence, clamped to [0,1]); below-floor
AI defects stay advisory.

Advisory-mode-safe: aiReviewGateMode defaults to advisory, so the live posted
gate is unchanged — this only affects the block path and the dry-run would-be
verdict. A finding with no confidence degrades to 1.0, byte-identical to today.
@dosubot dosubot Bot added the size:L label Jun 27, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.50%. Comparing base (810ddaf) to head (c8dad10).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1599   +/-   ##
=======================================
  Coverage   95.50%   95.50%           
=======================================
  Files         203      203           
  Lines       21985    22008   +23     
  Branches     7943     7956   +13     
=======================================
+ Hits        20996    21019   +23     
  Misses        413      413           
  Partials      576      576           
Files with missing lines Coverage Δ
src/queue/processors.ts 88.25% <100.00%> (+<0.01%) ⬆️
src/rules/advisory.ts 97.60% <100.00%> (+0.04%) ⬆️
src/rules/predicted-gate.ts 100.00% <100.00%> (ø)
src/services/ai-review.ts 98.63% <100.00%> (+0.04%) ⬆️
src/signals/focus-manifest.ts 99.17% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored
JSONbored merged commit b6e79f4 into main Jun 27, 2026
18 checks passed
@JSONbored
JSONbored deleted the feat/ai-review-close-confidence branch June 27, 2026 13:58
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