Repository navigation
feat(shadow-eval): skip redundant reverse evaluations on opt-in - #52192
Conversation
…erved A reverse shadow eval judges the router's response against baseline_model. When the router itself sent the request to the baseline's model group, the comparison only produces ties and still pays for a shadow and a judge call. Reverse jobs can now opt in with skip_same_model. A sampled request whose served group (router alias resolved, fallback hops respected) is the baseline's own group is counted in a new same_model funnel stage instead of being judged. It makes no provider calls, writes no attempt row, and leaves max_turns and the eval budget untouched. When the served group is unknown the sample is judged as before. The job detail reports same_model_skipped_count even when nothing has been judged yet. The flag defaults to false and is rejected on forward jobs, so existing jobs and requests behave exactly as before. Adds two columns through an additive, schema-only migration.
…n signals Judged cases now wait on the attempt write the injected prisma reports, then await the pipeline task that made it. Skip cases drain only the tasks the hook created, through a task factory scoped to the hook call, before asserting that no provider call, attempt row, or spend was recorded. This replaces a whole-loop task diff and the assertion on the number of tasks. Adds a skip case with tier parameter overrides, which the policy still treats as the same group, and a case showing a lost sampling roll counts as not_sampled before same_model. Drops the class docstring claim that a same group comparison only produces ties.
|
bugbot run |
[Medium impact] The PR appears safe to merge with no actionable findings.
|
The generated request type now requires skip_same_model, which broke the dashboard typecheck and builds. The form sends false, the API default, so jobs started from the UI behave exactly as before.
|
bugbot run |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3d7a83f. Configure here.
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Handwritten 1-3 sentence description
Details
TLDR
Problem this solves:
How it solves it:
skip_same_modelflag for reverse jobs.User Flow
Before, a reverse job evaluates requests already served by its baseline group.
POST /auto_router/shadow_eval/startand a baseline model.GET /auto_router/shadow_eval/{job_id}and see another judged sample.After, an opted-in reverse job records the redundant sample as skipped.
skip_same_model: true.same_model_skipped_countincrease, with no added verdict or spend.The flag defaults to false. The existing dashboard form sends false explicitly to preserve its behavior and satisfy the generated request type. Different model groups still evaluate, including groups backed by the same provider model. Aliases resolving to the same group skip. The baseline is never replaced. Unknown served-group metadata conservatively keeps evaluation enabled. The policy compares model groups even when tier parameters differ.
Pre-Submission checklist
Type
New Feature
Caveats
Low
The Responses limitation is pre-existing and unchanged in the matching run. It does not prove a successful different-group evaluation through that surface. Chat completions and Anthropic Messages do demonstrate that flow. No unrelated repair is included.
Screenshots / Proof of Fix
Baseline
49b2058c1a7ef71764fd756d1f091445071cabed. Current tip3d7a83fa400d74430aec6c23d1c0e42fc7fe6bd4passes independent live verification of matching groups, different groups, and the omitted flag. The full surface matrix passed at2b2a1ca984b8e79c8effa9bf5a290b170cc4e246. Only the migration lock timeout changed afterwards. Current-tip checks report 106 success and two expected skips. Greptile rated the tip 5/5, and Bugbot and Veria found no issues.Independent Devin verification ran source builds with two proxy workers, Redis, and PostgreSQL. At the current tip, the three mapped test files pass with 444 tests and the affected UI suite passes with 42 tests. Changed Python executable-line coverage is 33/33. Branches from changed Python lines are 12/12. These are changed-code figures, not repository-wide coverage. The one production TypeScript line is asserted by four payload tests but has no separate local line-coverage measurement. Codecov reports all modified coverable lines covered, and its current-tip patch check passes.
Ruff lint and source formatting, strict rules, type discipline, test quality, OpenAPI docs, basedpyright, and the MCP operation boundary passed at
9ff40fb65581472df4b92292192aae245d8256e1. Subsequent changes remove two extra blank lines, explicitly send the default false flag from the existing UI form, and add the required migration lock timeout. These gates also pass in current-tip CI. Generated API types and the lazy OpenAPI snapshot match. Applying the additive migration to the baseline schema matches the candidate schema, and a second apply is idempotent. No rows are rewritten. The migration starts with the required 10-second local lock timeout.Baseline sensitivity ran the new tests from an external copy against the baseline. Seven skip tests failed because
acompletionwas called twice. They pass at the candidate. This demonstrates the unwanted calls, not just a missing configuration field.Shared setup
The executed layout was
~/verif/shadow/{base,head,final,run,art}. The reusable Python environment was~/repos/litellm/.venv. PostgreSQL was on port 5432 and Redis on port 6379. Required environment variables areANTHROPIC_API_KEY,DATABASE_URL,LITELLM_MASTER_KEY, andLITELLM_SALT_KEY. Localrun/master.keyandrun/salt.keyheld the latter two values. No values are included here.Baseline used database
shadow_base. Candidate usedshadow_head, initialized with the baseline schema and then the new migration. The Prisma client for the candidate was generated from its schema outside tracked source intorun/prisma_headand prepended toPYTHONPATH.The baseline schema push was applied to each task database. The migration diff printed
This is an empty migration.Executed source builds and proxy commands
The final worktree reused the native extension built at
9ff40fb6558. Subsequent changes do not touch native source. Both copies have SHA25691a7a0e67647aeed52a8583198f77b093dd828cd1e5eb215b92621ab27e8402a.Baseline start script
Final start script
Both logs confirmed two server workers. Reload was omitted to serve with two workers. The migration resolver flag was omitted because the schema was applied explicitly above.
Executed config_final.yaml
The deliberately invalid key on the unused fallback fixture is not a credential.
Executed matrix4.py with accounting completion checks
The script waits for a real spend log and exactly one attempt or funnel outcome per job, with the corresponding shadow and judge logs. Timeouts fail the run. The initial 12-second wait allows the documented 10-second job-cache TTL to expire. The script SHA256 is
5ada421a648ed4cfeffddbd9d754bca23d24b9275cb5370111dd466e22ebac5d.Before (49b2058)
SIDE=base PORT=4310 DBNAME=shadow_base python run/matrix4.py art/matrix4_base.json.RESULT PASSfor the baseline expectations below.After (4a683d6)
SIDE=final PORT=4311 DBNAME=shadow_head python run/matrix4.py art/matrix4_final.json.RESULT PASSfor the final expectations below.Skipped cases have zero evaluation spend, zero judged samples, and
same_model: 1in the funnel. Evaluated final cases measured $0.000172 for the shadow and $0.003088 for the judge. These are observed run costs, not fixed vendor-price assertions.Additional cases for distinct groups sharing a provider model, mixed skipped/judged traffic, an explicit false flag, and forward jobs passed at
9ff40fb6558. Python evaluation code is identical at the final tip. Those cases used the earlier Sonnet judge and were not rerun with the Opus judge. Mixed traffic kept the quality denominator at one judged sample and reported the two skips separately.Final-tip refresh
At
3d7a83fa400d74430aec6c23d1c0e42fc7fe6bd4, Devin ran the same two-worker source proxy with the same config and latest-family provider models.run/matrix5.pyis the client above with this filter after theCASESdefinition.The command returned
RESULT PASS. Matching groups produced zero shadow calls, zero judge calls, zero attempts, zero evaluation spend, and one skip. Different groups and the omitted flag each produced one shadow call, one judge call, and one judged attempt with no skips. The observed shadow and judge costs were $0.000172 and $0.003088 respectively.The final migration passed against a scratch database with the baseline schema using
psql --single-transaction -v ON_ERROR_STOP=1. The timeout was10sinside the transaction and0after commit. A second application skipped the existing columns successfully. Schema comparison was empty. A failing statement in the same transaction rolled back both new columns. This tested PostgreSQL transactions directly, not the proxy migration resolver.Exact-tip focused test commands
Both exit zero, with 444 backend tests and 42 UI tests passed. The UI typecheck and build also passed in CI. Existing UI lint warnings occur in unchanged test lines and the build's existing AVIF asset warning is unchanged.
Final Attestation