feat(gate): route cost-regression blocking through the policy engine#189
Merged
Conversation
Cost-regression already blocks a PR, but through the analyzer's old inline path, so a repo couldn't set it to warn/off the way it can for untested-data-access (#183) and schema-drift (#188). Route the regression arm through resolveVerdict/policyFor, matching those two conditions. regression-beyond-threshold is a finding in the shared taxonomy and defaults to fail, so a repo that sets nothing blocks exactly as before. warn caps it at a surfaced, non-blocking neutral; off suppresses it. The new-query gate is left on its inline setFailed: its default policy is warn, so routing it through resolveVerdict would silently stop it blocking — a behavior change that needs a separate human sign-off. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Query Doctor Analysis
3 queries analyzed
0 regressed · 0 improved · 0 new · 0 removed
2 pre-existing issues
SELECT "guests"."id", "guests"."session_id", "guests"."username", "guests"."avatar_path", "guests"."color", "guests"."side", "guests"."audio_recording_path", "guests"."audio_recording_public", "gue...
indexassets(event_id, inserted_at desc)
cost 31,003,449 → 1,498 (100% reduction)SELECT * FROM guest_ip_addresses WHERE ip_address = '127.0.0.1';
indexguest_ip_addresses(ip_address)
cost 154,402 → 8 (100% reduction)
Using assumed statistics (10000000 rows/table). For better results, sync production stats.
More detail → get_ci_run({ runId: "019f8b70-00d7-7a0d-8744-52a307a36dee" }) · view run · docs
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.
Goal
Cost-regression already blocks a PR, but through the analyzer's old inline path. A repo can set
untested-data-access(#183) andschema-drift(#188) towarn/offper-repo; it couldn't do the same for regression. This routes the regression gate through the shared policy engine so it's overridable the same way.Regression already fails today, so this adds no new blocking — only per-repo overridability.
What
Before: a beyond-threshold, untriaged cost regression always fails the check, with no way to soften it. After: the same regression still fails by default, but a repo can set the
regression-beyond-thresholdpolicy towarn(surfaced, non-blocking) oroff(suppressed) in CI settings, exactly as it already can for the other two conditions.regression-beyond-thresholdis afindingin the shared taxonomy (concludesfailure) and defaults tofailinDEFAULT_CONDITION_POLICIES, so a repo that configures nothing is unaffected.How
src/gate/regression.ts(new) — a pure helpergateRegression(regressedCount, policyConfig)that builds the{ condition: "regression-beyond-threshold", verdictClass: "finding" }verdict, runs it throughresolveVerdict, and returns{ conclusion } | null. MirrorsgateSchemaChangefrom feat(gate): block PRs with schema changes (gate the API's signal) #188. Detection is not its job; it only decides the check outcome from a count already computed upstream.src/main.ts— the regression arm insideif (reportContext.comparison)now callsgateRegressionand emitscore.setFailedonfailure,core.warningonneutral. The per-query message text (previews, cost delta, dashboard links) is unchanged. Regression and new-query now emit their own annotations instead of one joinedsetFailed, consistent with how the test-presence gate already callssetFailedindependently just above.regressedis already the untriaged, beyond-threshold set (compareRunsfilters byacknowledgedQueryHashesandregressionThreshold), so the gate does not re-filter.New-query gate left untouched, on purpose.
gateEligibleNewQueries(a new query shipping a high-impact index) currently blocks via inlinesetFailed. Butnew-querydefaults towarninDEFAULT_CONDITION_POLICIES, so routing it throughresolveVerdictwould silently stop it blocking. That may be desirable, but it's a behavior change to sign off on separately. This PR is regression only.Triage vs. policy — two override layers
regressedis untriaged already, so there are now two independent override layers:regression-beyond-thresholdpolicy applies to whatever survives triage:offsuppresses the whole condition regardless of triage;warnsurfaces all untriaged regressions without blocking;fail(default) blocks them as today.Tests
src/gate/regression.test.ts— the pure helper: blocks by default,warn→neutral,off→null, zero regressions →null.npm test -- run→ 321 passing (32 files). Typecheck clean; build succeeds. (The pre-existingsite-api.test.tsred and theapi-client.tstype errors noted in the hand-off were already resolved onmainby the@query-doctor/core ^0.14.0adoption.)🤖 Generated with Claude Code