fix(event_handler): match exact routes before catch-all regex routes #8881
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 284 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.338
Real PR Conversation Timeline
1 comments
"Review active on #8881"
general
weight: 0.35
bardrop
<!-- markdownlint-disable MD041 MD043 -->
Issue number:
closes #8879
Summary
Changes
A regex rule without named groups, such as
/proxy/.+, hasrule.groups == 0, soroute()stored it in_static_routesnext to exact rules, and_resolvematched them in registration order. A catch-all registered before/proxy/healthtook its requests.route()now inserts exact static rules (no regex metacharacters) before regex static rules, so the order no longer depends on registration. This happens at registration; matching at request time is unchanged, and dynamic routes keep coming after static ones. Routes included from aRoutergo throughroute()too, so they are covered.Thanks @bardrop for the detailed report and repro.
User experience
Before: with
@app.get("/proxy/.+")registered before@app.get("/proxy/health"),GET /proxy/healthreturns{"route":"catch-all"}.After: it returns
{"route":"health"}, as the "Route Matching Priority" box in the Catch-all routes docs says.GET /proxy/otherstill goes to the catch-all.Verification
tests/functional/event_handler/required_dependencies/test_api_gateway.py, through the public API: both registration orders, and an exact route included later from a prefixedRouter. Two of the three fail ondevelop(the "exact registered first" case already worked) and all pass with the fix.pytest tests/unit/event_handler tests/functional/event_handler: 1288 passed, 1 skipped. Two failures,test_load_resolver_file_not_foundandtest_openapi_encode_purepath, also fail ondevelop: they are Windows path-separator issues on my machine, unrelated to this change.ruff format --check,ruff checkandmypyclean on the changed files.{"route":"health"}for/proxy/healthand{"route":"catch-all"}for/proxy/other.AI-assisted; I reproduced the bug, reviewed the change and ran the checks above myself.
---
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.