← Back to Pull requests

fix(event_handler): match exact routes before catch-all regex routes #8881

Open
unknown opened this pull request with 284 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 21, 2026 07:38 UTC
Author

<!-- markdownlint-disable MD041 MD043 -->
Issue number:

closes #8879

Summary

Changes

A regex rule without named groups, such as /proxy/.+, has rule.groups == 0, so route() stored it in _static_routes next to exact rules, and _resolve matched them in registration order. A catch-all registered before /proxy/health took 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 a Router go through route() 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/health returns {"route":"catch-all"}.

After: it returns {"route":"health"}, as the "Route Matching Priority" box in the Catch-all routes docs says. GET /proxy/other still goes to the catch-all.

Verification

  • New functional tests in 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 prefixed Router. Two of the three fail on develop (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_found and test_openapi_encode_purepath, also fail on develop: they are Windows path-separator issues on my machine, unrelated to this change.

  • ruff format --check, ruff check and mypy clean on the changed files.

  • The issue's repro script now prints {"route":"health"} for /proxy/health and {"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.

    Diff: 284 lines (+213 / -71) across 3 files Reviewer: bardrop Review duration: 1095m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.2% · Safe to merge
    21.2%