Skip to content

feat(review): add a read-only endpoint exposing ORB's live self-tuned gate thresholds - #6561

Closed
galuis116 wants to merge 1 commit into
JSONbored:mainfrom
galuis116:feat/ams-live-gate-thresholds-endpoint
Closed

feat(review): add a read-only endpoint exposing ORB's live self-tuned gate thresholds#6561
galuis116 wants to merge 1 commit into
JSONbored:mainfrom
galuis116:feat/ams-live-gate-thresholds-endpoint

Conversation

@galuis116

Copy link
Copy Markdown
Contributor

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:

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, returning null when the override carries neither a confidenceFloor nor a scopeCap.

Note on a prior closed attempt

A previous PR for this issue (#6545) was auto-closed on codecov/patch failing 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 (a confidenceFloor-absent-but-scopeCap-present override, and vice versa — see toLiveGateThresholdFields's 5 dedicated unit tests). I also caught and removed a v8 ignore comment 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 via lcov line/branch hit-count output that the real conditional is genuinely, fully exercised by the test suite with no coverage exemption needed at all.

Scope

Validation

  • git diff --check
  • npm run actionlint
  • npm run db:migrations:check / db:schema-drift:check — N/A, no migration or schema change (reuses the existing tunables_overrides/tunables_overrides_shadow tables as-is).
  • npm run selfhost:env-reference:check / selfhost:validate-observability
  • npm run docs:drift-check / manifest:drift-check / command-reference:check
  • npm run ui:openapi (regenerated) / npm run ui:openapi:check (clean) / npm run ui:openapi:settings-parity (clean) — new LiveGateThresholdsResponseSchema + path registered in src/openapi/schemas.ts/spec.ts, apps/loopover-ui/public/openapi.json regenerated and committed.
  • test/unit/auto-apply.test.ts (full file, 103 tests) and test/integration/api.test.ts (full file, 48 tests) — both 100% passing.
  • Broader regression sweep: auto-apply/auto-tune/reputation-wiring test files together — 190 tests, all passing.
  • Coverage verified directly, not assumed: ran a scoped vitest --coverage against just src/review/auto-apply.ts and src/api/routes.ts with 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 the lcov report's per-line DA:/BRDA: hit counts: every line has a non-zero hit count, and both sides of every branch (the identity?.kind === "static" && identity.actor === "mcp" && !isMcpReadRepoAllowed(...) chain, and the if (!fields) 404 check) show non-zero counts on both outcomes.
  • npm audit --audit-level=moderate — 0 vulnerabilities.
  • Root npm run typecheck / unsharded npm run test:coverage — this sandbox's root tsc --noEmit reliably 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) plus npm run ui:openapi's own tsx-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:

  • Root typecheck/unsharded test: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's codecov/patch gate actually measures for this diff.

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. — Not an auth-model change (reuses the existing isMcpReadRepoAllowed gate verbatim), but the negative path (403 forbidden_repo, 401 unauthenticated) is explicitly tested in the integration test.
  • API/OpenAPI/MCP behavior is updated and tested where needed. — New route, schema, and path registered; ui:openapi:check clean.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. — N/A, no UI change.
  • Visible UI changes include a UI Evidence section below with screenshots. — N/A, no UI change.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. — CHANGELOG.md untouched.

Notes

The AMS-side consumer (self-review-context.js probing this endpoint, #6487) is explicitly a separate, blocked-on-this sibling issue and is not built here.

… 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
@galuis116
galuis116 requested a review from JSONbored as a code owner July 16, 2026 13:46
@superagent-security

Copy link
Copy Markdown
Contributor

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

@galuis116

Copy link
Copy Markdown
Contributor Author

Closing — #6486 was independently resolved by #6553, which merged first. No need to carry two implementations of the same endpoint.

@galuis116 galuis116 closed this Jul 16, 2026
@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(review): read-only endpoint exposing ORB's live self-tuned gate thresholds

1 participant