From 7e53959bfa72903289b3b46bc0450be04d781e45 Mon Sep 17 00:00:00 2001 From: Sean Silvius Date: Mon, 27 Apr 2026 22:05:11 -0700 Subject: [PATCH 1/2] Add D1 migration for uncertainty engine tables Closes #97. Phase 1 of the uncertainty engine spike. Two tables per docs/designs/uncertainty-engine.md schema section: - uncertainty_prediction: emit + witness lifecycle (state machine over emitted | witnessed | orphaned | retired). Indexes on cohort_key, surface, state, and (state, orphan_after) to support the orphan sweep. - uncertainty_calibration_snapshot: materialized reliability per cohort, recomputed by the nightly calibration cron. Indexed on cohort_key. Created via wrangler d1 migrations create. Applied locally; both tables present and indexes verified. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../db/migrations/0002_uncertainty_engine.sql | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 apps/web/src/db/migrations/0002_uncertainty_engine.sql diff --git a/apps/web/src/db/migrations/0002_uncertainty_engine.sql b/apps/web/src/db/migrations/0002_uncertainty_engine.sql new file mode 100644 index 0000000..c73efb4 --- /dev/null +++ b/apps/web/src/db/migrations/0002_uncertainty_engine.sql @@ -0,0 +1,38 @@ +-- Migration number: 0002 2026-04-28T05:04:33.321Z +CREATE TABLE `uncertainty_prediction` ( + `id` text PRIMARY KEY NOT NULL, + `surface` text NOT NULL, + `feature_key` text NOT NULL, + `input_fingerprint` text NOT NULL, + `model` text NOT NULL, + `model_version` text NOT NULL, + `claimed_confidence` real NOT NULL, + `prediction_payload` text NOT NULL, + `state` text NOT NULL, + `outcome_label` text, + `outcome_payload` text, + `outcome_correctness` real, + `created_at` integer NOT NULL, + `witnessed_at` integer, + `orphan_after` integer NOT NULL, + `cohort_key` text NOT NULL +); +--> statement-breakpoint +CREATE INDEX `idx_uncertainty_prediction_cohort` ON `uncertainty_prediction` (`cohort_key`);--> statement-breakpoint +CREATE INDEX `idx_uncertainty_prediction_surface` ON `uncertainty_prediction` (`surface`);--> statement-breakpoint +CREATE INDEX `idx_uncertainty_prediction_state` ON `uncertainty_prediction` (`state`);--> statement-breakpoint +CREATE INDEX `idx_uncertainty_prediction_orphan_sweep` ON `uncertainty_prediction` (`state`, `orphan_after`);--> statement-breakpoint +CREATE TABLE `uncertainty_calibration_snapshot` ( + `id` text PRIMARY KEY NOT NULL, + `cohort_key` text NOT NULL, + `bucket_lower` real NOT NULL, + `bucket_upper` real NOT NULL, + `claimed_confidence` real NOT NULL, + `actual_correctness` real NOT NULL, + `prediction_count` integer NOT NULL, + `orphan_count` integer NOT NULL, + `brier_score` real NOT NULL, + `computed_at` integer NOT NULL +); +--> statement-breakpoint +CREATE INDEX `idx_uncertainty_calibration_snapshot_cohort` ON `uncertainty_calibration_snapshot` (`cohort_key`); From 8f8887bcc4405d381dfaeaeff2da6719ee56e506 Mon Sep 17 00:00:00 2001 From: Sean Silvius Date: Mon, 27 Apr 2026 22:39:03 -0700 Subject: [PATCH 2/2] Re-run CI on public repo