feat(review): add a read-only endpoint exposing ORB's live self-tuned gate thresholds - #6561
Closed
galuis116 wants to merge 1 commit into
Closed
feat(review): add a read-only endpoint exposing ORB's live self-tuned gate thresholds#6561galuis116 wants to merge 1 commit into
galuis116 wants to merge 1 commit into
Conversation
… gate thresholds New GET /v1/repos/:owner/:repo/live-gate-thresholds (#6486, implementing #6209's decision): a field-limited, snake_case-only projection of a repo's authoritative gate threshold override -- confidence_floor, scope_cap_files, scope_cap_lines only. Never applied_at/clear_at or the override_audit history. The live override wins; a soaking shadow's queued value fills in when live is absent, so AMS sees a pending tightening too, not just a promoted one. Auth matches the existing intelligence/issue-quality/ reviewability precedent routes (isMcpReadRepoAllowed gating a static mcp actor, everything else trusted) rather than gate-config/effective's stricter static-token-only gate, per #6209's decision to reuse the simpler, already-established pattern. Two new pure helpers in auto-apply.ts: authoritativeGateOverride (live-wins-over-shadow) and toLiveGateThresholdFields (the snake_case projection, null when the override carries neither field). Both are exhaustively branch-tested, including the specific confidenceFloor- undefined-but-scopeCap-defined combination. Closes #6486
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6486
Summary
#6209 decided the design (see its pinned decision comment): AMS probes a new read-only ORB endpoint for a repo's live self-tuned gate thresholds before falling back to static-file reconstruction (the AMS-side consumer is a separate, blocked-on-this sibling issue, #6487). This PR is the ORB-side endpoint only.
New
GET /v1/repos/:owner/:repo/live-gate-thresholds:confidence_floor,scope_cap_files,scope_cap_lines— noapplied_at/clear_at, nooverride_audithistory. These are the liveTunableOverridefields already defined insrc/review/auto-apply.ts.{ error: "live_gate_thresholds_not_found", repoFullName }when neither a live nor a shadow override is active — matching the existing not-found convention/issue-quality's route already uses (issue_quality_not_found), per the issue's own "follow existing convention, don't invent a new response shape" requirement.isMcpReadRepoAllowed+MCP_READ_REPO_ALLOWLISTgates a staticmcp-actor identity; every other identity (an authenticated session, or an operator-only static token) is trusted — the exact same gate already used onsrc/api/routes.ts:2354/2368/2959. This is deliberately the simpler pattern, not the stricterrequireStaticProtectedApiToken-gated shape the sibling/gate-config/effectiveroute (feat(review): add a read-only endpoint exposing ORB's live self-tuned gate thresholds for a repo #6247) uses — Spec: upgrade AMS's predicted-gate to query ORB's live self-tuned config when both are installed #6209's decision comment names this specific gate ("the exact same gate already used on ~6 existing MCP-facing read routes"), and/gate-config/effectivepredates Spec: upgrade AMS's predicted-gate to query ORB's live self-tuned config when both are installed #6209's decision and has a different (nested camelCase,shadowPending-flagged) response shape serving a different UI consumer, so this is intentionally a distinct route, not a duplicate.Two new pure helpers in
auto-apply.ts:authoritativeGateOverride(live, shadow):live ?? shadow?.override ?? null— live wins, shadow is the fallback.toLiveGateThresholdFields(override): projects into the exact snake_case allowlist, returningnullwhen the override carries neither aconfidenceFloornor ascopeCap.Note on a prior closed attempt
A previous PR for this issue (#6545) was auto-closed on
codecov/patchfailing at 95.45% (1 uncovered line). I did not blindly reuse that PR's diff — I re-derived the implementation from #6209's decision comment and the existing precedent routes, then wrote my own test suite and specifically traced every branch by hand before writing tests, including the exact combination that's easy to miss in a??-heavy projection function (aconfidenceFloor-absent-but-scopeCap-present override, and vice versa — seetoLiveGateThresholdFields's 5 dedicated unit tests). I also caught and removed av8 ignorecomment I'd initially misattributed to the wrong line while drafting (copied from an adjacent "unauthenticated requests never reach here" precedent that doesn't actually apply to the mcp-allowlist check) — verified vialcovline/branch hit-count output that the real conditional is genuinely, fully exercised by the test suite with no coverage exemption needed at all.Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Validation
git diff --checknpm run actionlintnpm run db:migrations:check/db:schema-drift:check— N/A, no migration or schema change (reuses the existingtunables_overrides/tunables_overrides_shadowtables as-is).npm run selfhost:env-reference:check/selfhost:validate-observabilitynpm run docs:drift-check/manifest:drift-check/command-reference:checknpm run ui:openapi(regenerated) /npm run ui:openapi:check(clean) /npm run ui:openapi:settings-parity(clean) — newLiveGateThresholdsResponseSchema+ path registered insrc/openapi/schemas.ts/spec.ts,apps/loopover-ui/public/openapi.jsonregenerated and committed.test/unit/auto-apply.test.ts(full file, 103 tests) andtest/integration/api.test.ts(full file, 48 tests) — both 100% passing.auto-apply/auto-tune/reputation-wiringtest files together — 190 tests, all passing.vitest --coverageagainst justsrc/review/auto-apply.tsandsrc/api/routes.tswith only my 2 changed test files.auto-apply.ts— 100% statements/functions/lines, 98.72% branch with the single remaining gap confirmed pre-existing and unrelated (runAutoApplyRecommendations, an untouched function, in a partial 2-file run — the full suite covers it). My new route's exact lines, verified via thelcovreport's per-lineDA:/BRDA:hit counts: every line has a non-zero hit count, and both sides of every branch (theidentity?.kind === "static" && identity.actor === "mcp" && !isMcpReadRepoAllowed(...)chain, and theif (!fields)404 check) show non-zero counts on both outcomes.npm audit --audit-level=moderate— 0 vulnerabilities.npm run typecheck/ unshardednpm run test:coverage— this sandbox's roottsc --noEmitreliably OOMs regardless of diff content (reproduced repeatedly this session, confirmed again on this diff — the failure trace shows the standard V8 heap-limit abort, not a real type error). Substituted with careful manual type review of every new line (documented above) plusnpm run ui:openapi's owntsx-driven type-check of the new Zod schemas passing clean, plus the scoped coverage run's line-by-line confirmation that the actual runtime code paths execute exactly as written.If any required check was skipped, explain why:
typecheck/unshardedtest:coverage: established OOM pattern in this sandbox (2.3GB free RAM, no swap headroom), unrelated to diff content. Substituted with the scoped, file-targeted coverage verification above, which is the specific signal Codecov'scodecov/patchgate actually measures for this diff.Safety
isMcpReadRepoAllowedgate verbatim), but the negative path (403 forbidden_repo, 401 unauthenticated) is explicitly tested in the integration test.ui:openapi:checkclean.UI Evidencesection below with screenshots. — N/A, no UI change.CHANGELOG.mduntouched.Notes
The AMS-side consumer (
self-review-context.jsprobing this endpoint, #6487) is explicitly a separate, blocked-on-this sibling issue and is not built here.