Uncertainty engine: Hono routes (#99)#110
Merged
ssilvius merged 2 commits intofeat/uncertainty-schemafrom Apr 28, 2026
Merged
Conversation
Closes #99. Phase 1 of the uncertainty engine spike. Four endpoints under /api/uncertainty, all gated by requireAuth: - POST /predictions: emits a prediction. Computes cohort_key from surface|model|model_version|bucketLower. Writes state='emitted', orphan_after = now + ttl. Returns id + orphan_after. - PUT /predictions/:id/witness: idempotent. 404 if missing, 409 if already witnessed. Otherwise flips to state='witnessed' with outcome label/correctness/payload and witnessed_at. - GET /calibration?surface&model&model_version: returns the cached snapshot bucket rows for the matching cohort prefix, ordered by bucket lower bound. - GET /orphans: per-surface counts grouped by state. Pure cohort/Brier helpers in api/lib/uncertainty/cohort.ts so they unit-test without needing Hono or D1 in the test surface. Vitest covers bucketing, cohort composition, Brier math, and the schema guards on confidence range and state/outcome enums (18 tests). Mounts in both api/app.ts (AppType source) and pages/api/[...slug].ts (the inlined runtime app, per the existing dual-mount pattern). db/client.ts now wires the uncertainty schema through drizzle. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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 #99. Stacks on #109.
Four endpoints under /api/uncertainty, all gated by requireAuth:
Pure cohort/Brier helpers live in api/lib/uncertainty/cohort.ts so they unit-test without dragging Hono or D1 into the test surface. 18 tests cover bucketing, cohort composition, Brier math, and the schema guards on confidence range and the state/outcome enums.
Mounts in both api/app.ts (AppType source) and pages/api/[...slug].ts (the inlined runtime app, per the existing dual-mount pattern). db/client.ts now wires the uncertainty schema through drizzle.