Skip to content

tech-debt(ci): the duplicate-route guard is AST-based and blind to include_router — a better one exists, abandoned #17325

Description

@mrveiss

The duplicate-route guard landing in #17314 reads @router.<verb> decorators out of the AST. It therefore cannot see any route mounted with router.include_router(other), and 16 non-test modules under autobot-backend/api/ compose that way — agent_terminal.py:218, auth.py:302, and 14 others.

So its "1518 distinct (method, path) pairs, 1 duplicate" is a floor, not a total. A duplicate between two included sub-routers is invisible to it.

A better guard already exists, and was abandoned

Commit f4e2d6badb on the local branch issue-16908-duplicate-routes rebuilt exactly this guard on real router objects:

  • calls load_core_routers() / load_optional_routers() — the same functions app_factory calls, so the population is the real one
  • walks effective_routes(), which resolves nested include_router() including an inner router's own prefix
  • carries a population-collapse assertion, so a broken import cannot make the guard pass by finding nothing

That file was removed from the branch by a later commit ("split guard out of #16918 per review") and never landed anywhere. It is 228 lines and complete.

This is the repository's own prior work being redone worse. The AST version exists only because I did not find the abandoned branch before writing it — rule 1, check before writing.

Why it was not simply adopted

It cannot be verified on this machine. Importing real routers pulls llc.scheduler.base, which raises:

RuntimeError: llc.scheduler.base requires asyncio.Task.cancelling() (Python 3.11+);
the platform floor is 3.14, and CI runs 3.14, but this interpreter is Python 3.10.

CI runs 3.14 and would execute it fine. Shipping a 228-line guard that I could not run once is not better than shipping a lesser one that I could — so the AST version ships with its blind spot pinned (COMPOSING_MODULES_PIN = 16, asserted, so the gap cannot quietly grow) and this issue carries the upgrade.

Acceptance criteria

  • The guard enumerates routes from real router objects, resolving nested include_router() with its prefix
  • It is verified by an actual run, not by reading — on an interpreter at the platform floor, or in CI
  • A population-collapse assertion fails the guard when the registry yields implausibly few registrations, so a broken import cannot pass as "no duplicates"
  • The AST version and its COMPOSING_MODULES_PIN are removed in the same change, not left beside it — two guards for one property is what this repository calls a fork
  • f4e2d6badb's content is the starting point, credited, rather than a third independent implementation

Related

Activity

  1. mrveiss commented on Sep 23, 2026

    @mrveiss
    OwnerAuthor

    The starting point is now durable: preserved/issue-16908-real-router-guard on origin.

    f4e2d6badb previously existed only as a local branch on one machine. An issue that names a commit as its starting point should not depend on one developer's reflog, so the branch is pushed under a preserved/ prefix — it is a reference, not work in flight, and the name says so.

    The guard file is at repo_tests/duplicate_route_registration_16908_test.py in that commit (228 lines). Note it is not at the branch tip — a later commit on the same branch (3a43f296a2, "split guard out of #16918 per review") removed it. Read it at the commit:

    git show f4e2d6badb:repo_tests/duplicate_route_registration_16908_test.py
    

    Why it could not be adopted directly, restated so nobody repeats the attempt and draws the wrong conclusion: it imports real routers, which pulls llc.scheduler.base, which refuses on anything below Python 3.11. This machine is 3.10 and CI is 3.14, so it will run in CI and cannot be run here. That is a limitation of the verification environment, not a defect in the guard.

    Also worth recording for whoever takes this: the blind spot is currently 16 non-test modules under autobot-backend/api/ composing via router.include_router(...), pinned and asserted in repo_tests/no_duplicate_route_registration_16908_test.py as COMPOSING_MODULES_PIN. That pin exists so the gap cannot grow unobserved while this issue is open — and it should be deleted along with the AST guard when the real-router version lands, not left beside it.

  2. mrveiss commented on Oct 17, 2026

    @mrveiss
    OwnerAuthor

    Sighting (external API report via #18717, verified on origin/main 0196c7c234): the guard also can't see the same module registered twice, because it keys on module:var and a repeat collapses to one set entry. Confirmed double mounts: admin_retention_policies (core_routers.py:154 + feature_routers.py:703), chat_embed (core:166 + feature:680), voice_bundle_user (core:445 + feature:717); via composition: voice_bundle_admin, chat_sessions (chat.py:338-340 + feature:674), knowledge_boards (knowledge.py:225-227 + core:373), knowledge_search_aggregator (knowledge.py:3091-3093 + core:391). Second copies are unreachable, with identical handlers (OpenAPI noise, not behaviour). The fix and the guard belong here.

  3. mrveiss commented on Oct 20, 2026

    @mrveiss
    OwnerAuthor

    Further sightings, verified on origin/main @ 5be354b (2026-10-20). They are recorded here because this issue owns the double-mount / duplicate-route class.

    • llc agent_hires is included twice into the same parent: autobot-backend/llc/api/__init__.py:64 and :90. This duplicates GET /api/llc/agent-hires, POST /api/llc/agent-hires and POST /api/llc/companies/{company_id}/agent-hires. It is not in the earlier sighting list.
    • The existing guard is blind to these, in two ways.
      • repo_tests/no_duplicate_route_registration_16908_test.py::collisions() (:106-119) collects module:var per (method, path) in a set. A router mounted twice under the same name collapses to one entry, so it misses chat_embed, admin_retention_policies, voice_bundle_user and agent_hires.
      • It cannot see include_router at all; this is pinned at :211.
        The class fix is a runtime check: build both apps, walk app.router.routes and flag a repeated (method, path). The routing walk autobot_shared/api_routing/route_order.py already exists, which makes this cheap.
    • Shadow-guard gap (bug(api): literal routes declared after a {param} route never run — the anonymous embed widget gets 401, plugin audit and SLM node conflicts 404 #18720 guard): route_order.py:37 _VERBS has no api_route, so @router.api_route routes are invisible to shadowed_literal_routes_18720_test.py. Example still live: SLM api/personality_proxy.py:79 /{path:path} (all 5 methods) is declared before :106 /. {path:path} matches the empty string, so personality_proxy_root never runs. Today this is harmless, since the auth check is the same and the catch-all proxies path="".
  4. mrveiss commented on Oct 21, 2026

    @mrveiss
    OwnerAuthor

    Merge train #19048 (merge f323772) landed the #19032 part of this. AC status from origin/main:

    • AC1 is not met as written. repo_tests/no_duplicate_route_registration_16908_test.py now enumerates through autobot_shared/api_routing/route_order.py, which follows nested include_router with its prefix, but it reads source with ast (module docstring: "read from source alone"). It does not read real router objects.
    • AC2 depends on AC1.
    • AC3 population collapse: test_the_reader_reached_both_apps (:103-107) asserts the parsed-file reach BACKEND_PARSED_FLOOR = 290 / SLM_PARSED_FLOOR = 42 (:51-52, measured at 364 / 53), with the route-count floors kept as a second check.
    • AC4 is partly met. COMPOSING_MODULES_PIN is gone from main (git grep finds no hits), but the guard is still AST-based, so the "AST version removed" half depends on AC1.
    • AC5 is unverified. I did not check whether f4e2d6badb was used or credited.

    Decision needed: is an AST resolver that follows nested include_router acceptable in place of real router objects (importing the backend pulls in the whole service stack)? If yes, AC1, AC2 and AC4 can be re-worded and ticked. If not, a runtime-objects guard is still owed.

  5. added
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Oct 21, 2026
  6. mrveiss commented on Oct 24, 2026

    @mrveiss
    OwnerAuthor

    Owner decision (2026-10-24): the guard is built on real router objects. Revive the f4e2d6badb guard: it uses the loaders app_factory calls, walks effective_routes(), and asserts the route population. A source-reading resolver is not an acceptable substitute.

    The guard runs on the local 3.14 suite venv as well as in CI. The double-mount fixes edit core_routers.py and feature_routers.py, which #19425, #19382 and #19396 also touch, so those fixes land after those PRs. The guard and its findings are built now.

  7. removed
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Oct 24, 2026
  8. added
    needs-ac-evidenceClosed by a merge keyword; awaits an AC evidence table comment (#19520)
    on Oct 25, 2026
  9. github-actions commented on Oct 25, 2026

    @github-actions
    Contributor

    Landed in train train-2026-10-25-85e3 (#19585, merge b07673947b) via #19457

  10. mrveiss commented on Oct 25, 2026

    @mrveiss
    OwnerAuthor

    AC evidence, verified against origin/main @ b07673947b (train 85e, #19585) (landed via #19457):

    • Real router objects with nested include_router prefixes: repo_tests/_dump_real_routes.py and autobot_shared/api_routing/router_routes.py:79 _hop_prefix (used at :148). Tests :215 and :224 in no_duplicate_route_registration_16908_test.py.
    • Verified by an actual run, in CI: all 12 python-suite shards succeeded on train 85e's run 40217777038, and repo_tests/ is in the suite's path list.
    • Population-collapse floor: FLOORS (:45), test_a_dump_below_the_floors_is_a_finding (:156).
    • AST version and COMPOSING_MODULES_PIN removed: git grep COMPOSING_MODULES_PIN origin/main returns 0 hits, and there is no import ast in the guard.
    • f4e2d6badb credited: _dump_real_routes.py:19 and the guard docstring :11.
  11. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    AC evidence, checked against main f88cd37. Run evidence is labelled; the rest is read from code.

    AC Evidence
    The guard enumerates routes from real router objects, resolving nested include_router() with its prefix MET. repo_tests/_dump_real_routes.py:59-63 imports load_core_routers and load_optional_routers and builds entries = [*load_core_routers(), *load_optional_routers()], then walks effective_routes(...) (:38-43; SLM app via main.app.router, :70-81). autobot_shared/api_routing/router_routes.py:152 effective_routes resolves nested prefixes. Guard: repo_tests/no_duplicate_route_registration_16908_test.py, including nested-prefix tests (/api/p/inner/inner/own/leaf).
    It is verified by an actual run, not by reading — on an interpreter at the platform floor, or in CI MET (CI-run evidence). The guard landed through the merge train whose run 40217777038 concluded success with all 12 python-suite shards and the aggregate success (checked with gh run view); the train's title lists "route guard". I did not confirm which shard ran this file.
    A population-collapse assertion fails the guard when the registry yields implausibly few registrations, so a broken import cannot pass as "no duplicates" MET. no_duplicate_route_registration_16908_test.py:43-44 records floors (backend 276 registry entries / 2567 routes; SLM 56 / 428), reach_shortfall (:140-152) flags registrations <= floor and routes <= floor, and test_a_dump_below_the_floors_is_a_finding (:156) proves it fires.
    The AST version and its COMPOSING_MODULES_PIN are removed in the same change, not left beside it — two guards for one property is what this repository calls a fork MET. git grep COMPOSING_MODULES_PIN origin/main returns no hits; the guard file's imports are collections, functools, json, subprocess, sys and others, with no ast; its docstring says it replaces the AST guard.
    f4e2d6badb's content is the starting point, credited, rather than a third independent implementation MET. Credited in the guard docstring (no_duplicate_route_registration_16908_test.py:11) and repo_tests/_dump_real_routes.py:19 ("Design from commit f4e2d6b (#16908)"). Whether code was copied from that commit is not checkable here; the credit is explicit.
  12. removed
    needs-ac-evidenceClosed by a merge keyword; awaits an AC evidence table comment (#19520)
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions