feat(calibration): counterfactual prompt replay — offline harness + budget-gated advisory CI check#8271
Conversation
…udget-gated advisory CI check (#8221, #8222) Closes the #8218 sub-epic's phases 3+4 against the #8219 contract verbatim: - scripts/counterfactual-replay-core.ts (pure, unit-tested): abstention-safe variant-output parsing (never coerced), scoreBacktest mapping over the #8220 fixture plan, budget arithmetic + resume cursor, run-accounting invariant, artifact cache keys, Pareto baseline comparison - scripts/counterfactual-replay.ts (thin IO): ollama smoke path only (BYOK refused loudly), raw outputs cached under a local artifacts dir so re-scoring is free, --baseline prints the shared renderer's comparison; exit reflects operational success only, never verdict - src/services/ai-review.ts: REVIEW_PROMPT_VERSION + buildCanonicalJudgePrompt (the pure, input-free judge prompt the dual-checkout replay diffs) - scripts/print-review-prompt.ts: the #8139 dual-checkout extractor - .github/workflows/counterfactual-replay-check.yml: path-filtered on the judge-prompt surface, hard-gated on an explicitly configured replay budget (visible skipped-notice otherwise), byte-identical prompts short-circuit, fail-open on every step, update-in-place marker comment, persisted calibration.counterfactual_backtest_run events feeding the SAME REGRESSED-verdict track record as the threshold/logic backtests - docs: worked ollama example + the prompt-change workflow
Logic backtestReplayed 0 historical case(s) for Backtest comparison:
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
loopover-ui | 7d81d1a | Commit Preview URL Branch Preview URL |
Jul 23 2026, 09:47 PM |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Bundle ReportChanges will increase total bundle size by 8.42kB (0.11%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: loopover-uiAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8271 +/- ##
=======================================
Coverage 92.16% 92.16%
=======================================
Files 786 786
Lines 78941 78943 +2
Branches 23840 23840
=======================================
+ Hits 72757 72759 +2
Misses 5062 5062
Partials 1122 1122
Flags with carried forward coverage won't be shown. Click here to find out more.
|
orb-v3.3.0 shipped stable, so the beta cutter is idle until the manifest's declared target moves forward. The calibration-expansion epic's merges since (per-repo loosening #8264, reviewer votes #8265, tightening #8267, AMS loop #8270, counterfactual replay #8271) are feats — the inferred bump is minor, so the next automated snapshot targets orb-v3.4.0-beta.1.
Summary
Closes #8221. Closes #8222. (Phases 3+4 of sub-epic #8218, one PR per the fewer-larger-PRs direction.)
Implements the #8219 contract verbatim — every shape cited, none re-invented:
scripts/counterfactual-replay.tswith the pure core incounterfactual-replay-core.ts(the backtest-corpus-export split). Abstention-safe verdict parsing (string-aware balanced-object extraction; anything unparseable is counted, never coerced),scoreBacktest/compareBacktestScoresapplied unchanged over the counterfactual: pure fixture assembler — replayable cases from the raw-context corpus #8220 fixture plan, neuron-budget arithmetic with a first-gap resume cursor, a run-accounting invariant asserted before any artifact persists, and a content-keyed raw-output cache under a local artifacts dir so re-scoring is free. Ollama is the only wired provider (BYOK refused loudly, per the contract); exit codes reflect operational success only — never a verdict.REVIEW_PROMPT_VERSION+buildCanonicalJudgePrompt()insrc/services/ai-review.ts(pure, input-free — the exact default-config system prompt), extracted per checkout byscripts/print-review-prompt.ts(the Extend the backtest check to logic/regex changes via a dedicated CI job, using captured raw context #8139 dual-checkout mechanism, sentinel-tolerant for pre-counterfactual: advisory check when reviewer prompt versions change #8222 bases)..github/workflows/counterfactual-replay-check.yml, path-filtered on the judge-prompt surface. Hard spend guard first: without the explicitly configuredCOUNTERFACTUAL_REPLAY_BUDGET/COUNTERFACTUAL_REPLAY_MODELvariables + provider secret it posts a visible "skipped: no replay budget configured" notice and does nothing else. Byte-identical base/head prompts short-circuit; the sample seed is the head SHA (deterministic per push); every step fails open; the comparison lands as an update-in-place marker comment; each run persists acalibration.counterfactual_backtest_runevent feeding the SAME REGRESSED-verdict track record as the threshold/logic backtests (backtest-track-record.tsnow aggregates all three siblings).qwen3:8bis finishing — the mechanism already ran end-to-end: 40 scored / 0 abstained / 0 accounting drift on the seeded production sample).Validation
npm run test:ci: green except one unrelated suite (test/unit/miner-package-skeleton.test.ts) that hit the known subprocess-spawn timeout while two gates ran concurrently on this machine — 6/6 standalone in this worktree; no miner packaging file is touched here.npm audit --audit-level=moderateclean;actionlintclean on the new workflow.src/**diff (the two new exports); the core has 12 tests covering every parsing/scoring/accounting arm.