Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(performance): a cause a request, consumer or job role reaches is entry reachable (#4234)
Raghav Chamadiya48f9eaded016
diff --git a/docs/layers/PERFORMANCE.md b/docs/layers/PERFORMANCE.mdindex 5a380b2c9..1127206ec 100644--- a/docs/layers/PERFORMANCE.md+++ b/docs/layers/PERFORMANCE.md@@ -106,7 +106,8 @@ Each opportunity also says what runs its loop (`execution_role`: request, eventconsumer, scheduled job, startup, CLI, UI, tooling, test or unknown), and loops runper request rank above the rest. Roles are read for Python andTypeScript/JavaScript; other languages show `unknown`. The `role` filter lists any-one role, or `all`.+one role, or `all`. A request, event consumer or scheduled job role is walked from+its handler, consumer or job, so its `exposure` is `entry_reachable` too.Work a request hands to `asyncio.create_task` and never waits for is a backgroundjob, not part of the request, even when the task is kept in a map on shared appdiff --git a/packages/core/src/repowise/core/analysis/execution_roles.py b/packages/core/src/repowise/core/analysis/execution_roles.pyindex 8bb77bf21..5ba5118e5 100644--- a/packages/core/src/repowise/core/analysis/execution_roles.py+++ b/packages/core/src/repowise/core/analysis/execution_roles.py@@ -52,6 +52,11 @@ user's own machine (a browser, desktop or terminal UI)."""_HOT: tuple[ExecutionRole, ...] = ("request", "event_consumer", "scheduled_job")_SEEDED: tuple[ExecutionRole, ...] = (*_HOT, "startup", "cli")++ENTRY_ROLES = frozenset(_HOT)+"""Roles a hot walk spreads from a handler, consumer or job seed: a function+holding one counts as reached from an entry point, on the same evidence the+queue ranks the role on. Startup and CLI stay out: a cold role never leads."""_SEEDED_LANGUAGES = frozenset({"python", "typescript", "javascript"})_TS_JS = frozenset({"typescript", "javascript"})_CALLABLE_KINDS = frozenset({"function", "method"})@@ -494,6 +499,7 @@ def hottest_role(roles: Iterable[str | None]) -> ExecutionRole:__all__ = ["COLD_ROLES",+ "ENTRY_ROLES","EXECUTION_ROLES","LEADING_ROLES","ExecutionRole",diff --git a/packages/core/src/repowise/core/analysis/health/perf/opportunities.py b/packages/core/src/repowise/core/analysis/health/perf/opportunities.pyindex 4bbe4af57..3b576b0df 100644--- a/packages/core/src/repowise/core/analysis/health/perf/opportunities.py+++ b/packages/core/src/repowise/core/analysis/health/perf/opportunities.py@@ -20,7 +20,7 @@ from collections.abc import Mappingfrom dataclasses import dataclassfrom typing import Any-from ...execution_roles import hottest_role+from ...execution_roles import ENTRY_ROLES, hottest_rolefrom ..worth import dormantfrom .actionability import (ActionabilityState,@@ -200,7 +200,11 @@ def _read_live(members: list[Any]) -> _Reading:sites=sites,files={site[0] for site in sites},provenance=weakest_provenance({facts.provenance for facts in live}),- reachable=_reachability({facts.reliable_entry_reachability for facts in live}),+ # A hot role is an entry reaching the group, a handler a framework+ # registers included, which the entry-file walk does not see.+ reachable=True+ if role in ENTRY_ROLES+ else _reachability({facts.reliable_entry_reachability for facts in live}),role=role,sinks=tuple(sorted({facts.terminal_sink for facts in live if facts.terminal_sink})),magnitude=loop_magnitude(marker, [f.details for f in owners]),diff --git a/tests/unit/health/test_perf_opportunities.py b/tests/unit/health/test_perf_opportunities.pyindex 5b6499bd2..5878ec32c 100644--- a/tests/unit/health/test_perf_opportunities.py+++ b/tests/unit/health/test_perf_opportunities.py@@ -581,3 +581,30 @@ def test_a_loop_not_known_to_grow_never_leads(magnitude):details = {"loop_magnitude": magnitude} if magnitude else {}(opportunity,) = build_performance_opportunities([_finding("a.py", 1, **details)])assert opportunity.may_lead is False+++ ("role", "walked", "exposure"),+ [+ ("request", None, "entry_reachable"),+ ("scheduled_job", False, "entry_reachable"),+ ("unknown", None, "unknown"),+ ("unknown", False, "not_entry_reachable"),+ # A cold role is its own seed and never spreads: no claim beyond the walk.+ ("cli", None, "unknown"),+ ],+)+def test_a_seeded_role_is_an_entry_reaching_the_cause(role, walked, exposure):+ """The role and the exposure facet state one fact, so the text agrees with both."""+ row = _finding(+ "app/views.py",+ 12,+ marker="hot_path_sync_io",+ boundary="filesystem",+ execution_role=role,+ reliable_entry_reachability=walked,+ )+ (opportunity,) = build_performance_opportunities([row])+ assert opportunity.facets["execution_role"] == role+ assert opportunity.facets["exposure"] == exposure+ assert opportunity.reliable_entry_reachability is (True if exposure == "entry_reachable" else walked)