perf(d-3 followup): harden compare.exs against schema drift (standards#99)#30
Merged
Merged
Conversation
…s#99) Phase D-3 follow-up under the single-lane HCG tier-2 channel (standards#91). PR #26 (D-4 bootstrap) deferred this as a "separate defensive D-3 follow-up, not coupled to D-4 collection": when bench/baseline.json `_status` is flipped to `active`, a scenario present in results.json but absent from baseline.json (a new harness scenario landed without rebaseline) silently passed the gate, and a scenario present in baseline.json but absent from results.json (the harness dropped a scenario without rebaselining) was never even checked. Both directions of schema drift now fail-closed in active mode and surface as informational "scaffold (would fail: ...)" rows in scaffold-placeholder mode so a rebaseline PR previews the active-mode verdict before the gate is armed. The comparator now iterates the union of scenario names across results and baseline rather than the results map alone, and uses a single `enforce: bool` opt to pivot between scaffold and active mode (replaces the previous `nil` sentinel). check_regression/5 also has a latent crash fixed in the process — when baseline values are TODO sentinels (or any non-number), num/1 returns nil and the `or` chain raises BadBooleanError; the inner `&&` short-circuit already returns nil for unknowns, so the outer joins are switched from `or` to `||` to match. Previously this was masked by scaffold mode never reaching check_regression at all (the `nil` sentinel skipped it); the new flow exposes that path in scaffold mode too. docs/perf-contract.md gains a "Schema drift" section explaining the two directions, the active vs scaffold display difference, and the fail-closed semantic. The behaviour pivots on `_status` in bench/baseline.json — no code change is needed to arm the schema checks once Phase D-4 maintainer-only rebaseline + active flip lands. Smoke-tested locally against synthetic results/baseline fixtures (four cases: active+drift→regressed, scaffold+drift→ok-with-warnings, active+clean→ok, active+TODO-sentinels→ok-no-crash). Build is not verified end-to-end — the session environment has Elixir 1.14 only, no Elixir 1.19 / OTP 28 toolchain — but Code.format_string!/1 reports the file is already formatted and Code.string_to_quoted!/1 round-trips under 1.14. Repo CI (`Perf Regression`, governance, hypatia-scan, dogfood-gate, codeql, scorecard) is the verification gate. Refs hyperpolymath/standards#91 Refs hyperpolymath/standards#99 NOT Closes #99: joint-close is owner-only; D-4 baseline collection plus the `_status` flip to active still pend under #99 after this lands. Same posture as PRs #14, #22, #26. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🔍 Hypatia Security ScanFindings: 65 issues detected
View findings[
{
"reason": "Issue in boj-build.yml",
"type": "missing_timeout_minutes",
"file": "boj-build.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in casket-pages.yml",
"type": "missing_timeout_minutes",
"file": "casket-pages.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in casket-pages.yml",
"type": "missing_timeout_minutes",
"file": "casket-pages.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in codeql.yml",
"type": "missing_timeout_minutes",
"file": "codeql.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in dogfood-gate.yml",
"type": "missing_timeout_minutes",
"file": "dogfood-gate.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in dogfood-gate.yml",
"type": "missing_timeout_minutes",
"file": "dogfood-gate.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in dogfood-gate.yml",
"type": "missing_timeout_minutes",
"file": "dogfood-gate.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in dogfood-gate.yml",
"type": "missing_timeout_minutes",
"file": "dogfood-gate.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in dogfood-gate.yml",
"type": "missing_timeout_minutes",
"file": "dogfood-gate.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in governance.yml",
"type": "missing_timeout_minutes",
"file": "governance.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
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.
Summary
Phase D-3 follow-up under the single-lane HCG tier-2 channel (
standards#91). PR #26 (D-4 bootstrap) deferred this as a "separate defensive D-3 follow-up, not coupled to D-4 collection": oncebench/baseline.json_statusis flipped toactive(which the D-4 ritual eventually does), two directions of schema drift betweenbench/results.jsonandbench/baseline.jsonsilently passed the gate. This PR closes both.Refs hyperpolymath/standards#91Refs hyperpolymath/standards#99The gap
The comparator's old
emit_table/3iterated over results scenarios only and letcheck_regression(nil, …)fall through to"no baseline", which never bubbled up to the:regressedexit:Map.get(baseline, name)returnsnil→check_regression(nil, …)returns"no baseline"→reducekeepsacc = :ok→ exit 0. The gate has no anchor for the new scenario, so it cannot meaningfully report regression for it, but it should say so instead of silently passing.Enum.reduce(stats, …)body at all → invisible in the report and exit 0. A scenario was removed (or the harness crashed before emitting it) and the gate did not notice.In
scaffold-placeholdermode the existing code was fine — every row was tagged"scaffold"and the build exited 0 unconditionally — but it gave operators no preview of how the eventual active-mode verdict would look.What changed
bench/compare.exsemit_table/4now iterates the union of scenario names fromresults.statisticsandbaseline.scenarios(sorted lexicographically), so both drift directions are visible.MISSING IN BASELINEMISSING IN RESULTSenforce: boolopt replaces the previousnilbaseline sentinel —compare/2now always passesMap.get(baseline, "scenarios", %{})and usesenforce: falseinscaffold-placeholdermode,enforce: trueinactivemode.enforce: falserows are displayed asscaffold (would fail: MISSING IN BASELINE)etc. so a rebaseline PR previews the active-mode verdict; the build still exits 0.enforce: truerows are displayed as bareMISSING IN BASELINE/MISSING IN RESULTS/REGRESSEDand the comparator exits 1 if any row is drift.check_regression(nil, _, _, _, _) -> "no baseline"clause is removed.TODOsentinels (or any non-number),num/1returnsnil, and the old(bp50 && p50 && p50 > bp50 * t50) or (…) or (…)chain raisedBadBooleanErrorbecausenil or nilis not a validor. Inner&&already short-circuits tonil; the outer joins are now||so the whole expression short-circuits consistently. Previously masked because scaffold mode never reachedcheck_regression; the new flow does, so this had to be fixed in the same PR.docs/perf-contract.md## Schema driftsection between## Regression-alert toleranceand## Baseline lifecycledocuments the two directions, the active vs scaffold display difference, and the fail-closed semantic.compare.exsto mention that drift is now surfaced inline.Behaviour matrix (smoke-tested)
_status)scaffold (would fail: MISSING IN BASELINE)scaffold (would fail: MISSING IN RESULTS)scaffoldscaffold (would fail: REGRESSED)MISSING IN BASELINEMISSING IN RESULTSok(TODO parses as nil → no breach)REGRESSEDokThe behaviour pivots on
_statusinbench/baseline.json— no code change is needed to arm the schema checks once the D-4 rebaseline + active flip lands.Local verification
Smoke-tested via a synthetic-fixture harness against the four named cases (active-with-drift →
:regressed, scaffold-with-drift →:okwith(would fail: …)rows, active-clean →:ok, active-TODO-sentinels →:okno crash). Output matched expected status strings and exit returns in every case.Build was not verified end-to-end — the session environment has Elixir 1.14 only, no Elixir 1.19 / OTP 28 toolchain — but
Code.format_string!/1reports the file is already formatted andCode.string_to_quoted!/1round-trips under 1.14. The existingperf-regression.ymlworkflow exercises the comparator end-to-end on CI.Test plan
Perf Regressionworkflow runsmix run bench/compare.exsend-to-end and posts a scaffold-mode markdown report (still non-blocking —_statusisscaffold-placeholder).mix teststill passes —bench/compare.exsis not exercised bymix test; no production-code change in this PR.Statuscolumn should still readscaffoldfor every scenario unless a true drift is present._statusis flipped toactive, the comparator exits 1 on anyMISSING IN BASELINE,MISSING IN RESULTS, orREGRESSEDrow.Downstream unblock
The boj-server rollout-prerequisite checklist in
docs/integration/hcg-tier2-rollout-runbook.md§1.1 lists "Phase D-3 (gate armed)" and "Phase D-4 (numbers populated)" as the remaining open items gating Phase E rollout. This PR doesn't tick either box directly — neither requires schema-drift hardening — but it hardens the gate before it gets armed, so the first time_statusflips toactivethe gate already covers the failure modes a future scenario rename / removal would otherwise hide.Owner merges; not for admin-merge.
🤖 Generated with Claude Code
Generated by Claude Code