Skip to content

fix(guards): the unconnected-code gate follows include_router through package routers; one-time re-measure (#21428) - #21470

Merged
mrveiss merged 5 commits into
mainfrom
issue-21428-gate-package-routers
Nov 13, 2026
Merged

mrveiss merged 5 commits into
mainfrom
issue-21428-gate-package-routers

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 13, 2026

Copy link
Copy Markdown
Owner

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__.py and only the from .x import router as alias + include_router shape, while the real chain is __init__.py → routes.py → router.py, which includes twenty endpoint modules imported as from .endpoints import charts, …. Every route in api/codebase_analytics/endpoints/*.py was therefore judged by its unmounted path. The same shape affects api.redis_mcp and the routes defined in the home file of the llc.api package 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, follows from .x import router re-exports to the file that builds the router, walks its include_router calls (names resolved through relative and absolute imports, including module.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_prefixes merges 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):
  • 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.

  • Instrument check: two separately written text re-implementations of the gate's route verdict each reproduce the current baseline exactly with the old resolution — 1378 unconnected route keys, zero differences — and give 1351 with the fix: the same 39 removals, the same twelve additions, no other change of verdict (2917 route sites).
  • An independent AST resolver agrees with package_mounts on all 69 mount entries of the three affected packages.
  • Each new positive test was traced to fail on the old resolution and pass on the new; the negative controls fail if the walk drops a prefix level.
  • Guards read or computed: files with route decorators 442 before and after (floor 421); guard-reach window 331 < 380 ≤ 381 (no test file added); uncovered python-filter reads 27 = 27; file sizes and function lengths within limits; no open PR touches these six files.

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).

… 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.
@mrveiss mrveiss added bug Something isn't working phase:M4.11 Safety net: tests and analysers reach the whole tree labels Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0f14a1b and e73568a.

Files ignored due to path filters: 1

  • repo_tests/unconnected_code_baseline.txt is excluded by !**/*_baseline.txt
Files selected for processing: 6

  • repo_tests/_unconnected_mounts.py
  • repo_tests/_unconnected_routes.py
  • repo_tests/unconnected_clients_20512_test.py
  • repo_tests/unconnected_code_gate_20512_test.py
  • repo_tests/unconnected_code_remeasure_20910.txt
  • repo_tests/unconnected_code_remeasure_21428.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

Copy link
Copy Markdown
Contributor

Notice: 28 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

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

# Severity Where Finding
1 none repo_tests/_unconnected_mounts.py cb65862 changes it only inside the module docstring: ast.dump of the file before (c97e6d5) and after, docstrings stripped, is identical.
2 nit (non-blocking) docstring limitation (c), include_router(router=x.router) Stated as "the router it names is not seen". True for the shared prefix grammar (_INCLUDE_ROUTER_TARGET_RE excludes name=), but the helper's own INCLUDE_ROUTER_NAME_RE (include_router\(\s*(\w+)) captures the keyword name router, so if the including file also binds a name router, the walk follows that instead of the intended child. The limitation is real; the wording is slightly under-stated. No effect on the live tree (no such include in the three packages).
3 nit (non-blocking) AC 2 The cause is stated by file and symbol (registry entry, package_router_files, the __init__ -> routes.py -> router.py chain), not by line number. Acceptable; the docstring carries the full chain.

No blocking finding.

Delta checks (cb65862)

  • Files: exactly three (repo_tests/_unconnected_mounts.py +19/-1, repo_tests/unconnected_clients_20512_test.py +9, repo_tests/unconnected_code_remeasure_20910.txt +2/-2).
  • Docstring claims against the code:
    • Scope = package registry entries only: true (package_mounts skips an entry when <module>.py exists or there is no __init__.py).
    • (a) hub whose router is not named router or not built by router = APIRouter( at line start yields no mounts: true (_ROUTER_DEF_RE is ^router\s*(:...)?=\s*APIRouter\( with MULTILINE; _router_home then follows only the binding named router).
    • (b) backslash-continued from ... import loses later names: true (_FROM_IMPORT_RE takes [^\n]+ or a parenthesised group).
    • (c) keyword include form: true with the nit in finding 2.
    • (d) includes under if/try/functions count as unconditional: true (plain text scan, no scope tracking).
    • (e) include_router( in a comment or docstring counts: true (INCLUDE_ROUTER_NAME_RE runs on the raw source; only the import scan strips comments, so the include counts when its name is bound).
    • (f) from .sub import router binds sub/router.py before sub/__init__.py: true (_source_file order: sub/router.py, sub/router/__init__.py, sub.py, sub/__init__.py).
    • mount_graph.py sentence: true. _collect_imports skips node.module is None (so from . import x) and binds only alias names containing "router" (so from .endpoints import charts is never bound).
  • Header of repo_tests/unconnected_code_remeasure_20910.txt: keys before and after are identical (586 = 586, same order). The gate compares keys through code_lines, which with the default markers drops lines starting with #, so a reworded comment is not growth (_remeasure_keys, _frozen_additions, _frozen_keys in repo_tests/unconnected_code_gate_20512_test.py).

Real-tree test, derivation (test_the_real_package_router_mounts_are_seen_21428)

Call form matches the sibling test_the_real_nested_mount_of_a_registry_router_is_seen_20910: Audit(root, ...).registry_prefixes("autobot-backend") returns {repo-relative path including the autobot-backend/ prefix: list[str]}; in on a list is correct.

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-list 0/3); mergeable.
  • No *_test.py file added (the two added files are _unconnected_mounts.py and a .txt); main has no repo_tests/*_test.py change 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.txt are 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.py 171 lines, longest function 18; _unconnected_routes.py 277 / 23; unconnected_clients_20512_test.py 271 / 22; unconnected_code_gate_20512_test.py 482 / 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 label phase:M4.11 present. Unresolved review threads: 0.

Closes #21428 justified?

  1. 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).
  2. 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.
  3. 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).
  4. 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).

mrveiss added a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working phase:M4.11 Safety net: tests and analysers reach the whole tree

Projects

None yet

1 participant