Repository navigation
Description
Problem
A Codebase Analytics result can come from a different source than the one being viewed, and nothing says so. The maintainer saw a job for another source while looking at AutoBot's analysis (#20491). repo_tests/source_scoping_guard_17758_test.py guards one shape of this class, X if source_id else <unscoped>, and #17761 tracks its seven frozen sites. The shapes below pass that guard. The class has been closed four times and returned (#17761 lists them), so this needs a rule that holds at the route, not another sweep.
Evidence
Read from the code on main at f88cd37, not run.
| Shape | Where | What happens |
|---|---|---|
| Silent default to the most recent source | default_source_id() callers: endpoints/stats.py:612, report.py:2229, dependencies.py:489, import_tree.py:264; and use_default in endpoints/shared.py:137-142 |
A request with no source gets another source's results, with nothing in the response saying which |
| No source at all | /index/current (endpoints/indexing.py:319) |
One global job. PR #20501 adds its source and has the page ignore another source's job; the route itself still takes none |
| Global result key | bug_pred_task:latest_task_id (api/analytics_bug_prediction.py), debt:latest (api/analytics_debt.py), /api/quality/health-score |
Cached under no source |
| Results not limited to the analysed root | #20224 (PR #20410 labels this rather than limiting it) | The response reads as if it covered one root |
| Index keyed by relative path | #20402 | Files from different roots can overwrite each other |
Size not established. Lines declaring source_id as optional under endpoints/*.py, matched by source_id: str | None or Optional[str]: 75. That count includes helpers and is not a count of routes. Paths outside endpoints/, other spellings and the per-route verdicts have not been measured.
Fix
- A route that returns per-source results requires a source through
SourceIdQueryand refuses a request without one. No default to the most recent source. - A result that is really across sources says so in its response, by a named property the guard can read.
- Responses state the source they came from.
- The frontend sends the source on every such call. A caller that sends none today gets a 422 after this, so each caller is checked first.
Acceptance criteria
- Every route under
api/codebase_analytics/endpoints/that returns per-source results requires a source, or carries a named cross-source declaration. The list of routes and each verdict is posted here. -
default_source_idanduse_defaulthave no caller serving an HTTP request, or each remaining one states why. - The global keys in the table are keyed by source, or declared cross-source.
- A guard fails on a new route with an optional or missing source. It reads the registered routes, states how many it examined, fails if that count falls below its floor, and has a control route it must flag and one it must pass.
- Any baseline freezing today's sites is content-keyed, can only shrink and has its count re-derived by a second method, per
RATCHET_BASELINES.md. - A request for source A never returns source B's stored result (test with two sources).
Related
Class witnesses, each keeping its own issue: #17761 (fallback sites), #20224, #20402, #20491, #17758.
Activity
github-actions commentedon Nov 1, 2026
needs-structurecleared: goal milestone, matching phase label and native parent (or sub-issues) are all present (#19522).mrveiss commentedon Nov 2, 2026
Route inventory against
mainat 87eae8a, read from the code and not run. The per-route verdict list this issue's first AC asks for still has to be posted; these are the class counts.86 route registrations, 83 unique paths. Decorators alone count 81, so a guard that greps
@router.would miss routes registered throughadd_clear_stuck_route. A guard should read the registered routes, as the AC says."default"tagpath, defaulting to the project rootWrong-source results even when a source is named:
_get_last_indexed(endpoints/sources.py:475-481) falls back to the globalcodebase_statsdocument when a source has no stats of its own, so that source reports another's last-indexed time. Confirmed by reading it./hardcodesfallback (endpoints/stats.py) readscodebase:hardcodes:*with no source. The helper takes no source; the call path still needs confirming.Other things this adds to the issue's table:
"default"or""), which doesn't change when the most recent source does. A later request can get a result computed for an earlier default. Read from the code, not run.pattern_task:latest_task_idandpatsummary_task:latest_task_idare further global keys.debt:latestand/api/quality/health-scoreweren't checked.resolve_scan_rootfalls through to AutoBot's own tree when no source can be resolved.Requiring a source will break callers unless they change first.
withSourceIdandsourceIdQuerysend nothing when no source is selected, so those callers would get a 422.usePatternAnalysis.ts,useImpactAnalysis.tsand the debug health check inuseAnalyticsDebug.tsnever send one. Non-frontend clients weren't searched.Not established: whether a task id's result belongs to the caller's source, whether the code graph collection behind
/impactholds one source or several, and what/report's sub-analyses key on.mrveiss commentedon Nov 2, 2026
Correction to my inventory comment: the in-memory
/hardcodesfallback is not a wrong-source read today.endpoints/shared.py:36_in_memory_storage = {}is never written, so it's always empty, andstats.py:363never takes that branch. With no Redis,/hardcodesanswersno_data, which is honest.It's still unfinished:
_fetch_hardcodes_from_memoryignores the source and callsscan_iteron what is a plain dict, so it would both fail and be unscoped if anything filled that store.storage.py:100InMemoryStorageexists and isn't wired to it. Left in place and recorded here, since it isn't reachable._get_last_indexedis the confirmed wrong-source read; its fix is in #20612.mrveiss commentedon Nov 2, 2026
#20612 landed in #20692 (58cbf98):
_get_last_indexedand_get_problems_from_chromadbno longer fall back to the global stats document. Still open: require a source on routes, per-route verdicts, a guard that reads registered routes, the frontend 422 check, and the global keys.fix(analytics): a named source never reads the global stats document (m…
mrveiss commentedon Nov 7, 2026
Witness from the review of #20491 (checked against origin/main, 2026-11-07). This is the route-level shape this issue's first AC covers.
Route:
autobot-backend/api/codebase_analytics/endpoints/pattern_analysis.py:539-542,GET /patterns/cached-summary, withsource_id: str | None = Query(default=None).Silent default: when
source_idis absent,_build_chromadb_where_filter(pattern_analysis.py:634) substitutes the sentinelsource_id or "default". The summary is therefore read from the"default"partition, not from the selected source and not from all sources, and the response does not say so.Frontend caller:
autobot-frontend/src/composables/usePatternAnalysis.ts:494calls/api/analytics/codebase/patterns/cached-summarywith no params. It does not usescopeToSourceorwithSourceId(composables/analytics/useAnalyticsDataFetchers.ts:153,CodebaseAnalytics.vue:556).Fix in this issue's scope:
source_id(or declares a cross-source result), per the first AC.source_idthrough the canonicalscopeToSource/withSourceIdpattern.source_idfor the selected source.mrveiss commentedon Nov 7, 2026
Decisions for the first PR of this issue (#21008), recorded before it merges.
1. Task routes are exempt. Routes addressed by
{task_id}(status, result, cancel,*/tasks/clear-stuck,clear-all) do not take a source: the id was minted for one source's run and the caller cannot usefully re-assert it. The route guard classifies them by the{task_id}path marker and by a named ops list (POST /sources,POST /embedding-stats/reset,POST /patterns/tasks/clear-all, theclear-stucksuffix).2.
POST /indexrequires exactly one ofsource_id/root_path. The devroot_pathmode stays. A body naming neither (which used to index AutoBot's own project root) or both is a 422. The frontend indexing trigger now sendssource_idalone when a source is selected.3.
pathon the/patterns/*routes is relative to the source root. It is optional (no path scans the whole source), resolved withresolve_scan_root(strict=True)and validated withvalidate_relative_pathso it cannot leave the source. The previous default was AutoBot's own project root.4.
/impactis cross-source, and says so. Evidence, read from the code:CodeIndexer(services/knowledge/code_indexer.py) writes node metadata{source, record_type, node_kind, node_name, source_path, line, parent, origin}and edge metadata{source, record_type, kind, source_id, target_id, ...}; thesource_idon an edge is the CALLER NODE's id, not a registry source. The only writer,POST /api/knowledge_base/index/code, takes a directory, not a source. So no where-filter by code source is possible, and node ids are path-based, so the same id in two sources is one node. The route carriesx-source-scope: cross-sourcein its OpenAPI metadata and every response carriessource_scope: "cross-source". Scoping it needs the graph writer to tag nodes with a source first (follow-up below).Visible API change: the source-bound analytics routes now answer 422 without a well-formed
source_id. The full list and the guard output are in the PR body.Scope of the next PR (PR 2), after the page-open PR that touches the same files lands:
/index/currentand/index/cancelscoping, deletingjobBelongsToSource, and the edits toanalytics_page_open_reads_only_20491_test.py.Follow-ups, not in either PR:
/api/qualityhealth-score and metrics routes.bug_pred_task:anddebt:latest.analytics_cache_population.py) dispatches with no source./impact.resolve_scan_rootstill falls back to AutoBot's own tree when a NAMED source does not resolve on the non-strict routes.source_storage.get_default_source_idhas no production caller after this PR."default".42 remaining items
fix(frontend): keep waiting for a request queued behind another sourc…
fix(frontend): drop the old source's job and polling on a source swit…
mrveiss commentedon Nov 22, 2026
Instance inventory, re-verified on origin/main (2026-11-22)
Rule applied: where an analyzer's own code lives is legitimate; what tree it scans must be the selected source's clone. Paths are under
autobot-backend/api/unless noted.A. Scan root is not the selected source (live defects)
analytics_bug_prediction.py:824,904,947,1113,1276(/analyzeGET+POST,/high-risk,/heatmap,/summary)path=Query("."): the server's working directory (the install tree). Nosource_idanywhere in the module. This is #18030, still live.analytics_bug_prediction.py:59,69,910pathonly;bug_pred_task:latest_task_idis global./cachedignores the source (frontenduseBugPrediction.ts:67sends none).codebase_analytics/endpoints/report.py:1603-1607PATH.BACKEND_DIR(install backend) whenever the source root equals the install's git root.report.py:1662parents[4]whenproject_rootis falsy.report.py:1785PATH.PROJECT_ROOT.duplicate_detector.py:476DuplicateCodeDetector()with no root scansparents[3](install backend).api_endpoint_scanner.py:203,970,1402APIEndpointChecker, endpoint scanners and the checker fall back toresolve_git_repo_root(), which probes<base>/code_sourcethenparents[4].endpoints/shared.py:297-345get_project_root()(parents[4], no live caller found) andresolve_git_repo_root()(walk-up for.git, then<base>/code_source, then parents[4]). Root cause of 3, 7, 9, 10, 11.endpoints/shared.py:377filter_problems_by_file_existence(root_path=None)resolves problems againstresolve_git_repo_root().tasks/analytics_cache_population.py:164resolve_git_repo_root()as the project root to the modules that take a path; only some modules also get the per-source list.codebase_analytics/scanner.py:275scan_codebase(root_path=None)scansPATH.PROJECT_ROOT.endpoints/indexing.py:184root_pathindexesPATH.PROJECT_ROOT.schemas_analytics.py:1068CodeAnalysisRequest.target_pathdefaults toPATH.PROJECT_ROOT.analytics_architecture.py:368-372base_pathdefaults toconfig.base_dir.analytics_debt.py:412,432,443debt:latest, global;target_pathechoed from the request.B.
source_idoptional, so an unsourced call is not a 4xx (the #20513 shape)analytics_quality.py:132,203,701,1033,1091,1163,1227,1355,1400,1515analytics_code_review.py:426,496,614,682,757analytics_evolution.py:328,398,552,816analytics_code_generation.py:936analytics_reporting.py:78codebase_analytics/endpoints/charts.py:37,163,238codebase_analytics/endpoints/cross_language_patterns.py:49codebase_analytics/endpoints/report.py:1300,1393,1526,1752,2125C. Legitimate, not scan roots (allowlist):
environment.py:235-244(puts the backend onsys.pathand loadsenv_analyzer.py),ownership.py:49-54(loadsownership_analyzer.py),analytics_controller.py:76-77(tool locations).default_source_id/use_defaultcallers listed in the issue body no longer exist on main (grep: 0).D. Frontend:
composables/analytics/useBugPrediction.ts:67calls/api/analytics/bug-prediction/cachedwith nosource_id; the other analytics composables need the same audit.#18030 is the same defect as rows 1-2 and is fully fixed only when the bug-prediction routes require
source_id.mrveiss commentedon Nov 22, 2026
Owner decision on row 15 (technical debt): debt moves under the codebase page (
codebase/:id) as a tab of the selected codebase, withsource_idrequired on every debt route and results kept per codebase. It lands in PR 3 with the other optional-source_idroutes. PR 2 (#22085) leaves/api/debt/*unchanged.fix(analytics): bug prediction skips symlinks leaving the checkout; i…
mrveiss commentedon Nov 22, 2026
Added to the instance list:
autobot-backend/api/code_intelligence.pyPOST /evolution/analyze(line 1685 on main) takes a caller-typedpathquery (Query(...), validated only for existence) and mines that repository, so it scans a path rather than the selected source's checkout. It moves to a requiredsource_idand the source's checkout; it rides with the evolution PR (#22089) because no open PR touches that file.fix(analytics): quality routes and socket require source_id and keep …
fix(analytics): evolution review fixes, code-intelligence evolution r…
test(analytics): evolution scope test without a hand-rolled pipeline …
mrveiss commentedon Nov 22, 2026
Instances left out of the PRs so far, each with its plan (read from code, not run)
autobot-backend/api/code_intelligence.pypath-typed scans:POST /analyzeandGET /health-score;POST /redis/analyzeandGET /redis/health-score;POST /security/analyze,GET /security/report;POST /performance/analyze,GET /performance/score,GET /performance/report;POST /security/score/analyze(path/request.path, checked only for existence)source_idrequired, scan root fromresolve_scan_root(an optional sub-path goes throughscan_path_in_source), result keys per source.GET /security/scoreand/security/score/cachedalready take a source (#21463). The evolution routes of this file are fixed in #22089.autobot-backend/api/analytics_quality.pyGET /remediation-deltasremediation:delta:history, written bycode_analysis/src/remediation_loop.pywith no source on the recordautobot-backend/api/analytics_quality.pyruntime_riskdrill-down and theruntime_riskmetric (code_analysis/src/runtime_risk.py:44,build_runtime_risk_map)fix(analytics): quality socket works with the source dependency; runt…
mrveiss commentedon Nov 22, 2026
For PR 1 (resolver), checked on main:
resolve_source_rootreturnsPath(source.clone_path)unresolved andresolve_scan_rootaccepts it whenis_dir()is true, which follows symlinks. Aclone_paththat is itself a link (or sits under one) is therefore scanned wherever it points, while containment checks elsewhere (confirm_scan_dir_in_source, the quality and evolution filters) compare againstroot.resolve(), so the two can disagree about what the root is. PR 1 should return the resolved path fromresolve_scan_rootso every scanner and every containment check use one real root. Not verified: whether source registration restrictsclone_pathfor local sources (if it accepts any path, the link case is no wider than registering that path directly). The pattern analyzer's missing cooperative cancel token is #22094 (sub-issue of this one).fix(analytics): report scanners require their root and source; contra…