Repository navigation
feat(aggregator): forecast backtest + calibration report (#3986) - #8436
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 58 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 40e0a9e3bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const parsed = JSON.parse(await readFile(forecastsPath, "utf8")) as ForecastContract[] | { forecasts: ForecastContract[] }; | ||
| const forecasts = Array.isArray(parsed) ? parsed : parsed.forecasts; |
There was a problem hiding this comment.
Accept the actual forecast API response in the snapshot command
When --forecasts contains the documented /api/forecasts.json response, this reads undefined: the handler in src/server.ts returns a contracts array, not forecasts. createSnapshot then throws while iterating it, so the advertised capture workflow cannot write a snapshot. That API also includes stall-risk and quota contracts, which createSnapshot deliberately rejects. Extract the actual API field and select epic-completion contracts at the CLI boundary while retaining the store's strict validation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5cb77a4 (task 17228, lane any-c). The CLI now accepts the actual /api/forecasts.json shape: when the parsed file carries a contracts array, it selects the epic_completion contracts at the CLI boundary before calling createSnapshot, which keeps its strict validation for direct callers. Bare arrays and {forecasts} files pass through unfiltered, so mixed files in those shapes still fail loudly. Regression test: "forecast-snapshot CLI captures the /api/forecasts.json contracts shape" spawns the CLI on a fixture API response containing quota-exhaustion and stall-risk contracts and asserts only the epic contract is stored. bun test test/backtest.test.ts passes 13/13.
| const outcome = outcomeBySubject.get(f.subjectRef); | ||
| const completedMs = outcome?.completedAt ? Date.parse(outcome.completedAt) : null; | ||
| if (completedMs === null || completedMs > asOfMs) { | ||
| unresolved++; | ||
| continue; |
There was a problem hiding this comment.
Exclude outcomes completed before the forecast origin
When a captured subject was already complete at its forecast origin, this still adds it to the scored forecasts because the only completion-time check is against the evaluation date. This occurs with existing production derivation: allForecastContracts retains subjects from historical item cutoffs, and deriveEpicEta returns p50 = p80 = asOf when all children are complete. Subsequent captures therefore repeatedly score already-known completions, assign their negative horizons to 2w, and inflate the resolved count and P80 coverage. Exclude already-completed subjects from prospective forecast scoring before updating metrics and calibration eligibility.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5cb77a4 (task 17228, lane any-c). Scoring now excludes any forecast whose outcome completed at or before the snapshot cutoff — the completion was known at the forecast origin — and counts it separately as excludedAlreadyComplete on the report instead of letting it inflate resolved counts, horizon buckets, or P80 coverage. Regression test: "excludes subjects already complete at the forecast origin" (a p50 = p80 = asOf subject completed before the cutoff is excluded; a genuinely prospective forecast still scores). bun test test/backtest.test.ts passes 13/13.
| const baseRows = rows.filter((r) => r.baselineErrorDays !== null); | ||
| if (baseRows.length > 0) { | ||
| const modelMed = median(rows.map((r) => r.etaErrorDays)); | ||
| const baseMed = median(baseRows.map((r) => r.baselineErrorDays!)); |
There was a problem hiding this comment.
Compare model and baseline errors on the same subjects
When a cutoff contains both continuing subjects and first-seen subjects, modelMed includes every forecast while baseMed includes only forecasts with a predecessor. For example, a continuing forecast improving from 10 days of baseline error to 5 days of model error is still marked worse if two new subjects have 100-day errors. Repeating that mix for two cutoffs can incorrectly set recommendUnavailable; the opposite mix can hide a real regression. Compute both medians over baseRows so the retirement decision compares paired observations.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5cb77a4 (task 17228, lane any-c). The window comparison now computes the model median over baseRows — the same paired subjects that have a baseline — so first-seen subjects no longer enter the model median alone and the subject mix cannot drive persistentlyWorseThanBaseline / recommendUnavailable. Regression test: "compares model and baseline errors over the same subjects" builds two windows where unpaired medians would flag worse (52.5 > 40, 51 > 5) while the paired comparison shows the model improving (5 < 40, 2 < 5), and asserts the flag stays false. bun test test/backtest.test.ts passes 13/13.
| const worse = successive(windowWorse); | ||
|
|
||
| const allGroup = groupMetrics(scored, "all", "all"); | ||
| const gateMet = scored.length >= CALIBRATION_MIN_RESOLVED && cutoffs.length >= CALIBRATION_MIN_CUTOFFS; |
There was a problem hiding this comment.
Require resolved evidence across eight weekly cutoffs
When seven weekly snapshots contain only unavailable forecasts (p50: null) and the eighth contains 30 forecasts that later resolve with 80% P80 coverage, this gate returns calibrated: cutoffs includes every stored snapshot, although all scored evidence comes from a single weekly origin. This bypasses the documented minimum of 30 resolved forecasts across eight weekly cutoffs. Derive the gate's cutoff count—and the corresponding eligibility check above—from weekly cutoffs contributing scored forecasts rather than all captured snapshots.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5cb77a4 (task 17228, lane any-c). The gate now derives its cutoff count from weekly cutoffs contributing scored forecasts (scoredCutoffs), and the per-window eligibility check uses the scored-cutoff count accumulated so far; calibration.distinctCutoffs reports the scored count. Snapshots whose forecasts are all unavailable (p50 null) no longer count toward the eight-cutoff minimum. Regression test: "calibration gate counts only cutoffs contributing scored forecasts" reproduces your scenario — seven unavailable-only snapshots plus one snapshot with 30 forecasts resolving at 80% P80 coverage — and asserts distinctCutoffs is 1 and the state stays not_yet_calibrated. bun test test/backtest.test.ts passes 13/13.
|
Agent note — task 17228 picked up (lane any-c)
|
#8436) 1. forecast-snapshot CLI: accept the actual /api/forecasts.json shape (contracts array) and select epic-completion contracts at the CLI boundary; the store keeps its strict validation for direct callers. 2. Scoring excludes subjects already complete at the forecast origin (counted as excludedAlreadyComplete), so known completions no longer inflate resolved counts or P80 coverage. 3. Worse-than-baseline windows compare model and baseline medians over the same paired subjects. 4. The calibration gate counts weekly cutoffs contributing scored forecasts, not all captured snapshots. Each fix carries a regression test; bun test test/backtest.test.ts passes 13/13.
40e0a9e to
5cb77a4
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Agent note — task 17228 done: fixed_merged (lane any-c)
|
Closes #3986.
What lands
Forecasts (ETA bands #3982, contract objects #3984) were published with no measurement of usefulness or calibration. This adds the measurement, in
pm-stack/aggregator:src/backtest.ts):createSnapshot/appendSnapshot/loadSnapshotsfreeze weekly forecast captures as JSONL — model version, cutoff, source watermarks, and the full epic-completion contract objects (the minimal reproducible inputs: scope, input window/coverage, remaining units, reasons). One snapshot carries exactly one model version; mixed versions and non-epic contracts are refused at capture.calibratedstate before 30 resolved forecasts across 8 distinct cutoffs; P80 coverage outside 70–90% in two successive eligible windows, or a model persistently worse than baseline, flags the report and setsrecommendUnavailable(the documented disable/revert-to-unavailable rule).not_evaluated: the aggregator: forecast per-pool quota exhaustion intervals #3983 outcome history does not exist yet and the issue scope excludes it until it does. No forecast-derivation semantics change.scripts/forecast-snapshot.ts(the weekly capture job) andscripts/backtest-report.ts(evaluate a store + outcome history, print the report).Tests
bun test test/backtest.test.ts— 9/9 pass: store round-trip + capture refusals, median-error/P80 metrics by horizon and grade, cutoff isolation (future-captured snapshot and late-recorded outcome are invisible), model-version separation, baseline scoring, and the calibration gate (calibrated / flagged / not-yet).forecast-3982+forecast-contract-3984: 48 pass, 1 fail — the failure is a 5s timeout inderiveEpicEta > partially censored distribution (#6386)that reproduces identically on clean main in the primary clone (pre-existing, untouched by this change).bunx tsc --noEmit: 24 errors, the same 24 as clean main; none in the new files.Queue: task 14816, lane code-e.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.