Skip to content

feat(api): wire internal decision/calibration routes, drop duplicate handleParity - #6216

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
nghetienhiep:fix/issue-6166
Jul 15, 2026
Merged

feat(api): wire internal decision/calibration routes, drop duplicate handleParity#6216
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
nghetienhiep:fix/issue-6166

Conversation

@nghetienhiep

Copy link
Copy Markdown
Contributor

Summary

Wires the two genuinely-missing operator read endpoints into src/api/routes.ts and resolves the parity-handler duplication flagged in the issue:

  • handleInternalDecisionGET /v1/internal/decision?repo=<owner/repo>&number=<n>[&kind=pull_request|issue] — the decision trail (row state + cached terminal GateDecision + audit log) for one review target.
  • handleInternalCalibrationGET /v1/internal/calibration — confidence-vs-outcome calibration + recommended floor.
  • handleParity (src/review/stats.ts) — removed as a confirmed duplicate (see Notes).

Both new routes sit alongside the existing /v1/internal/* operator reads (ops/stats, parity, predicted-agreement) and use the same access-control convention: the /v1/internal/* middleware bearer-gates on INTERNAL_JOB_TOKEN, and the handlers' own requireInternalAuth re-checks that same token (one logical gate). The handlers' logic is unchanged — this is routing only. The project namespace is resolved from GITHUB_APP_SLUG (fallback loopover), matching operator-dashboard.ts's existing config.

Closes #6166

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 a currently open issue this PR resolves (Closes #6166).

Validation

  • git diff --check
  • npm run typecheck
  • npm run test:coverage — new registrations covered 100% (statements + the slug || "loopover" fallback branch) by test/unit/routes-internal-decision-calibration.test.ts.
  • npm run test:workers
  • npm run ui:openapi:check (+ selfhost:env-reference:check, cf-typegen:check, docs:drift-check, command-reference:check)
  • npm audit --audit-level=moderate
  • New behavior has integration tests: 401 (missing/wrong token), 400 (bad repo+number), 404 (unknown target), 200 (seeded decision trail), calibration 200, and the loopover slug fallback.

The sibling /v1/internal/parity and /v1/internal/ops/stats reads are not listed in the hand-authored OpenAPI spec, so these two follow that same pattern and add no OpenAPI drift.

Safety

  • No secrets, wallets, hotkeys, trust scores, or private evidence exposed — the endpoints return aggregate review state only (a privacy assertion in the test guards against login|actor|reward|payout|trust|wallet|hotkey).
  • Auth is exercised on the negative path (401 with no token / wrong token) as well as the happy path.
  • No UI, docs, or changelog changes.

Notes

handleParity was a confirmed duplicate and is removed (as the issue requested for the true-duplicate case). Both handleParity (src/review/stats.ts) and computeParityReadiness (src/review/parity-wire.ts) wrap the same core (computeGateParity + isParityCutoverReady) to serve the /internal/parity cutover-readiness feed. parity-wire.ts is the canonical production implementation: it is the one actually registered (GET /v1/internal/parity, gated by the /v1/internal/* INTERNAL_JOB_TOKEN middleware + the LOOPOVER_REVIEW_PARITY_AUDIT flag) and the writer half (recordNativeGateDecision). handleParity was a reviewbot-port-era variant (bearer-gated by LOOPOVER_REVIEW_STATS_TOKEN, CORS-open, per-project scope) with zero production callers and no route — dead code superseded by parity-wire.ts. Removing it (and its now-orphaned unit tests) resolves the duplication instead of leaving it wired to nothing; all remaining stats.ts exports (computeStats, handleStats) keep the shared helpers/imports in use.

@nghetienhiep
nghetienhiep requested a review from JSONbored as a code owner July 15, 2026 22:37
@superagent-security

Copy link
Copy Markdown
Contributor

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

…handleParity

Register the two fully-built-but-never-routed ops handlers as operator read
endpoints alongside the existing /v1/internal/* reads, and resolve the
parity-handler duplication flagged in the issue:

- GET /v1/internal/decision -> handleInternalDecision (per-target decision trail)
- GET /v1/internal/calibration -> handleInternalCalibration (confidence calibration)

Both gate on INTERNAL_JOB_TOKEN via the /v1/internal/* middleware, which the
handlers' own requireInternalAuth re-checks. The project namespace comes from
GITHUB_APP_SLUG (fallback loopover), matching operator-dashboard's config. The
handlers' logic is unchanged - routing only.

handleParity (src/review/stats.ts) is a confirmed duplicate of parity-wire.ts's
canonical, registered /v1/internal/parity readiness feed (both wrap
computeGateParity + isParityCutoverReady). It had zero callers and no route, so
it is removed along with its orphaned unit tests rather than left as dead code.

Closes JSONbored#6166
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.32%. Comparing base (73b773c) to head (2205d15).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6216      +/-   ##
==========================================
- Coverage   95.32%   95.32%   -0.01%     
==========================================
  Files         596      596              
  Lines       47109    47098      -11     
  Branches    15015    15009       -6     
==========================================
- Hits        44907    44896      -11     
  Misses       1477     1477              
  Partials      725      725              
Flag Coverage Δ
shard-1 43.98% <50.00%> (-0.04%) ⬇️
shard-2 36.80% <100.00%> (+0.25%) ⬆️
shard-3 32.16% <50.00%> (-0.03%) ⬇️
shard-4 34.01% <50.00%> (-0.08%) ⬇️
shard-5 31.67% <50.00%> (-0.03%) ⬇️
shard-6 45.32% <50.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/api/routes.ts 94.48% <100.00%> (+0.01%) ⬆️
src/review/stats.ts 99.06% <ø> (-0.12%) ⬇️

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 15, 2026
@loopover-orb

loopover-orb Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-15 22:50:56 UTC

4 files · 1 AI reviewer · no blockers · readiness 80/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR wires two already-implemented handlers (handleInternalDecision, handleInternalCalibration from src/review/ops.ts) into src/api/routes.ts as new GET routes under the existing /v1/internal/* bearer-gated middleware, and removes handleParity from src/review/stats.ts along with its dedicated test suite. The routing change is thin and consistent with the existing pattern (same OpsAgentConfig shape used by operator-dashboard.ts), and the new test file exercises 401/400/404/200 paths plus the GITHUB_APP_SLUG fallback branch. The stats.ts removal is plausible as a genuine duplicate given routes.ts retains a separate parity implementation (computeParityReadiness/isParityAuditEnabled) still wired in, but that can't be fully confirmed from this diff alone since no other callers of the removed handleParity are visible.

Nits — 5 non-blocking
  • The internalOpsAgentConfig doc comment in src/api/routes.ts:930 is unusually long for a 4-line helper — consider trimming to the non-obvious parts (token reuse rationale) and dropping the restated middleware behavior.
  • The removed handleParity supported an OPTIONS/CORS preflight (204 + CORS headers); confirm no external client of the old `/<slug>/internal/parity` route depended on that specific handler's CORS behavior before treating this as a clean duplicate removal.
  • Grep the repo for any remaining imports of `handleParity` from src/review/stats.ts to be fully certain no other entrypoint (e.g., a self-host server file) still wires it before merging.
  • Consider a short comment noting *why* stats.ts's parity implementation (computeGateParity) and routes.ts's live parity route (computeParityReadiness) diverged, so future readers don't reintroduce the duplicate.
  • Possible secret-shaped assignment in the diff (generic_secret_assignment) — Verify the value is not a real credential.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #6166
Related work ⚠️ 2 scoped overlaps Top overlaps are listed below; lower-confidence bulk is hidden.
Change scope ❌ 8/20 High review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 99 registered-repo PR(s), 53 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor nghetienhiep; Gittensor profile; 99 PR(s), 0 issue(s).
Gate result ✅ Passing No configured blocker found.
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR registers GET /v1/internal/decision and /v1/internal/calibration in routes.ts using the same INTERNAL_JOB_TOKEN gate convention as sibling internal routes, and removes handleParity as a documented duplicate of parity-wire.ts's canonical route, with the removal rationale stated in the PR description.

Review context
Contributor next steps
  • Start here: Review top overlaps.
  • Then work through the remaining 2 steps in the Signals table above.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://gittensory.aethereal.dev/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot 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.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 00c14a5 into JSONbored:main Jul 15, 2026
15 checks passed
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): wire handleParity/handleInternalDecision/handleInternalCalibration into real routes (fully built, documented, never routed)

1 participant