Repository navigation
fix(guards): the unconnected-code gate follows include_router through package routers; one-time re-measure (#21428) - #21470
Conversation
… package routers (#21428) A registry entry that names a package mounts a router which is not built in its __init__: __init__ re-exports it from routes.py, which re-exports it from router.py, which include_router()s the endpoint modules. The shared resolver reads only __init__ and only the `from .x import router as alias` shape, so those endpoint modules got no mount prefix and the gate judged them by loose forms (/analytics/charts instead of /analytics/codebase/analytics/charts). _unconnected_mounts.package_mounts follows the re-exports to the file that builds the router and walks its include_router calls, composing registry prefix, each router's own prefix and each include prefix, with a cycle guard. It is kept in the gate because the shared resolver feeds the api-wiring audit, the endpoint inventory and oracles that pin its exact output. Tests plant the package shape and cover: full-path caller connects, no caller still fires, an unmounted-form or /api/<name> literal no longer connects, own + include prefix, two-level nesting, both cycles, and the codebase_analytics shape. The baseline is re-measured in the next commit of this change; with this commit alone the gate is red, and only the tip of the change is judged.
…he baseline, twelve unmasked routes are frozen with their issues (#21428) With the mount prefix of package-router routes resolved, 39 codebase-analytics baseline lines have a frontend caller of their full path and leave the baseline. Twelve routes read as unconnected that never were connected: they passed only because an unrelated /api/{p} literal matched their unmounted form. Eleven are codebase-analytics routes (#21459), one is the Company OS package's GET /health (#21460). They are recorded once, in the dated frozen list unconnected_code_remeasure_21428.txt, and appended to the baseline; no route code is deleted. The gate test now takes a tuple of frozen lists: a baseline addition is allowed only if some list names it, every list may only shrink against its base, and every list's keys must still be in the baseline. Controls: an addition named in no list is refused, and a list that gained a line against its base is refused.
…d a real-tree control, correct the re-measure record (#21428) Cites #21467 for the shared-resolver convergence, states that only package registry entries are resolved here, and lists the shapes the walk cannot see. A real-tree test pins the codebase-analytics, redis-mcp and Company OS package mounts. The #20910 frozen list's header no longer claims to be the only allowed baseline addition. Correction to the previous commit's message: of the 39 baseline lines that leave, 37 have a frontend caller of their path; GET /cross-language/patterns and POST /cross-language/clear-cache read as connected only through the gate's loose wildcard rule (the wildcard literal at useCrossLanguageAnalysis.ts:87), noted in #21467. The three sources/{source_id} routes do have real callers.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Verdict: APPROVE @ cb65862 Scope of this verdict: the whole PR at head cb65862. The first two commits (e0b7f46 helper + tests; c97e6d5 baseline re-measure + frozen list + generalised gate test) were approved by an earlier independent review whose computed results are restated here, not recomputed: instrument check reproduces the baseline's 1378 route keys exactly with the old resolution and gives 1351 with the fix; the 39 removed and 12 added sets match; an AST resolver agrees with the helper on all 69 mount entries; the new tests were replayed by text; no guard predicted red. The third commit cb65862 is covered by this delta review. Findings
No blocking finding. Delta checks (cb65862)
Real-tree test, derivation (
|
| Assertion | Derivation at this head | Holds |
|---|---|---|
"/analytics/codebase" in autobot-backend/api/codebase_analytics/endpoints/charts.py |
Registry entry ("api.codebase_analytics", "/analytics/codebase", ...). __init__.py -> from .routes import router -> routes.py -> from .router import router -> router.py, which builds router = APIRouter(tags=..., dependencies=...) (no prefix) and has router.include_router(charts.router) (no prefix); charts is bound by the parenthesised from .endpoints import (... charts ...) to endpoints/charts.py, which builds router = APIRouter(). Mount = /analytics/codebase + "" + "". |
yes |
"/redis" in autobot-backend/api/redis_mcp/router.py |
Variable-form entry (redis_mcp_router, "/redis", [...]) resolved by the from api.redis_mcp import router as redis_mcp_router alias to api.redis_mcp. __init__.py has from api.redis_mcp.router import router; the absolute import binds to router.py (its own router = APIRouter(tags=...), line start). The helper records the registry prefix for the home file. |
yes |
"" in autobot-backend/llc/api/__init__.py |
Entry ("llc.api", "", [...]): the registry prefix of llc.api is empty (the entry regex allows an empty prefix). The router is built in __init__.py itself (router = APIRouter(prefix="/llc", ...)), so it is its own home. The helper records the registry prefix WITHOUT the router's own /llc (the stated contract: callers add the file's own prefix), so the list contains "". |
yes |
No assertion is predicted to fail.
Whole-PR state at the head
- Changed files: 7 (matches
gh): the two helper modules, the two test modules, the baseline, the two frozen lists. Branch is 0 behind main (rev-list0/3); mergeable. - No
*_test.pyfile added (the two added files are_unconnected_mounts.pyand a.txt); main has norepo_tests/*_test.pychange since 8781966, so the guard-reach window (MIN_GUARDS_EXAMINED = 380) is unchanged. - Baseline: 1351 route keys. All 12 keys of
unconnected_code_remeasure_21428.txtare present in the baseline; tags wire(analytics): eleven codebase-analytics routes are served but nothing calls them #21459 x11, decide(company-os): GET /api/llc/health has no caller in the tree — declare its external caller or wire it #21460 x1. - Python files:
_unconnected_mounts.py171 lines, longest function 18;_unconnected_routes.py277 / 23;unconnected_clients_20512_test.py271 / 22;unconnected_code_gate_20512_test.py482 / 13. All < 600 lines, all functions <= 30. - Commits: three, subjects in
<type>(scope): ... (#21428)form, no trailers. - PR body has Thinking Path / What Changed / Verification / Model Used and
Closes #21428. Milestone M4 and labelphase:M4.11present. Unresolved review threads: 0.
Closes #21428 justified?
- Gate resolves package-included routes, with a nested-include test and a control without a caller: delivered (
package_mounts; the synthetic codebase-analytics-shape, own+include prefix, two-level and cycle tests with an uncalled control route; plus the real-tree control). - Cause stated with file:line: delivered by file and symbol in the issue and the helper docstring (see finding 3); the
.py-suffix guess is refuted there. - The 55 lines re-measured: delivered (39 leave, 16 stay; 12 newly unmasked routes frozen with issues wire(analytics): eleven codebase-analytics routes are served but nothing calls them #21459/decide(company-os): GET /api/llc/health has no caller in the tree — declare its external caller or wire it #21460 per the owner decision).
- A route in that package with a real caller passes without a baseline entry: delivered (the 39 leave; the synthetic caller test pins it).
Verified / Not verified
Verified (by reading text from git refs, with stdlib-only text checks): everything listed above, including the AST equality, key-set equality, baseline counts and tags, file sizes and function lengths, the three expected mount values, thread count, and PR metadata.
Not verified: any execution. Nothing from the repository was executed (no tests, no gate, no repo imports); the results above come from text re-implementations and reading. The PR's CI has not run on this head. The first two commits' computed results are restated from the earlier independent review, not recomputed here. The module, queue and table kinds of the gate were not recomputed (not touched by this change).
An approval is not a merge go-ahead: merging follows the repository's merge-queue rules.
Follow-ups: #21467 (shared resolver convergence, module-entry includes, method/wildcard looseness), #21468 (python filter does not cover the baseline data files), #21459 (eleven codebase-analytics routes without a caller), #21460 (Company OS package GET /health).
Thinking Path
The unconnected-code gate (#20512) decides whether a backend route has a caller by matching caller literals against the route's full path: mount prefix + router prefix + route path. For routers mounted through a package it lost the mount prefix. The registry names the package
api.codebase_analytics(prefix/analytics/codebase); the shared resolver's package branch reads only the package's__init__.pyand only thefrom .x import router as alias+include_routershape, while the real chain is__init__.py→routes.py→router.py, which includes twenty endpoint modules imported asfrom .endpoints import charts, …. Every route inapi/codebase_analytics/endpoints/*.pywas therefore judged by its unmounted path. The same shape affectsapi.redis_mcpand the routes defined in the home file of thellc.apipackage router.Two consequences, both wrong in opposite directions: routes with real callers of their full path were baselined as unconnected (so a new, properly called route in that package could not pass the gate at all — the baseline only shrinks), and routes with no caller passed because an unrelated
/api/{p}literal matched their unmounted single-segment path.The fix is gate-local (
repo_tests/_unconnected_mounts.py), reusing the shared resolver's grammar and adding only the walk through package router chains. It is deliberately not placed in the shared resolver here: that would change the output of the API-wiring audit, the endpoint inventory, the SDK path oracles and a convergence test that pins the Company OS prefixes, none of which can be re-measured without running them. Converging on one implementation is tracked in #21467.What Changed
repo_tests/_unconnected_mounts.py(new) —package_mounts: for registry entries that name a package, followsfrom .x import routerre-exports to the file that builds the router, walks itsinclude_routercalls (names resolved through relative and absolute imports, includingmodule.router), and composes mount +APIRouter(prefix=)+include_router(prefix=), with a cycle guard. Its docstring states the scope (package entries only) and what it cannot see.repo_tests/_unconnected_routes.py—Audit.registry_prefixesmerges those mounts.repo_tests/unconnected_code_baseline.txt— the one-time re-measure decided by the owner on 2026-11-13 (recorded on bug(guards): the unconnected-code gate does not resolve the mount prefix of the codebase analytics endpoints package, so called routes read as unconnected #21428):GET /cross-language/patternsandPOST /cross-language/clear-cachematch only a wildcard call (/cross-language/${endpointPath}) — the gate's existing loose rule (path parameters are wildcards, HTTP method ignored), unchanged here and recorded in bug(api-routing): the shared router-prefix resolver cannot follow package router chains or 'from api import x' includes — its consumers are still wrong #21467.GET /health(tagged decide(company-os): GET /api/llc/health has no caller in the tree — declare its external caller or wire it #21460).repo_tests/unconnected_code_remeasure_21428.txt(new) — the frozen list of exactly those twelve keys. It may only shrink.repo_tests/unconnected_code_gate_20512_test.py— the frozen re-measure is generalised from one file to a tuple of files: an addition to the baseline is allowed only if some frozen list names it; each list may never gain a line against its base; each frozen key must still be in the baseline. Two control tests: an addition named in no list is refused; a list that grew is refused. No existing assertion is weakened.repo_tests/unconnected_code_remeasure_20910.txt— header comment reworded (it claimed to hold the only additions ever allowed); keys untouched.repo_tests/unconnected_clients_20512_test.py— tests for the walk on synthetic trees (the codebase-analytics shape, own prefix + include prefix, two-level nesting, re-export and include cycles) with negative controls, and a real-tree control for the three affected packages.No route code is deleted. No pinned floor is changed.
History note: the branch has three commits; the first alone leaves the gate red (the baseline is re-measured in the second), and the second's message says each of the 39 lines has a caller of its full path, which the third commit's message and this description correct. Only the tip is judged by CI.
Verification
Nothing was executed locally (CI is the gate); this run is the first execution of the new tests.
package_mountson all 69 mount entries of the three affected packages.Not verified: any CI result; the module, queue and table kinds of the gate were not recomputed (the change does not touch them).
Follow-ups: #21467 (shared resolver; module-entry includes — 14 more baseline lines and two routes would move; method/wildcard looseness), #21468 (the python filter does not cover the baseline data files), #21459, #21460.
Closes #21428
Model Used
Claude Sonnet (implementation and review), Claude Fable (planning).