Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(performance): one opportunity per place you change, ranked by value (#2817)

Raghav Chamadiya44061e8a5ad2
diff --git a/docs/agent/MCP_TOOLS.md b/docs/agent/MCP_TOOLS.md
index 0b685252c..a87cb9478 100644
--- a/docs/agent/MCP_TOOLS.md
+++ b/docs/agent/MCP_TOOLS.md
@@ -1009,8 +1009,10 @@ CLAUDE.md render the same object. The block carries `lead` (equal to
`items[0]`), up to five `items` in a compact projection (`id`, `tier`, `kind`,
`title`, `target`, `why`, `gain`, `effort`, `confidence`, `next_call`),
`totals` (`candidates`, `eligible`, `shown`, and `excluded` counted by reason:
-`test`, `tooling`, `generated`, `expected`, `no_plan`, `below_min_worth`,
-`history_only`), `by_improves`, `model_version`, `basis`, and `detail_call`,
+`test`, `tooling`, `unknown`, `generated`, `expected`, `no_strategy`, `no_plan`,
+`below_min_worth`, `history_only`; a performance cause enters only from the
+performance default queue, whose reasons `unknown`, `expected` and `no_strategy`
+are), `by_improves`, `model_version`, `basis`, and `detail_call`,
the `get_health(fix_id=...)` call that returns the lead in full. `tier` is
`now` (worth doing, and the plan is safe to start), `next` (worth doing, needs
judgment) or `later`. Items are ordered by value first, the larger of the recoverable health and the size of the problem (CCN, lines and nesting past their bars, a critical or brain-method finding, a hot file), then by tier, so a function far past every bar leads as "Break up ..." ahead of tidy work that is safer to start. `kind` is `refactor` (one file's composed refactoring),
diff --git a/docs/layers/CODE_HEALTH.md b/docs/layers/CODE_HEALTH.md
index 4be4fb16d..76a12fec2 100644
--- a/docs/layers/CODE_HEALTH.md
+++ b/docs/layers/CODE_HEALTH.md
@@ -574,15 +574,19 @@ code, in the same function or one same-file helper. It is the one shape here
that is not a loop around I/O: the query runs once and returns too much, and
the fix is to select one row per key in the database.
-**ORM lazy loads.** `lazy_load_in_loop` (Python, advisory, weight 0.4) flags a
-lazy relationship read on each iteration of a loop over model rows, the N+1 an
-attribute access hides. The loop's rows must resolve to one SQLAlchemy or
+**ORM lazy loads.** `lazy_load_in_loop` (Python: sync SQLAlchemy and Django)
+flags a lazy relationship read on each iteration of a loop over model rows, the
+N+1 an attribute access hides. The loop's rows must resolve to one SQLAlchemy or
Django model through the cross-file model index, and the attribute must be a
lazy relation the producing query does not already eager-load. Async functions
are skipped, so SQLAlchemy coverage is sync only. Its plan is
-`eager_load_relationship`, advisory. Measured at 81% precision on held-out
-Django (47 of 58), it ranks in the queue but never leads the performance
-directive.
+`eager_load_relationship`, advisory, and names the eager load that replaces it
+(`selectinload(...)`, `select_related(...)`). Each finding records its ORM in
+`details.orm`, and the weight and the right to lead are read per finding:
+Django measured 29/32 = 90.6% on a fresh held-out sample and carries weight 0.7
+and may lead; SQLAlchemy has fewer than 30 held-out labels and stays at the
+advisory 0.4 and never leads. One marker, one opportunity id: the ORM is a fact
+on the finding, not a second marker.
Methodology and raw data:
[perf-detection](https://github.com/repowise-dev/repowise-bench/tree/master/perf-detection).
@@ -592,10 +596,33 @@ Methodology and raw data:
The web Code Health page has a dedicated **Performance** tab. It leads with a
bounded list of causal opportunities rather than a flat wall of observations:
the boundary and execution context, shared intervention, affected call-site and
-file totals, confidence, and resolution provenance. Production/tooling and test
-contexts are separate views. Expanding an opportunity shows caller-to-sink
-paths; raw findings remain canonical and load as a separately paged evidence
-drill-down.
+file totals, confidence, and resolution provenance. Expanding an opportunity
+shows caller-to-sink paths; raw findings remain canonical and load as a
+separately paged evidence drill-down.
+
+**One opportunity per intervention.** An opportunity is the place you edit,
+within one cost family and boundary: the function holding the loop, or a helper
+every caller reaches the sink through. The sinks it reaches, its call sites and
+co-signals of one family (`io_in_loop` with `nested_loop_with_io`) are members,
+so one loop reaching three sinks is one opportunity with three
+`terminal_sinks`, not three opportunities. Every opportunity names its
+`intervention_symbol` and `intervention_kind` (`function`, `shared_helper`, or
+`module` for top-level script code, named `<file>::__module__`). Two loops in one
+function are one edit site today, because findings carry the sink's line and not
+the loop's.
+
+**The default queue** (MCP `get_health` and the REST list) holds production
+opportunities with a strategy: `plan_ready` and `advisory`. Test, tooling and
+unclassified code, `expected` repetition and `investigate` causes (no
+supported strategy, so no safe plan) are one filter away, and the summary's
+`default_queue` block counts each reason it leaves out, so nothing is dropped
+silently. Fix first (the dashboard lead, `repowise health` and the Overview's
+Do next) takes its performance items through the same predicate and counts the
+same reasons in `totals.excluded`.
+
+**Order.** The queue is ranked by value (`rank_score`) first; actionability only
+breaks a tie, so at equal value a plan-ready cause comes before an advisory one,
+and a cheap plan never outranks a costlier cause.
When the deterministic service can describe a safe intervention, the
opportunity links by its exact stable `opportunity_id` to the matching
diff --git a/packages/core/src/repowise/core/analysis/change_health/perf_delta.py b/packages/core/src/repowise/core/analysis/change_health/perf_delta.py
index c618377a0..9899c56f8 100644
--- a/packages/core/src/repowise/core/analysis/change_health/perf_delta.py
+++ b/packages/core/src/repowise/core/analysis/change_health/perf_delta.py
@@ -34,10 +34,9 @@ class PerfOpportunityView:
affected_call_sites_total: int
observations_total: int
evidence: list[dict[str, Any]]
-
- @property
- def is_cross_function(self) -> bool:
- return self.intervention_symbol is not None
+ # A member reached its sink through a call: every group names an
+ # intervention, so the symbol alone no longer says this.
+ is_cross_function: bool = False
def summary(self) -> str:
if self.is_cross_function:
@@ -95,4 +94,5 @@ def _view(opportunity: Any) -> PerfOpportunityView:
affected_call_sites_total=opportunity.affected_call_sites_total,
observations_total=opportunity.observations_total,
evidence=evidence[:EVIDENCE_CAP],
+ is_cross_function=any(len(row.get("path") or ()) >= 2 for row in evidence),
)
diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/lazy_load_in_loop.py b/packages/core/src/repowise/core/analysis/health/biomarkers/lazy_load_in_loop.py
index ce22715f3..54d72db83 100644
--- a/packages/core/src/repowise/core/analysis/health/biomarkers/lazy_load_in_loop.py
+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/lazy_load_in_loop.py
@@ -1,8 +1,9 @@
"""Lazily-declared relationship read on each iteration of a loop.
-Lifts ``perf.lazy_load`` hits. ``PerfHit.path`` carries ``(subject, fix)``: the
-relationship read (``Incident.owner``) and the eager load that replaces it
-(``selectinload(Incident.owner)``, ``select_related("owner")``).
+Lifts ``perf.lazy_load`` hits. ``PerfHit.path`` carries ``(subject, fix, orm)``:
+the relationship read (``Incident.owner``), the eager load that replaces it
+(``selectinload(Incident.owner)``, ``select_related("owner")``), and the ORM
+(``sqlalchemy`` or ``django``), which the score and the lead read per finding.
"""
from __future__ import annotations
@@ -22,7 +23,7 @@ class LazyLoadInLoopDetector:
for hit in ctx.perf_hits:
if hit.kind != _KIND:
continue
- subject, fix = hit.path
+ subject, fix, orm = hit.path
out.append(
BiomarkerResult(
biomarker_type=self.name,
@@ -34,6 +35,7 @@ class LazyLoadInLoopDetector:
"boundary_kind": hit.detail,
"relationship": subject,
"eager_load": fix,
+ "orm": orm,
**hit.loop_facts(),
},
reason=(
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py b/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py
index 9c754de8a..c4d1c6e8c 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/perf_walk.py
@@ -19,13 +19,14 @@ registered.
from __future__ import annotations
+from dataclasses import replace
from typing import TYPE_CHECKING
from ..perf.dialects import PERF_DIALECTS
from ..perf.dialects.base import BasePerfDialect as BasePerfDialectClass
from ..perf.io_boundaries import collect_io_names
from ..perf.loop_facts import LoopFacts
-from .ast_utils import _dart_signature_sibling, _find_name
+from .ast_utils import _dart_signature_sibling, _find_function_entry_name, _find_name
from .languages import LanguageNodeMap
from .models import PerfFnFacts, PerfHit
@@ -112,6 +113,28 @@ def _perf_func_name(node: Node) -> str | None:
return name if name != "<anonymous>" else None
+def _name_lambda_hits(hits: list[PerfHit], spans: list[tuple[int, int, str]]) -> list[PerfHit]:
+ """Name a hit with no enclosing named function after the lambda holding it.
+
+ The innermost span wins, and the name is the one the complexity walker gives
+ that lambda (its binding, ``<callee> callback``, or ``<anonymous@line>``), so
+ the two passes agree. A hit outside every lambda is top-level code and keeps
+ ``None``. Only the hit is renamed: the per-function facts stay keyed to
+ module scope, where the cross-function bridge resolves them.
+ """
+ if not spans:
+ return hits
+ named: list[PerfHit] = []
+ for hit in hits:
+ if hit.function is None:
+ inside = [span for span in spans if span[0] <= hit.line <= span[1]]
+ if inside:
+ innermost = min(inside, key=lambda span: span[1] - span[0])
+ hit = replace(hit, function=innermost[2])
+ named.append(hit)
+ return named
+
+
def _enclosing_loop_iterables(
node: Node,
dialect: BasePerfDialect,
@@ -297,6 +320,9 @@ def _collect_perf_hits(
] = {}
# func_start -> {call_line: facts} for the loop-call targets above.
call_facts: dict[int, dict[int, LoopFacts]] = {}
+ # ``(first_line, last_line, name)`` of each lambda with no named function
+ # around it, so a hit inside one is named for it rather than left blank.
+ lambda_spans: list[tuple[int, int, str]] = []
def _acc(
func_start: int, func_name: str | None
@@ -359,6 +385,14 @@ def _collect_perf_hits(
if t in fn_kinds:
next_func = _perf_func_name(node) or func_name
next_start = node.start_point[0] + 1
+ elif t in lambda_kinds and func_name is None:
+ lambda_spans.append(
+ (
+ node.start_point[0] + 1,
+ node.end_point[0] + 1,
+ _find_function_entry_name(node, lmap),
+ )
+ )
# A data-dependent loop nested inside another (``loop_depth`` only counts
# non-constant loops) is an O(n^2) shape. Record the site as a fact; the
@@ -618,7 +652,7 @@ def _collect_perf_hits(
# one logical query, one finding. Collapse per (kind, line, function).
seen: set[tuple[str, int, str | None]] = set()
deduped: list[PerfHit] = []
- for h in hits:
+ for h in _name_lambda_hits(hits, lambda_spans):
key = (h.kind, h.line, h.function)
if key in seen:
continue
diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.py
index a1ff895f2..84a91a6fb 100644
--- a/packages/core/src/repowise/core/analysis/health/engine.py
+++ b/packages/core/src/repowise/core/analysis/health/engine.py
@@ -129,6 +129,13 @@ log = structlog.get_logger(__name__)
# line (``details["symbol_line"]``) and its public id is anchored on the symbol
# plus the offset into it, hashing no metric values, so every stored finding id
# moves once.
+# v37 (also): a perf hit inside a lambda with no named function around it is
+# named for that lambda (``build``, ``it callback``), so its stored
+# ``function_name`` and public id change; top-level script code still carries
+# none. The v3 performance model also keys one opportunity per intervention, so
+# every stored opportunity id and the id stamped on every perf finding change.
+# ``lazy_load_in_loop`` findings carry ``details["orm"]``, which moves their
+# public ids and, for Django, their performance weight (0.4 -> 0.7).
#
# v36 (also): which files are tests changed (``repowise.core.test_paths``).
# Compound directories headed by a test word (``e2e-tests/``, ``pkg_tests/``,
diff --git a/packages/core/src/repowise/core/analysis/health/fix_first/build.py b/packages/core/src/repowise/core/analysis/health/fix_first/build.py
index cde920f80..3951597ea 100644
--- a/packages/core/src/repowise/core/analysis/health/fix_first/build.py
+++ b/packages/core/src/repowise/core/analysis/health/fix_first/build.py
@@ -46,7 +46,11 @@ from typing import Any
from repowise.core.analysis.finding_registry import excluded_types
from repowise.core.analysis.health.models import primary_finding, split_by_origin
-from repowise.core.analysis.health.perf.causal import code_context, execution_context
+from repowise.core.analysis.health.perf.causal import code_context
+from repowise.core.analysis.health.perf.opportunity_rank import (
+ DEFAULT_QUEUE_CONTEXTS,
+ default_queue_exclusion,
+)
from repowise.core.analysis.health.refactoring.extract_helper import _is_generated_path
from repowise.core.analysis.health.rows import detail_map, field, json_field
from repowise.core.analysis.health.scoring import biomarker_dimension
@@ -151,19 +155,17 @@ def _num(value: Any) -> float:
#: The shared path rules, memoised: they are pure on the path and the test
#: check dominates a cold build.
_code_context = functools.lru_cache(maxsize=65536)(code_context)
-_perf_context = functools.lru_cache(maxsize=65536)(execution_context)
-def _path_exclusion(
- path: str, is_test: bool | None, context: str | None = None, *, perf: bool = False
-) -> str | None:
+def _path_exclusion(path: str, is_test: bool | None, context: str | None = None) -> str | None:
"""Why a file is out of the queue, or ``None`` when it ships.
- Code-shape work reads :func:`code_context`, where a CLI ships; a
- performance fix reads the stored execution context, where a CLI loop is
- off the request path. The stored ``is_test`` flag also marks a test.
+ Code-shape work reads :func:`code_context`, where a CLI ships. A
+ performance fix passes ``production``: its stored execution context is
+ judged by the performance default queue, so only the path rules apply.
+ The stored ``is_test`` flag also marks a test.
"""
- ctx = context or (_perf_context(path) if perf else _code_context(path))
+ ctx = context or _code_context(path)
if is_test or ctx == "test":
return "test"
parts = set(path.lower().split("/")[:-1])
@@ -604,12 +606,8 @@ def _refactor_measure(
# --- performance ----------------------------------------------------------------
-def _perf_ready(row: Any) -> bool:
- return (
- field(row, "actionability_state") != "expected"
- and field(row, "plan_state") == "available"
- and bool(field(row, "fix_strategy"))
- )
+def _has_plan(row: Any) -> bool:
+ return field(row, "plan_state") == "available" and bool(field(row, "fix_strategy"))
def _perf_value(row: Any, facets: Mapping[str, Any]) -> int:
@@ -965,8 +963,8 @@ def build_fix_first(
hot_cuts,
)
- def out_of_scope(path: str, context: str | None = None, *, perf: bool = False) -> bool:
- reason = _path_exclusion(path, files.is_test(path), context, perf=perf)
+ def out_of_scope(path: str, context: str | None = None) -> bool:
+ reason = _path_exclusion(path, files.is_test(path), context)
if reason is None or (reason == "test" and keep_tests):
return False
excluded[reason] += 1
@@ -1003,14 +1001,19 @@ def build_fix_first(
if _open(row):
path = field(row, "file_path") or ""
groups[(path, field(row, "intervention_symbol") or path)].append(row)
+ # The performance default queue decides which causes are work (context and
+ # actionability, one predicate for every surface); Fix first adds its path
+ # rules and needs a stored plan to quote.
+ perf_contexts = DEFAULT_QUEUE_CONTEXTS | {"test"} if keep_tests else DEFAULT_QUEUE_CONTEXTS
for (path, _symbol), rows in groups.items():
- context = field(rows[0], "execution_context")
- if out_of_scope(path, context, perf=True):
+ if out_of_scope(path, "production"):
continue
- ready = [r for r in rows if _perf_ready(r)]
+ rows.sort(key=lambda r: (field(r, "rank_position") or 0, field(r, "opportunity_id")))
+ reasons = [default_queue_exclusion(r, perf_contexts) for r in rows]
+ queued = [r for r, reason in zip(rows, reasons, strict=True) if reason is None]
+ ready = [r for r in queued if _has_plan(r)]
if not ready:
- expected = any(field(r, "actionability_state") == "expected" for r in rows)
- excluded["expected" if expected else "no_plan"] += 1
+ excluded["no_plan" if queued else reasons[0] or "no_plan"] += 1
continue
units.append(_perf_unit(ready, files))
diff --git a/packages/core/src/repowise/core/analysis/health/fix_first/model.py b/packages/core/src/repowise/core/analysis/health/fix_first/model.py
index ec95e4ad8..1605d4fc3 100644
--- a/packages/core/src/repowise/core/analysis/health/fix_first/model.py
+++ b/packages/core/src/repowise/core/analysis/health/fix_first/model.py
@@ -34,8 +34,18 @@ FIX_LEVELS: tuple[str, ...] = get_args(FixLevel)
FixFactBasis = Literal["measured", "inferred", "unknown"]
FIX_FACT_BASES: tuple[str, ...] = get_args(FixFactBasis)
+# ``unknown``, ``expected`` and ``no_strategy`` are the performance default
+# queue's own reasons (``opportunity_rank.DEFAULT_QUEUE_EXCLUSIONS``).
FixExclusion = Literal[
- "test", "tooling", "generated", "expected", "no_plan", "below_min_worth", "history_only"
+ "test",
+ "tooling",
+ "unknown",
+ "generated",
+ "expected",
+ "no_strategy",
+ "no_plan",
+ "below_min_worth",
+ "history_only",
]
FIX_EXCLUSIONS: tuple[str, ...] = get_args(FixExclusion)
diff --git a/packages/core/src/repowise/core/analysis/health/perf/causal.py b/packages/core/src/repowise/core/analysis/health/perf/causal.py
index caf733332..d0dadd61b 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/causal.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/causal.py
@@ -33,12 +33,21 @@ from the string alone. Version 1 ids carry no digit and remain readable as
version 1. Moving this constant means bumping ``HEALTH_ANALYZER_VERSION`` with
it, which forces the rescore that restamps every stored finding.
-Version 3 classes schema migrations as ``tooling`` in :func:`execution_context`,
-a kernel input. Digests of every other path are unchanged; only the prefix moved.
+Version 3 keys a cause by its intervention, not by the sink it reaches: one
+loop reaching three sinks was three opportunities under version 2. It also
+classes schema migrations as ``tooling`` in :func:`execution_context`, a kernel
+input.
"""
ExecutionContext = Literal["production", "tooling", "test", "unknown"]
+# Where the edit lands: the function holding the loop, a helper every caller
+# reaches the sink through, or top-level script code.
+InterventionKind = Literal["function", "shared_helper", "module"]
+
+MODULE_SCOPE = "__module__"
+"""The symbol name for top-level code, the same synthetic node the graph uses."""
+
CausalKey = tuple[Any, ...]
_ID_PREFIX = "perf"
@@ -135,42 +144,53 @@ def cost_shape(marker: str) -> str:
return marker
-def causal_key(facts: ObservationFacts) -> CausalKey:
- """The v2 identity kernel.
+def shared_helper(facts: ObservationFacts) -> str | None:
+ """The helper the repetition passes through, when the loop is not the edit.
+
+ On ``loop owner -> helper -> ... -> sink`` every caller reaches the sink
+ through the sink's immediate caller, so that helper is the one place a
+ batched form settles them all. A two-node path has no helper: the loop
+ owner calls the sink-holding function itself, so the loop is the edit.
+ """
+ if facts.cross_function and facts.path_depth >= 3:
+ return facts.meaningful_predecessor
+ return None
- A cross-function cause is named by the pair the intervention lives in:
- the sink that pays the cost and the caller that repeats it. Naming it by
- the sink alone merged every workflow that happened to reach a shared
- infrastructure helper, so a session opener reached from many unrelated
- callers read as one cause. Requiring the caller to match splits those, and
- leaves a genuinely shared helper merged however many callers reach it,
- because they all reach the sink through that helper.
- A same-function cause has no call path and is named by its own location.
+def causal_key(facts: ObservationFacts) -> CausalKey:
+ """The v3 identity kernel: one cause per intervention and cost family.
+
+ The unit is the place a person edits. A loop is named by the function that
+ holds it, so the sinks it reaches, the call sites inside it, and the
+ co-signals of one cost family (``io_in_loop`` with ``nested_loop_with_io``)
+ are members of one cause, not one cause each. A shared helper is named by
+ itself, so unrelated callers that reach a sink through it stay one cause,
+ and unrelated callers of a generic sink stay apart because each loop owner
+ is its own intervention.
+
+ Boundary stays in: a loop doing database and filesystem work holds two
+ different changes. The loop's own line does not: two loops in one function
+ are one edit site, and their lines stay in the evidence. That is a ceiling,
+ not a claim that they are one loop: findings record the sink's line and not
+ the loop's, so splitting per loop would need the walk to carry the loop
+ line into ``details`` first.
Everything outside these tuples is display or derived data and stays out:
- prose, line ends, storage ids, rank factors, confidence, reachability, and
- provenance.
+ prose, lines, sinks, storage ids, rank factors, confidence, reachability,
+ and provenance.
"""
context = execution_context(facts.file_path)
- predecessor = facts.meaningful_predecessor
- if facts.cross_function and predecessor is not None:
- return (
- "cross-function",
- context,
- cost_shape(facts.marker),
- facts.boundary_kind,
- predecessor,
- facts.terminal_sink,
- )
+ family = cost_shape(facts.marker)
+ helper = shared_helper(facts)
+ if helper is not None:
+ return ("shared_helper", context, family, facts.boundary_kind, helper)
return (
- "local",
+ "function",
context,
- facts.marker,
+ family,
facts.boundary_kind,
facts.file_path,
- facts.function_name,
- facts.line_start,
+ facts.function_name or None,
)
@@ -190,18 +210,20 @@ def key_boundary(key: CausalKey) -> str | None:
return key[3]
-def key_is_cross_function(key: CausalKey) -> bool:
- return key[0] == "cross-function"
+def key_intervention_kind(key: CausalKey) -> InterventionKind:
+ if key[0] == "shared_helper":
+ return "shared_helper"
+ return "function" if key[5] else "module"
-def key_intervention_symbol(key: CausalKey) -> str | None:
- """The caller the whole group shares, and therefore the place to edit."""
- return key[4] if key_is_cross_function(key) else None
+def key_intervention_symbol(key: CausalKey) -> str:
+ """The place the whole group shares, and therefore the place to edit.
-
-def key_terminal_sink(key: CausalKey) -> str | None:
- """The sink the whole group shares. Read off the key, never off a member."""
- return key[5] if key_is_cross_function(key) else None
+ Every group has one: top-level script code is named for its module.
+ """
+ if key[0] == "shared_helper":
+ return key[4]
+ return f"{key[4]}::{key[5] or MODULE_SCOPE}"
def opportunity_id_model_version(opportunity_id: str) -> int | None:
@@ -286,22 +308,24 @@ def shared_path_suffix(paths: list[tuple[str, ...]]) -> tuple[str, ...]:
__all__ = [
+ "MODULE_SCOPE",
"PERFORMANCE_MODEL_VERSION",
"CausalKey",
"ExecutionContext",
+ "InterventionKind",
"causal_key",
"cost_shape",
"execution_context",
"group_observations",
"key_boundary",
"key_context",
+ "key_intervention_kind",
"key_intervention_symbol",
- "key_is_cross_function",
- "key_terminal_sink",
"link_performance_findings",
"model_state",
"opportunity_id_for_finding",
"opportunity_id_model_version",
+ "shared_helper",
"shared_path_suffix",
"stable_id",
]
diff --git a/packages/core/src/repowise/core/analysis/health/perf/lazy_load.py b/packages/core/src/repowise/core/analysis/health/perf/lazy_load.py
index a184ea8f7..4ef9bca58 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/lazy_load.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/lazy_load.py
@@ -717,7 +717,7 @@ def _loop_hit(
fn_name,
"db",
func_start=fn.start_point[0] + 1,
- path=(subject, fix),
+ path=(subject, fix, orm),
loop=loop_facts,
)
diff --git a/packages/core/src/repowise/core/analysis/health/perf/opportunities.py b/packages/core/src/repowise/core/analysis/health/perf/opportunities.py
index 22342e581..6f083bbf9 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/opportunities.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/opportunities.py
@@ -32,13 +32,13 @@ from .actionability import (
from .causal import (
PERFORMANCE_MODEL_VERSION,
ExecutionContext,
+ InterventionKind,
execution_context,
group_observations,
key_boundary,
key_context,
+ key_intervention_kind,
key_intervention_symbol,
- key_is_cross_function,
- key_terminal_sink,
link_performance_findings,
model_state,
opportunity_id_for_finding,
@@ -54,6 +54,7 @@ from .opportunity_rank import (
exposure,
leverage,
loop_magnitude,
+ may_lead,
rank_factors,
rank_sort_key,
weakest_provenance,
@@ -78,9 +79,13 @@ class PerformanceOpportunity:
biomarker_types: tuple[str, ...]
boundary_kind: str | None
execution_context: ExecutionContext
+ # The one sink every member reaches, else ``None``; all of them are in
+ # ``terminal_sinks``, because one loop can reach several.
terminal_sink: str | None
shared_path_suffix: tuple[str, ...]
- intervention_symbol: str | None
+ intervention_symbol: str
+ intervention_kind: InterventionKind
+ terminal_sinks: tuple[str, ...]
resource_fingerprints: tuple[str, ...]
affected_call_sites_total: int
affected_files_total: int
@@ -98,6 +103,8 @@ class PerformanceOpportunity:
rank_factors: dict[str, int]
why_ranked: tuple[dict[str, Any], ...]
fix: PerformanceFix | None
+ # Whether this group may lead the directive; see ``opportunity_rank.may_lead``.
+ may_lead: bool
# Other causes observed on the same lines; see :mod:`.siblings`.
siblings: tuple[dict[str, Any], ...] = ()
@@ -112,6 +119,8 @@ class PerformanceOpportunity:
"terminal_sink": self.terminal_sink,
"shared_path_suffix": list(self.shared_path_suffix),
"intervention_symbol": self.intervention_symbol,
+ "intervention_kind": self.intervention_kind,
+ "terminal_sinks": list(self.terminal_sinks),
"resource_fingerprints": list(self.resource_fingerprints),
"affected_call_sites_total": self.affected_call_sites_total,
"affected_files_total": self.affected_files_total,
@@ -129,6 +138,7 @@ class PerformanceOpportunity:
"rank_factors": dict(self.rank_factors),
"why_ranked": [dict(entry) for entry in self.why_ranked],
"fix": self.fix.as_dict() if self.fix else None,
+ "may_lead": self.may_lead,
"siblings": [dict(entry) for entry in self.siblings],
}
@@ -143,10 +153,10 @@ def _reachability(values: set[Any]) -> bool | None:
def _assemble(key: Any, members: list[Any], cap: int) -> PerformanceOpportunity:
"""Read one group's answers off its owners. Decides nothing itself.
- Context, boundary, intervention symbol, and terminal sink are kernel
- inputs, so the group already agrees on them by construction. Taking them
- off the key keeps one owner for each instead of reclassifying a
- representative row.
+ Context, boundary, and intervention are kernel inputs, so the group
+ already agrees on them by construction. Taking them off the key keeps one
+ owner for each instead of reclassifying a representative row. Sinks are
+ members' facts, so they are listed rather than assumed shared.
"""
context = key_context(key)
boundary = key_boundary(key)
@@ -157,12 +167,13 @@ def _assemble(key: Any, members: list[Any], cap: int) -> PerformanceOpportunity:
provenance = weakest_provenance({facts.provenance for facts in members})
evidence_confidence = provenance_confidence(provenance)
reachable = _reachability({facts.reliable_entry_reachability for facts in members})
+ sinks = tuple(sorted({facts.terminal_sink for facts in members if facts.terminal_sink}))
assessment = assess_fix(
marker,
markers,
boundary,
[facts.details for facts in members],
- cross_function=key_is_cross_function(key),
+ cross_function=any(facts.cross_function for facts in members),
)
acted = actionability(assessment, evidence_confidence)
magnitude = loop_magnitude(marker, [facts.details for facts in members])
@@ -182,9 +193,11 @@ def _assemble(key: Any, members: list[Any], cap: int) -> PerformanceOpportunity:
biomarker_types=markers,
boundary_kind=boundary,
execution_context=context,
- terminal_sink=key_terminal_sink(key),
+ terminal_sink=sinks[0] if len(sinks) == 1 else None,
shared_path_suffix=shared_path_suffix([facts.path for facts in members if facts.path]),
intervention_symbol=key_intervention_symbol(key),
+ intervention_kind=key_intervention_kind(key),
+ terminal_sinks=sinks,
resource_fingerprints=tuple(
sorted({facts.resource_fingerprint for facts in members if facts.resource_fingerprint})
),
@@ -222,6 +235,7 @@ def _assemble(key: Any, members: list[Any], cap: int) -> PerformanceOpportunity:
},
),
fix=acted.fix,
+ may_lead=may_lead(marker, {facts.details.get("orm") for facts in members}),
)
diff --git a/packages/core/src/repowise/core/analysis/health/perf/opportunity_rank.py b/packages/core/src/repowise/core/analysis/health/perf/opportunity_rank.py
index 6725bfc01..afbc2152b 100644
--- a/packages/core/src/repowise/core/analysis/health/perf/opportunity_rank.py
+++ b/packages/core/src/repowise/core/analysis/health/perf/opportunity_rank.py
@@ -8,7 +8,7 @@ This module owns every judgement about how much a group costs and how far a
change to it reaches: the marker, boundary, context, and provenance tables and
the four magnitude facets read off them. Whether a change is *safe* is the
neighbouring module's question, and the only thing this one takes from it is
-the actionability state that orders actionable work first.
+the actionability state that breaks a tie in value.
Every input is already carried on the group. Ranking issues no query of its
own, per opportunity or otherwise.
@@ -19,6 +19,8 @@ from __future__ import annotations
from math import log2
from typing import Any
+from ..rows import field
+
BOUNDARY_POINTS = {"subprocess": 5, "network": 4, "db": 4, "lock": 3, "filesystem": 2}
"""What one crossing of each boundary costs, as an order of magnitude.
@@ -69,9 +71,27 @@ NON_LEADING_MARKERS = frozenset({"lazy_load_in_loop"})
``lazy_load_in_loop`` measured 81% on held-out Django (47/58, 2026-09-26), inside the
80-90% tier whose pre-registered rule is "advisory, never leads". Remove a marker once a
-held-out sample puts it at 90% or above.
+held-out sample puts it at 90% or above, or list the ORM that cleared it below.
"""
+LEADING_ORMS = {"lazy_load_in_loop": frozenset({"django"})}
+"""ORMs a non-leading marker may lead for, read off each finding's ``details["orm"]``.
+
+Django cleared the bar on a fresh held-out sample after narrowing (29/32 = 90.6%,
+Wilson LB 75.8%); SQLAlchemy has fewer than 30 labels and stays non-leading.
+"""
+
+
+def may_lead(marker: str, orms: set[Any]) -> bool:
+ """Whether a group of *marker* with members on *orms* may lead the directive.
+
+ Every member has to be on an ORM that cleared the bar: one unmeasured member
+ is enough to keep the group from leading.
+ """
+ if marker not in NON_LEADING_MARKERS:
+ return True
+ return bool(orms) and orms <= LEADING_ORMS.get(marker, frozenset())
+
UNKNOWN_MULTIPLIER_POINTS = 1
"""A detector added without a weight under-ranks rather than jumps the queue."""
@@ -102,13 +122,28 @@ characterised reports ``unknown`` rather than borrowing a neighbour's shape.
"""
ACTIONABILITY_ORDER = {"plan_ready": 0, "advisory": 1, "investigate": 2, "expected": 3}
-"""Actionable work sorts above evidence, whatever the raw magnitude.
+"""The tie-break between groups of equal value: the more actionable one first.
+
+Value leads. Sorting actionability first put a low-value plan above a costly
+cause nobody had a plan for yet, so the queue's order said "easy" where it
+should say "worth it". A plan-ready group is still never buried by an equal
+one, and the default queue leaves out what has no strategy at all, which is
+what kept a generic sink's volume from crowding out actionable work.
+"""
+
+DEFAULT_QUEUE_CONTEXTS = frozenset({"production"})
+DEFAULT_QUEUE_STATES = frozenset({"plan_ready", "advisory"})
+"""What the queue holds when a caller names no filter: production work with a strategy.
-A generic sink accumulates points through sheer volume. Left to the score
-alone it buries every group somebody could act on today, which is the wrong
-lead for both an agent and a person. ``expected`` is never a lead.
+Test, tooling and unclassified code, ``expected`` repetition, and causes with no
+supported strategy (``investigate``, whose plan state is always ``no_safe_plan``)
+are true and stay one filter away, but none of them is work to schedule. Each is
+counted by :func:`default_queue_exclusion` so leaving it out is never silent.
"""
+DEFAULT_QUEUE_EXCLUSIONS = ("test", "tooling", "unknown", "expected", "no_strategy")
+"""Every reason the default queue leaves a cause out, in the order it is checked."""
+
_LEVERAGE_BANDS = ((1, "isolated"), (3, "local"), (9, "shared"))
_CHANGE_RISK_BANDS = ((1, "contained"), (4, "moderate"))
@@ -241,14 +276,46 @@ def why_ranked(factors: dict[str, int], values: dict[str, Any], limit: int = 3)
)
+def default_queue_exclusion(
+ item: Any, contexts: frozenset[str] = DEFAULT_QUEUE_CONTEXTS
+) -> str | None:
+ """Why the default queue leaves *item* out, or ``None`` when it is queued.
+
+ One reason per cause, context first, so the counts of every reason and the
+ queue add up to the whole. Reads an opportunity, an ORM row or a plain row.
+ *contexts* widens the queue for a caller that asked for more (Fix first's
+ ``scope="all"`` keeps test code); the state rule never moves.
+ """
+ context = field(item, "execution_context")
+ if context not in contexts:
+ return context
+ state = field(item, "actionability_state")
+ if state in DEFAULT_QUEUE_STATES:
+ return None
+ return "expected" if state == "expected" else "no_strategy"
+
+
+def default_queue_counts(items: list[Any]) -> dict[str, Any]:
+ """The default queue's size and what it leaves out, by reason."""
+ excluded = dict.fromkeys(DEFAULT_QUEUE_EXCLUSIONS, 0)
+ queued = 0
+ for item in items:
+ reason = default_queue_exclusion(item)
+ if reason is None:
+ queued += 1
+ else:
+ excluded[reason] = excluded.get(reason, 0) + 1
+ return {"total": queued, "excluded": excluded}
+
+
def rank_sort_key(item: Any) -> tuple[int, int, int, str]:
- """A total order: actionable first, then rank, leverage, and id.
+ """A total order: value first, then actionability, leverage, and id.
The id tail is what makes it total, so ties never float between runs.
"""
return (
- ACTIONABILITY_ORDER[item.actionability_state],
-item.rank_score,
+ ACTIONABILITY_ORDER[item.actionability_state],
-item.affected_call_sites_total,
item.opportunity_id,
)
@@ -260,17 +327,25 @@ __all__ = [
"BOUNDARY_POINTS",
"CONTEXT_POINTS",
"CROSS_FUNCTION_POINTS",
+ "DEFAULT_QUEUE_CONTEXTS",
+ "DEFAULT_QUEUE_EXCLUSIONS",
+ "DEFAULT_QUEUE_STATES",
+ "LEADING_ORMS",
"MAGNITUDE_POINTS",
"MULTIPLIER_POINTS",
+ "NON_LEADING_MARKERS",
"PROVENANCE_POINTS",
"UNKNOWN_MULTIPLIER_POINTS",
"amplification",
"band",
"change_risk",
+ "default_queue_counts",
+ "default_queue_exclusion",
"dominant_marker",
"exposure",
"leverage",
"loop_magnitude",
+ "may_lead",
"observation_rank",
"rank_factors",
"rank_sort_key",
diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py b/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py
index 328f4ea33..851c9708e 100644
--- a/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py
+++ b/packages/core/src/repowise/core/analysis/health/refactoring/performance_fix.py
@@ -76,7 +76,7 @@ def fix_steps(
target = intervention or sink
steps.append(
{
- "action": intro.format(sink=(target or "the shared sink").rsplit("::", 1)[-1]),
+ "action": intro.format(sink=(target or "the per-key call").rsplit("::", 1)[-1]),
"symbol": target,
"file_path": file_of_symbol(target) if target else None,
"line": None,
@@ -152,8 +152,17 @@ def _suggestion(
}
for item in opportunity.evidence
]
+ # A bulk form belongs on the per-key callee: the shared helper, else the one
+ # sink the loop reaches. The loop's own function is where the keys are
+ # collected, never what gains the bulk form.
+ batched_on_helper = opportunity.intervention_kind == "shared_helper"
steps = fix_steps(
- fix.strategy, fix.safety, intervention, opportunity.terminal_sink, locations, fix.api
+ fix.strategy,
+ fix.safety,
+ intervention if fix.strategy != "batch_or_prefetch_io" or batched_on_helper else None,
+ opportunity.terminal_sink,
+ locations,
+ fix.api,
)
mechanical = sum(step["applicability"] == "mechanical" for step in steps)
return RefactoringSuggestion(
diff --git a/packages/core/src/repowise/core/analysis/health/scoring.py b/packages/core/src/repowise/core/analysis/health/scoring.py
index 36edeafd5..b8a428439 100644
--- a/packages/core/src/repowise/core/analysis/health/scoring.py
+++ b/packages/core/src/repowise/core/analysis/health/scoring.py
@@ -465,10 +465,19 @@ _PERFORMANCE_WEIGHT_MULTIPLIER: dict[str, float] = {
"sql_cartesian_join": 0.6,
# Advisory pending a corpus precision gate, like every new perf marker.
"unbounded_read_reduced_in_memory": 0.4,
- # Advisory until the pre-registered precision tiers are measured (2026-09-26).
+ # Advisory for an ORM without a held-out measurement; see the per-ORM table below.
"lazy_load_in_loop": 0.4,
}
+# Per-finding weight for a marker whose precision differs by ORM, keyed by the
+# finding's ``details["orm"]``. One marker, one id: the ORM is a fact on the
+# finding, not a second marker. Django measured 29/32 = 90.6% (Wilson LB 75.8%)
+# on a fresh held-out sample (2026-09-26), which clears the 90% bar; SQLAlchemy
+# (20/24, n < 30) has no tier yet and keeps the marker weight above.
+_PERFORMANCE_ORM_WEIGHT: dict[str, dict[str, float]] = {
+ "lazy_load_in_loop": {"django": 0.7},
+}
+
# All perf biomarkers share one ``performance`` category, so the single cap
# below bounds the entire dimension's deduction.
_PERFORMANCE_CATEGORY: dict[str, str] = {
@@ -596,8 +605,15 @@ def maintainability_category(name: str) -> str:
return _MAINTAINABILITY_CATEGORY.get(name, "size_and_complexity")
-def performance_weight(name: str) -> float:
- """Performance multiplier; 1.0 for unknown biomarkers."""
+def performance_weight(name: str, orm: str | None = None) -> float:
+ """Performance multiplier; 1.0 for unknown biomarkers.
+
+ *orm* is the finding's ``details["orm"]``: a marker measured per ORM carries
+ that ORM's weight, and falls back to the marker's own for any other.
+ """
+ by_orm = _PERFORMANCE_ORM_WEIGHT.get(name, {})
+ if orm in by_orm:
+ return by_orm[orm]
return _PERFORMANCE_WEIGHT_MULTIPLIER.get(name, 1.0)
@@ -608,7 +624,7 @@ def performance_category(name: str) -> str:
def _score_dimension(
results_list: list[BiomarkerResult],
- weight_fn: Callable[[str], float],
+ weight_fn: Callable[[BiomarkerResult], float],
category_fn: Callable[[str], str],
caps: dict[str, float],
conditioned_cap: tuple[str, Callable[[float], float]] | None = None,
@@ -631,7 +647,7 @@ def _score_dimension(
# both paths are then weighted and category-capped identically, so the
# per-finding ``health_impact`` stays linear and attributable.
base = r.deduction if r.deduction is not None else severity_deduction(r.severity)
- weighted = base * weight_fn(r.biomarker_type)
+ weighted = base * weight_fn(r)
raw.setdefault(cat, []).append((idx, weighted))
per_result = [0.0] * len(results_list)
@@ -720,7 +736,7 @@ def score_file(results: Iterable[BiomarkerResult]) -> tuple[dict[str, float | No
defect_results = [results_list[i] for i in defect_idx]
defect_score, defect_sub = _score_dimension(
defect_results,
- biomarker_weight,
+ lambda r: biomarker_weight(r.biomarker_type),
biomarker_category,
CATEGORY_CAPS,
conditioned_cap=(HISTORY_CATEGORY, history_cap),
@@ -734,7 +750,7 @@ def score_file(results: Iterable[BiomarkerResult]) -> tuple[dict[str, float | No
]
maint_score, _ = _score_dimension(
maint_results,
- maintainability_weight,
+ lambda r: maintainability_weight(r.biomarker_type),
maintainability_category,
_MAINTAINABILITY_CATEGORY_CAPS,
)
@@ -744,7 +760,7 @@ def score_file(results: Iterable[BiomarkerResult]) -> tuple[dict[str, float | No
perf_results = [r for r in results_list if "performance" in dimensions_for(r.biomarker_type)]
perf_score, _ = _score_dimension(
perf_results,
- performance_weight,
+ lambda r: performance_weight(r.biomarker_type, (r.details or {}).get("orm")),
performance_category,
_PERFORMANCE_CATEGORY_CAPS,
)
diff --git a/packages/core/src/repowise/core/persistence/crud/analysis/fix_first.py b/packages/core/src/repowise/core/persistence/crud/analysis/fix_first.py
index d033548eb..b86c5421f 100644
--- a/packages/core/src/repowise/core/persistence/crud/analysis/fix_first.py
+++ b/packages/core/src/repowise/core/persistence/crud/analysis/fix_first.py
@@ -30,6 +30,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from repowise.core.analysis.finding_registry import excluded_types
from repowise.core.analysis.health.fix_first import DEFAULT_LIMIT, FixFirstQueue, build_fix_first
from repowise.core.analysis.health.fix_first.build import MIN_WORTH, hot_cut, hot_cut_offset
+from repowise.core.analysis.health.perf.opportunity_rank import DEFAULT_QUEUE_STATES
from repowise.core.analysis.health.rows import detail_map
from repowise.core.analysis.health.scoring import history_biomarkers
@@ -251,8 +252,9 @@ async def _refactoring(session: AsyncSession, repo_id: str) -> list[Any]:
async def _performance(session: AsyncSession, repo_id: str) -> list[Any]:
p = PerformanceOpportunity
+ # Details are decoded only for a cause the builder can make an item of.
ready = and_(
- p.actionability_state != "expected",
+ p.actionability_state.in_(DEFAULT_QUEUE_STATES),
p.plan_state == "available",
p.fix_strategy.is_not(None),
)
diff --git a/packages/core/src/repowise/core/persistence/crud/analysis/performance.py b/packages/core/src/repowise/core/persistence/crud/analysis/performance.py
index 595d50585..f8a9dac9e 100644
--- a/packages/core/src/repowise/core/persistence/crud/analysis/performance.py
+++ b/packages/core/src/repowise/core/persistence/crud/analysis/performance.py
@@ -74,6 +74,8 @@ def opportunity_details(
return {
**({"plan": plan} if plan else {}),
"biomarker_types": list(opportunity.biomarker_types),
+ "intervention_kind": opportunity.intervention_kind,
+ "terminal_sinks": list(opportunity.terminal_sinks),
"shared_path_suffix": list(opportunity.shared_path_suffix),
"resource_fingerprints": list(opportunity.resource_fingerprints),
"reliable_entry_reachability": opportunity.reliable_entry_reachability,
@@ -84,6 +86,7 @@ def opportunity_details(
"rank_factors": dict(opportunity.rank_factors),
"why_ranked": [dict(entry) for entry in opportunity.why_ranked],
"fix_rationale": opportunity.fix.rationale if opportunity.fix else None,
+ "may_lead": opportunity.may_lead,
**({"fix_api": opportunity.fix.api} if opportunity.fix and opportunity.fix.api else {}),
"siblings": [dict(entry) for entry in opportunity.siblings],
}
@@ -137,7 +140,10 @@ def _summary_payload(
plans: dict[str, dict[str, Any]] | None = None,
) -> dict:
"""The compact current headline, written once and read by primary key."""
- from ....analysis.health.perf.opportunity_rank import NON_LEADING_MARKERS
+ from ....analysis.health.perf.opportunity_rank import (
+ default_queue_counts,
+ default_queue_exclusion,
+ )
counts: dict[str, int] = {}
contexts: dict[str, int] = {}
@@ -147,17 +153,18 @@ def _summary_payload(
contexts[item.execution_context] = contexts.get(item.execution_context, 0) + 1
key = item.boundary_kind or "none"
boundaries[key] = boundaries.get(key, 0) + 1
- # ``expected`` rows rank last and offer nothing to do, so they never lead; nor does a
- # marker whose measured precision is below the bar for leading.
+ # The lead is the head of the default queue, so it is production work with a
+ # strategy; never a marker whose measured precision is below the bar for leading.
lead = next(
(
o
for o in opportunities
- if o.actionability_state != "expected" and o.biomarker_type not in NON_LEADING_MARKERS
+ if default_queue_exclusion(o) is None and o.may_lead
),
None,
)
return {
+ "default_queue": default_queue_counts(opportunities),
"actionability": counts,
"context": contexts,
"boundary": boundaries,
diff --git a/packages/server/src/repowise/server/services/performance_health.py b/packages/server/src/repowise/server/services/performance_health.py
index 504298642..59118f9e1 100644
--- a/packages/server/src/repowise/server/services/performance_health.py
+++ b/packages/server/src/repowise/server/services/performance_health.py
@@ -25,6 +25,10 @@ from repowise.core.analysis.health.perf.opportunities import (
PERFORMANCE_MODEL_VERSION,
model_state,
)
+from repowise.core.analysis.health.perf.opportunity_rank import (
+ DEFAULT_QUEUE_STATES,
+ NON_LEADING_MARKERS,
+)
from repowise.core.analysis.health.rows import detail_map
from repowise.core.persistence.crud import (
get_performance_opportunity,
@@ -69,8 +73,9 @@ _CONFIDENCES = ("high", "medium", "low")
_ACTIONABILITIES = ("plan_ready", "advisory", "investigate", "expected")
_BOUNDARIES = ("db", "network", "filesystem", "subprocess", "lock", "none")
-_DEFAULT_ACTIONABILITIES = frozenset({"plan_ready", "advisory", "investigate"})
-"""``expected`` rows are true but offer nothing to change, so they are asked for, not queued."""
+_DEFAULT_ACTIONABILITIES = DEFAULT_QUEUE_STATES
+"""``expected`` rows offer nothing to change and ``investigate`` rows no strategy to apply,
+so both are asked for, not queued. The summary's ``default_queue`` counts each one left out."""
_PLAN_REASONS = {
"available": "A stored performance plan addresses this exact opportunity.",
@@ -121,7 +126,7 @@ class PerformanceQuery:
@property
def actionabilities(self) -> frozenset[str]:
- """The set the queue is filtered to: one explicit state, or the default three."""
+ """The set the queue is filtered to: one explicit state, or the default queue states (plan_ready, advisory)."""
if self.actionability is None:
return _DEFAULT_ACTIONABILITIES
return frozenset({self.actionability})
@@ -460,6 +465,7 @@ class PerformanceHealthService:
"execution_context": row.execution_context,
"terminal_sink": row.terminal_sink,
"intervention_symbol": row.intervention_symbol,
+ "intervention_kind": details.get("intervention_kind"),
"file_path": row.file_path,
"affected_call_sites_total": row.affected_call_sites_total,
"affected_files_total": row.affected_files_total,
@@ -469,6 +475,8 @@ class PerformanceHealthService:
"rank_score": row.rank_score,
"rank_position": row.rank_position,
"why_ranked": details.get("why_ranked", []),
+ # An older store has no per-group answer; its marker gives the old one.
+ "may_lead": details.get("may_lead", row.biomarker_type not in NON_LEADING_MARKERS),
"plan_id": link.row_id,
"plan_reference": link.public_id,
"plan_status": link.state,
@@ -479,6 +487,7 @@ class PerformanceHealthService:
fix_strategy = row.fix_strategy
return {
**payload,
+ "terminal_sinks": details.get("terminal_sinks", []),
"shared_path_suffix": details.get("shared_path_suffix", []),
"resource_fingerprints": details.get("resource_fingerprints", []),
"reliable_entry_reachability": details.get("reliable_entry_reachability"),
@@ -558,6 +567,7 @@ def _summary_of(row: Any) -> dict[str, Any]:
"context": payload.get("context", {}),
"boundary": payload.get("boundary", {}),
"with_plan_total": payload.get("with_plan_total", 0),
+ **({"default_queue": payload["default_queue"]} if "default_queue" in payload else {}),
**(
{"refresh_required": True, "detail": "Run repowise update to rescore."}
if stale
diff --git a/packages/types/src/fix-first.ts b/packages/types/src/fix-first.ts
index 0cac4abbf..a23e9bf42 100644
--- a/packages/types/src/fix-first.ts
+++ b/packages/types/src/fix-first.ts
@@ -25,8 +25,10 @@ export type FixFactBasis = "measured" | "inferred" | "unknown";
export type FixExclusion =
| "test"
| "tooling"
+ | "unknown"
| "generated"
| "expected"
+ | "no_strategy"
| "no_plan"
| "below_min_worth"
| "history_only";
diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts
index 721e3119b..f7f17e3d6 100644
--- a/packages/types/src/health.ts
+++ b/packages/types/src/health.ts
@@ -445,9 +445,16 @@ export interface PerformanceOpportunity {
biomarker_types: string[];
boundary_kind: C4IoKind | null;
execution_context: PerformanceExecutionContext;
+ /** The one sink every observation reaches, else null; see `terminal_sinks`. */
terminal_sink: string | null;
+ /** Every sink the intervention's observations reach. Absent on an older store. */
+ terminal_sinks?: string[];
shared_path_suffix: string[];
+ /** Where to edit. Named on every row from model 3 (`path::__module__` for
+ * top-level code); null only on an older store. */
intervention_symbol: string | null;
+ /** The loop's function, a helper every caller shares, or top-level code. */
+ intervention_kind?: "function" | "shared_helper" | "module";
/** The file holding the symbol worth editing. */
file_path: string;
resource_fingerprints: string[];
@@ -473,6 +480,9 @@ export interface PerformanceOpportunity {
rank_factors: Record<string, number>;
why_ranked: PerformanceWhyRanked[];
fix: PerformanceOpportunityFix | null;
+ /** Whether this cause may lead the dashboard. False for a marker below the
+ * leading bar (lazy loads outside Django). Absent on an older store. */
+ may_lead?: boolean;
/** Exact stored match. Never inferred from file, marker, or rank. */
plan_id: string | null;
plan_status: PerformancePlanStatus;
@@ -574,6 +584,11 @@ export type PerformanceOpportunityQuery = {
offset?: number;
};
+export interface PerformanceDefaultQueue {
+ total: number;
+ excluded: Record<"test" | "tooling" | "unknown" | "expected" | "no_strategy", number>;
+}
+
export interface PerformanceOpportunitySummary {
/** `current` once materialized, `stale_model` after a model bump, or
* `unavailable` when this index has not been analyzed yet. */
@@ -592,6 +607,9 @@ export interface PerformanceOpportunitySummary {
context?: Partial<Record<PerformanceExecutionContext, number>>;
boundary?: Record<string, number>;
with_plan_total: number;
+ /** The queue a caller gets with no filter (production work with a strategy),
+ * and how many causes it leaves out per reason. Absent on an older store. */
+ default_queue?: PerformanceDefaultQueue;
/** Why the queue is not current, when it is not. */
reason?: string;
detail?: string;
diff --git a/tests/fixtures/perf_corpus/golden_opportunities.json b/tests/fixtures/perf_corpus/golden_opportunities.json
index 958b0e656..136dd556a 100644
--- a/tests/fixtures/perf_corpus/golden_opportunities.json
+++ b/tests/fixtures/perf_corpus/golden_opportunities.json
@@ -1,160 +1,236 @@
{
"opportunities": [
{
- "actionability_reason": "proven_strategy",
- "actionability_state": "plan_ready",
- "affected_call_sites_total": 1,
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 3,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "nested_loop_with_io",
"biomarker_types": [
- "io_in_loop"
+ "io_in_loop",
+ "nested_loop_with_io"
],
"boundary_kind": "db",
"confidence": "high",
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/owners.py",
- "finding_id": "finding_c7e0cff49d2e4944af6c",
- "function_name": "load_owners",
- "line_end": 22,
- "line_start": 20,
+ "file_path": "src/app/jobs.py",
+ "finding_id": "finding_0bbb5976a0db9ce5c38b",
+ "function_name": "drain",
+ "line_end": 40,
+ "line_start": 40,
"path": [],
"provenance": "direct",
- "reason": "batch_form_equivalent: io_in_loop at src/app/owners.py:20 repeats work per iteration."
+ "reason": "one_loop_mixed_shapes: io_in_loop at src/app/jobs.py:40 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "nested_loop_with_io",
+ "file_path": "src/app/jobs.py",
+ "finding_id": "finding_4920d985db7b900b6d9a",
+ "function_name": "drain",
+ "line_end": 42,
+ "line_start": 42,
+ "path": [],
+ "provenance": "direct",
+ "reason": "one_loop_mixed_shapes: nested_loop_with_io at src/app/jobs.py:42 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/jobs.py",
+ "finding_id": "finding_2789a72f7acb87f86cdc",
+ "function_name": "drain",
+ "line_end": 44,
+ "line_start": 44,
+ "path": [
+ "src/app/jobs.py::drain",
+ "src/app/db.py::save"
+ ],
+ "provenance": "call-site",
+ "reason": "one_loop_mixed_shapes: io_in_loop at src/app/jobs.py:44 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "high",
- "amplification": "per_iteration",
+ "actionability_confidence": "medium",
+ "amplification": "quadratic",
"change_risk": "contained",
- "exposure": "unknown",
- "leverage": "isolated",
- "loop_magnitude": "grows_with_data"
+ "exposure": "entry_reachable",
+ "leverage": "local",
+ "loop_magnitude": "unknown"
},
"fix": {
- "api": ".in_(\"repo_id\", keys)",
- "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) covers the same rows, and nothing else in the loop can observe the difference.",
- "safety": "proven",
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": null,
- "observations_total": 1,
- "opportunity_id": "perf3_e1734c647c3b26b6dfc4",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/jobs.py::drain",
+ "may_lead": true,
+ "observations_total": 3,
+ "opportunity_id": "perf3_d41b04897cfde2a9eed6",
"performance_model_version": 3,
- "prerequisites": [],
- "provenance": "direct",
+ "prerequisites": [
+ "batch_api_contract",
+ "result_equivalence"
+ ],
+ "provenance": "call-site",
"rank_factors": {
- "affected_call_sites": 2,
+ "affected_call_sites": 4,
"boundary_kind": 4,
- "entry_reachability": 0,
+ "entry_reachability": 3,
"execution_context": 3,
- "loop_magnitude": 2,
- "multiplier_shape": 4,
+ "loop_magnitude": 1,
+ "multiplier_shape": 6,
"provenance": 3
},
- "rank_score": 18,
- "reliable_entry_reachability": null,
+ "rank_score": 24,
+ "reliable_entry_reachability": true,
"resource_fingerprints": [],
- "shared_path_suffix": [],
+ "shared_path_suffix": [
+ "src/app/jobs.py::drain",
+ "src/app/db.py::save"
+ ],
"siblings": [],
- "terminal_sink": null,
+ "terminal_sink": "src/app/db.py::save",
+ "terminal_sinks": [
+ "src/app/db.py::save"
+ ],
"why_ranked": [
{
- "factor": "boundary_kind",
- "points": 4,
- "value": "db"
+ "factor": "multiplier_shape",
+ "points": 6,
+ "value": "nested_loop_with_io"
},
{
- "factor": "multiplier_shape",
+ "factor": "affected_call_sites",
"points": 4,
- "value": "io_in_loop"
+ "value": 3
},
{
- "factor": "execution_context",
- "points": 3,
- "value": "production"
+ "factor": "boundary_kind",
+ "points": 4,
+ "value": "db"
}
]
},
{
- "actionability_reason": "proven_strategy",
- "actionability_state": "plan_ready",
- "affected_call_sites_total": 1,
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 3,
"affected_files_total": 1,
- "biomarker_type": "serial_await_in_loop",
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "serial_await_in_loop"
+ "io_in_loop"
],
- "boundary_kind": "network",
+ "boundary_kind": "db",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "serial_await_in_loop",
- "file_path": "src/app/fetch.py",
- "finding_id": "finding_f8f8bae754849200b18a",
- "function_name": "fetch_each",
- "line_end": 42,
- "line_start": 40,
- "path": [],
- "provenance": "direct",
- "reason": "bounded_fan_out: serial_await_in_loop at src/app/fetch.py:40 repeats work per iteration."
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/migrate.py",
+ "finding_id": "finding_99e6a402db90eaf9544e",
+ "function_name": "apply",
+ "line_end": 587,
+ "line_start": 587,
+ "path": [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_move"
+ ],
+ "provenance": "call-site",
+ "reason": "one_loop_many_sinks: io_in_loop at src/app/migrate.py:587 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/migrate.py",
+ "finding_id": "finding_9b7378f919d4c62c71b6",
+ "function_name": "apply",
+ "line_end": 590,
+ "line_start": 590,
+ "path": [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_fold_one"
+ ],
+ "provenance": "call-site",
+ "reason": "one_loop_many_sinks: io_in_loop at src/app/migrate.py:590 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/migrate.py",
+ "finding_id": "finding_bcbd5e05d77811ea7695",
+ "function_name": "apply",
+ "line_end": 591,
+ "line_start": 591,
+ "path": [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_write_alias"
+ ],
+ "provenance": "call-site",
+ "reason": "one_loop_many_sinks: io_in_loop at src/app/migrate.py:591 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "high",
+ "actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "unknown",
- "leverage": "isolated",
+ "exposure": "entry_reachable",
+ "leverage": "local",
"loop_magnitude": "unknown"
},
"fix": {
- "api": "self._sem",
- "rationale": "Iterations are independent and each await already runs under self._sem.",
- "safety": "proven",
- "strategy": "parallelize_independent_awaits"
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": null,
- "observations_total": 1,
- "opportunity_id": "perf3_cc802c5285ea0c31b02a",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/migrate.py::apply",
+ "may_lead": true,
+ "observations_total": 3,
+ "opportunity_id": "perf3_b03c60fe41fa017130c6",
"performance_model_version": 3,
- "prerequisites": [],
- "provenance": "direct",
+ "prerequisites": [
+ "batch_api_contract",
+ "result_equivalence"
+ ],
+ "provenance": "call-site",
"rank_factors": {
- "affected_call_sites": 2,
+ "affected_call_sites": 4,
"boundary_kind": 4,
- "entry_reachability": 0,
+ "entry_reachability": 3,
"execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 17,
- "reliable_entry_reachability": null,
+ "rank_score": 22,
+ "reliable_entry_reachability": true,
"resource_fingerprints": [],
"shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [
+ "src/app/migrate.py::_fold_one",
+ "src/app/migrate.py::_move",
+ "src/app/migrate.py::_write_alias"
+ ],
"why_ranked": [
{
- "factor": "boundary_kind",
+ "factor": "affected_call_sites",
"points": 4,
- "value": "network"
+ "value": 3
},
{
- "factor": "multiplier_shape",
+ "factor": "boundary_kind",
"points": 4,
- "value": "serial_await_in_loop"
+ "value": "db"
},
{
- "factor": "execution_context",
- "points": 3,
- "value": "production"
+ "factor": "multiplier_shape",
+ "points": 4,
+ "value": "io_in_loop"
}
]
},
@@ -216,9 +292,11 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
+ "intervention_kind": "shared_helper",
"intervention_symbol": "src/app/entry.py::_hit",
+ "may_lead": true,
"observations_total": 2,
- "opportunity_id": "perf3_0673587e7abbea99fc0b",
+ "opportunity_id": "perf3_6690af4c5e3f269c266e",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
@@ -243,6 +321,9 @@
],
"siblings": [],
"terminal_sink": "src/app/db.py::reach_sink",
+ "terminal_sinks": [
+ "src/app/db.py::reach_sink"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -319,9 +400,11 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
+ "intervention_kind": "shared_helper",
"intervention_symbol": "src/app/repo.py::fetch_page",
+ "may_lead": true,
"observations_total": 2,
- "opportunity_id": "perf3_89348be6c2ba0311a0e8",
+ "opportunity_id": "perf3_8456a319d03ac90c6041",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
@@ -346,6 +429,9 @@
],
"siblings": [],
"terminal_sink": "src/app/db.py::execute",
+ "terminal_sinks": [
+ "src/app/db.py::execute"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -423,9 +509,11 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
+ "intervention_kind": "shared_helper",
"intervention_symbol": "src/app/reindex.py::_write",
+ "may_lead": true,
"observations_total": 2,
- "opportunity_id": "perf3_3d62fcebb00bdf408f2c",
+ "opportunity_id": "perf3_a123c4c38fdb1cabaa6a",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
@@ -450,6 +538,9 @@
],
"siblings": [],
"terminal_sink": "src/app/db.py::upsert",
+ "terminal_sinks": [
+ "src/app/db.py::upsert"
+ ],
"why_ranked": [
{
"factor": "multiplier_shape",
@@ -469,70 +560,67 @@
]
},
{
- "actionability_reason": "strategy_requires_validation",
- "actionability_state": "advisory",
+ "actionability_reason": "no_supported_strategy",
+ "actionability_state": "investigate",
"affected_call_sites_total": 2,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "blocking_io_under_lock",
"biomarker_types": [
- "io_in_loop"
+ "blocking_io_under_lock"
],
"boundary_kind": "db",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/sync.py",
- "finding_id": "finding_3181306320c607f836ff",
- "function_name": "sync_one",
- "line_end": 72,
- "line_start": 70,
+ "biomarker_type": "blocking_io_under_lock",
+ "file_path": "src/app/pool.py",
+ "finding_id": "finding_2cca2a2e17c82f868f98",
+ "function_name": "reaper",
+ "line_end": 132,
+ "line_start": 130,
"path": [
- "src/app/sync.py::sync_one",
- "src/app/sync.py::_load",
- "src/app/db.py::query"
+ "src/app/pool.py::reaper",
+ "src/app/store.py::flush_all",
+ "src/app/store.py::flush"
],
"provenance": "call-site",
- "reason": "same_file_db_helper: io_in_loop at src/app/sync.py:70 repeats work per iteration."
+ "reason": "distinct_lock_owners: blocking_io_under_lock at src/app/pool.py:130 repeats work per iteration."
},
{
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/sync.py",
- "finding_id": "finding_77b2373b82e9257f6ee4",
- "function_name": "sync_all",
- "line_end": 73,
- "line_start": 71,
+ "biomarker_type": "blocking_io_under_lock",
+ "file_path": "src/app/pool.py",
+ "finding_id": "finding_401246625d2b912b7c5c",
+ "function_name": "writer",
+ "line_end": 132,
+ "line_start": 130,
"path": [
- "src/app/sync.py::sync_all",
- "src/app/sync.py::_load",
- "src/app/db.py::query"
+ "src/app/pool.py::writer",
+ "src/app/store.py::flush_all",
+ "src/app/store.py::flush"
],
"provenance": "call-site",
- "reason": "same_file_db_helper: io_in_loop at src/app/sync.py:71 repeats work per iteration."
+ "reason": "distinct_lock_owners: blocking_io_under_lock at src/app/pool.py:130 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "medium",
+ "actionability_confidence": "low",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
"leverage": "local",
"loop_magnitude": "unknown"
},
- "fix": {
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
- "safety": "advisory",
- "strategy": "batch_or_prefetch_io"
- },
- "intervention_symbol": "src/app/sync.py::_load",
+ "fix": null,
+ "intervention_kind": "shared_helper",
+ "intervention_symbol": "src/app/store.py::flush_all",
+ "may_lead": true,
"observations_total": 2,
- "opportunity_id": "perf3_af29fc10103a555c8652",
+ "opportunity_id": "perf3_d3dace3672249fc9bd03",
"performance_model_version": 3,
"prerequisites": [
- "batch_api_contract",
- "result_equivalence"
+ "single_lock_owner"
],
"provenance": "call-site",
"rank_factors": {
@@ -541,28 +629,31 @@
"entry_reachability": 0,
"execution_context": 3,
"loop_magnitude": 1,
- "multiplier_shape": 4,
+ "multiplier_shape": 5,
"provenance": 3
},
- "rank_score": 18,
+ "rank_score": 19,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
"shared_path_suffix": [
- "src/app/sync.py::_load",
- "src/app/db.py::query"
+ "src/app/store.py::flush_all",
+ "src/app/store.py::flush"
],
"siblings": [],
- "terminal_sink": "src/app/db.py::query",
+ "terminal_sink": "src/app/store.py::flush",
+ "terminal_sinks": [
+ "src/app/store.py::flush"
+ ],
"why_ranked": [
{
- "factor": "boundary_kind",
- "points": 4,
- "value": "db"
+ "factor": "multiplier_shape",
+ "points": 5,
+ "value": "blocking_io_under_lock"
},
{
- "factor": "multiplier_shape",
+ "factor": "boundary_kind",
"points": 4,
- "value": "io_in_loop"
+ "value": "db"
},
{
"factor": "affected_call_sites",
@@ -572,11 +663,201 @@
]
},
{
- "actionability_reason": "strategy_requires_validation",
- "actionability_state": "advisory",
+ "actionability_reason": "proven_strategy",
+ "actionability_state": "plan_ready",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "blocking_io_under_lock",
+ "biomarker_type": "io_in_loop",
+ "biomarker_types": [
+ "io_in_loop"
+ ],
+ "boundary_kind": "db",
+ "confidence": "high",
+ "evidence": [
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/owners.py",
+ "finding_id": "finding_c7e0cff49d2e4944af6c",
+ "function_name": "load_owners",
+ "line_end": 22,
+ "line_start": 20,
+ "path": [],
+ "provenance": "direct",
+ "reason": "batch_form_equivalent: io_in_loop at src/app/owners.py:20 repeats work per iteration."
+ }
+ ],
+ "evidence_truncated": false,
+ "execution_context": "production",
+ "facets": {
+ "actionability_confidence": "high",
+ "amplification": "per_iteration",
+ "change_risk": "contained",
+ "exposure": "unknown",
+ "leverage": "isolated",
+ "loop_magnitude": "grows_with_data"
+ },
+ "fix": {
+ "api": ".in_(\"repo_id\", keys)",
+ "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) covers the same rows, and nothing else in the loop can observe the difference.",
+ "safety": "proven",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/owners.py::load_owners",
+ "may_lead": true,
+ "observations_total": 1,
+ "opportunity_id": "perf3_83d258547498bed60226",
+ "performance_model_version": 3,
+ "prerequisites": [],
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 2,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 18,
+ "reliable_entry_reachability": null,
+ "resource_fingerprints": [],
+ "shared_path_suffix": [],
+ "siblings": [],
+ "terminal_sink": null,
+ "terminal_sinks": [],
+ "why_ranked": [
+ {
+ "factor": "boundary_kind",
+ "points": 4,
+ "value": "db"
+ },
+ {
+ "factor": "multiplier_shape",
+ "points": 4,
+ "value": "io_in_loop"
+ },
+ {
+ "factor": "execution_context",
+ "points": 3,
+ "value": "production"
+ }
+ ]
+ },
+ {
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 2,
+ "affected_files_total": 1,
+ "biomarker_type": "io_in_loop",
+ "biomarker_types": [
+ "io_in_loop"
+ ],
+ "boundary_kind": "db",
+ "confidence": "high",
+ "evidence": [
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/sync.py",
+ "finding_id": "finding_3181306320c607f836ff",
+ "function_name": "sync_one",
+ "line_end": 72,
+ "line_start": 70,
+ "path": [
+ "src/app/sync.py::sync_one",
+ "src/app/sync.py::_load",
+ "src/app/db.py::query"
+ ],
+ "provenance": "call-site",
+ "reason": "same_file_db_helper: io_in_loop at src/app/sync.py:70 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/sync.py",
+ "finding_id": "finding_77b2373b82e9257f6ee4",
+ "function_name": "sync_all",
+ "line_end": 73,
+ "line_start": 71,
+ "path": [
+ "src/app/sync.py::sync_all",
+ "src/app/sync.py::_load",
+ "src/app/db.py::query"
+ ],
+ "provenance": "call-site",
+ "reason": "same_file_db_helper: io_in_loop at src/app/sync.py:71 repeats work per iteration."
+ }
+ ],
+ "evidence_truncated": false,
+ "execution_context": "production",
+ "facets": {
+ "actionability_confidence": "medium",
+ "amplification": "per_iteration",
+ "change_risk": "contained",
+ "exposure": "unknown",
+ "leverage": "local",
+ "loop_magnitude": "unknown"
+ },
+ "fix": {
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "shared_helper",
+ "intervention_symbol": "src/app/sync.py::_load",
+ "may_lead": true,
+ "observations_total": 2,
+ "opportunity_id": "perf3_8845956c083937dad1ec",
+ "performance_model_version": 3,
+ "prerequisites": [
+ "batch_api_contract",
+ "result_equivalence"
+ ],
+ "provenance": "call-site",
+ "rank_factors": {
+ "affected_call_sites": 3,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 18,
+ "reliable_entry_reachability": null,
+ "resource_fingerprints": [],
+ "shared_path_suffix": [
+ "src/app/sync.py::_load",
+ "src/app/db.py::query"
+ ],
+ "siblings": [],
+ "terminal_sink": "src/app/db.py::query",
+ "terminal_sinks": [
+ "src/app/db.py::query"
+ ],
+ "why_ranked": [
+ {
+ "factor": "boundary_kind",
+ "points": 4,
+ "value": "db"
+ },
+ {
+ "factor": "multiplier_shape",
+ "points": 4,
+ "value": "io_in_loop"
+ },
+ {
+ "factor": "affected_call_sites",
+ "points": 3,
+ "value": 2
+ }
+ ]
+ },
+ {
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 1,
+ "affected_files_total": 1,
+ "biomarker_type": "blocking_io_under_lock",
"biomarker_types": [
"blocking_io_under_lock"
],
@@ -613,9 +894,11 @@
"safety": "advisory",
"strategy": "shrink_lock_scope"
},
+ "intervention_kind": "function",
"intervention_symbol": "src/app/cache.py::refresh",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_9dfe577bc9c8b799355e",
+ "opportunity_id": "perf3_600194da489eff07f26a",
"performance_model_version": 3,
"prerequisites": [
"shared_state_ordering"
@@ -639,6 +922,9 @@
],
"siblings": [],
"terminal_sink": "src/app/db.py::write",
+ "terminal_sinks": [
+ "src/app/db.py::write"
+ ],
"why_ranked": [
{
"factor": "multiplier_shape",
@@ -658,8 +944,8 @@
]
},
{
- "actionability_reason": "strategy_requires_validation",
- "actionability_state": "advisory",
+ "actionability_reason": "proven_strategy",
+ "actionability_state": "plan_ready",
"affected_call_sites_total": 1,
"affected_files_total": 1,
"biomarker_type": "serial_await_in_loop",
@@ -671,20 +957,20 @@
"evidence": [
{
"biomarker_type": "serial_await_in_loop",
- "file_path": "src/app/fanout.py",
- "finding_id": "finding_2fd4157a8e2822d774f3",
- "function_name": "gather_all",
- "line_end": 92,
- "line_start": 90,
+ "file_path": "src/app/fetch.py",
+ "finding_id": "finding_f8f8bae754849200b18a",
+ "function_name": "fetch_each",
+ "line_end": 42,
+ "line_start": 40,
"path": [],
"provenance": "direct",
- "reason": "async_serial_awaits: serial_await_in_loop at src/app/fanout.py:90 repeats work per iteration."
+ "reason": "bounded_fan_out: serial_await_in_loop at src/app/fetch.py:40 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "medium",
+ "actionability_confidence": "high",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
@@ -692,17 +978,18 @@
"loop_magnitude": "unknown"
},
"fix": {
- "rationale": "Iteration independence is proven; the concurrency the fan-out would create is not bounded by anything this group can see.",
- "safety": "advisory",
+ "api": "self._sem",
+ "rationale": "Iterations are independent and each await already runs under self._sem.",
+ "safety": "proven",
"strategy": "parallelize_independent_awaits"
},
- "intervention_symbol": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/fetch.py::fetch_each",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_182b2a7c053167959285",
+ "opportunity_id": "perf3_877f87ea6dac79fd92fc",
"performance_model_version": 3,
- "prerequisites": [
- "bounded_concurrency"
- ],
+ "prerequisites": [],
"provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
@@ -719,6 +1006,7 @@
"shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -751,17 +1039,14 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/billing.py",
- "finding_id": "finding_afbcfc0c666017b74c22",
- "function_name": "handle",
- "line_end": 13,
- "line_start": 11,
- "path": [
- "src/app/billing.py::handle",
- "src/app/db.py::get_session"
- ],
- "provenance": "call-site",
- "reason": "generic_infra_sink: io_in_loop at src/app/billing.py:11 repeats work per iteration."
+ "file_path": "src/app/commits.py",
+ "finding_id": "finding_67809361ebc8f5a864d8",
+ "function_name": "first_commit_each",
+ "line_end": 32,
+ "line_start": 30,
+ "path": [],
+ "provenance": "direct",
+ "reason": "batch_form_limited: io_in_loop at src/app/commits.py:30 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -770,24 +1055,26 @@
"actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "not_entry_reachable",
+ "exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
"fix": {
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "api": ".in_(\"repo_id\", keys)",
+ "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) is the bulk form; the per-key call limits, orders or shares the loop with other I/O.",
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": "src/app/billing.py::handle",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/commits.py::first_commit_each",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_3d4056f8405c9313d004",
+ "opportunity_id": "perf3_2a6f52da25a5ede16116",
"performance_model_version": 3,
"prerequisites": [
- "batch_api_contract",
"result_equivalence"
],
- "provenance": "call-site",
+ "provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
@@ -798,14 +1085,12 @@
"provenance": 3
},
"rank_score": 17,
- "reliable_entry_reachability": false,
+ "reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [
- "src/app/billing.py::handle",
- "src/app/db.py::get_session"
- ],
+ "shared_path_suffix": [],
"siblings": [],
- "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -829,26 +1114,23 @@
"actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "serial_await_in_loop",
"biomarker_types": [
- "io_in_loop"
+ "serial_await_in_loop"
],
- "boundary_kind": "db",
+ "boundary_kind": "network",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/orders.py",
- "finding_id": "finding_8277702ee7a1de73ddf9",
- "function_name": "handle",
- "line_end": 12,
- "line_start": 10,
- "path": [
- "src/app/orders.py::handle",
- "src/app/db.py::get_session"
- ],
- "provenance": "call-site",
- "reason": "generic_infra_sink: io_in_loop at src/app/orders.py:10 repeats work per iteration."
+ "biomarker_type": "serial_await_in_loop",
+ "file_path": "src/app/fanout.py",
+ "finding_id": "finding_2fd4157a8e2822d774f3",
+ "function_name": "gather_all",
+ "line_end": 92,
+ "line_start": 90,
+ "path": [],
+ "provenance": "direct",
+ "reason": "async_serial_awaits: serial_await_in_loop at src/app/fanout.py:90 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -857,24 +1139,25 @@
"actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "not_entry_reachable",
+ "exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
"fix": {
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "rationale": "Iteration independence is proven; the concurrency the fan-out would create is not bounded by anything this group can see.",
"safety": "advisory",
- "strategy": "batch_or_prefetch_io"
+ "strategy": "parallelize_independent_awaits"
},
- "intervention_symbol": "src/app/orders.py::handle",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/fanout.py::gather_all",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_5abe869788cb2cebf6cf",
+ "opportunity_id": "perf3_445b62193f1ff0db3cb4",
"performance_model_version": 3,
"prerequisites": [
- "batch_api_contract",
- "result_equivalence"
+ "bounded_concurrency"
],
- "provenance": "call-site",
+ "provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
@@ -885,24 +1168,22 @@
"provenance": 3
},
"rank_score": 17,
- "reliable_entry_reachability": false,
+ "reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [
- "src/app/orders.py::handle",
- "src/app/db.py::get_session"
- ],
+ "shared_path_suffix": [],
"siblings": [],
- "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "db"
+ "value": "network"
},
{
"factor": "multiplier_shape",
"points": 4,
- "value": "io_in_loop"
+ "value": "serial_await_in_loop"
},
{
"factor": "execution_context",
@@ -925,17 +1206,17 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/reports.py",
- "finding_id": "finding_8e1d9d853534ecd57392",
- "function_name": "handle",
- "line_end": 14,
- "line_start": 12,
+ "file_path": "src/app/job.py",
+ "finding_id": "finding_a4ca438d1238f8956526",
+ "function_name": "run",
+ "line_end": 202,
+ "line_start": 200,
"path": [
- "src/app/reports.py::handle",
+ "src/app/job.py::run",
"src/app/db.py::get_session"
],
"provenance": "call-site",
- "reason": "generic_infra_sink: io_in_loop at src/app/reports.py:12 repeats work per iteration."
+ "reason": "context_split: io_in_loop at src/app/job.py:200 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -944,7 +1225,7 @@
"actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "not_entry_reachable",
+ "exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
@@ -953,9 +1234,11 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": "src/app/reports.py::handle",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/job.py::run",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_7d6b729c3f43753626f2",
+ "opportunity_id": "perf3_4e3feb071c73aa51a6a4",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
@@ -972,14 +1255,17 @@
"provenance": 3
},
"rank_score": 17,
- "reliable_entry_reachability": false,
+ "reliable_entry_reachability": null,
"resource_fingerprints": [],
"shared_path_suffix": [
- "src/app/reports.py::handle",
+ "src/app/job.py::run",
"src/app/db.py::get_session"
],
"siblings": [],
"terminal_sink": "src/app/db.py::get_session",
+ "terminal_sinks": [
+ "src/app/db.py::get_session"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -1012,17 +1298,16 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/job.py",
- "finding_id": "finding_a4ca438d1238f8956526",
+ "file_path": "src/app/lone.py",
+ "finding_id": "finding_9cfd6311dc82a0049c6a",
"function_name": "run",
- "line_end": 202,
- "line_start": 200,
+ "line_end": 11,
+ "line_start": 9,
"path": [
- "src/app/job.py::run",
- "src/app/db.py::get_session"
+ "src/app/db.py::only_sink"
],
"provenance": "call-site",
- "reason": "context_split: io_in_loop at src/app/job.py:200 repeats work per iteration."
+ "reason": "sink_without_caller: io_in_loop at src/app/lone.py:9 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -1040,9 +1325,11 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": "src/app/job.py::run",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/lone.py::run",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_811bb33b8d8f9e744638",
+ "opportunity_id": "perf3_919d91fe15e89966b389",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
@@ -1062,11 +1349,13 @@
"reliable_entry_reachability": null,
"resource_fingerprints": [],
"shared_path_suffix": [
- "src/app/job.py::run",
- "src/app/db.py::get_session"
+ "src/app/db.py::only_sink"
],
"siblings": [],
- "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sink": "src/app/db.py::only_sink",
+ "terminal_sinks": [
+ "src/app/db.py::only_sink"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -1090,23 +1379,23 @@
"actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "lazy_load_in_loop",
"biomarker_types": [
- "io_in_loop"
+ "lazy_load_in_loop"
],
"boundary_kind": "db",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/commits.py",
- "finding_id": "finding_67809361ebc8f5a864d8",
- "function_name": "first_commit_each",
- "line_end": 32,
- "line_start": 30,
+ "biomarker_type": "lazy_load_in_loop",
+ "file_path": "app/incidents/service.py",
+ "finding_id": "finding_b8a85cd0da954d3af1b7",
+ "function_name": "notify_owners",
+ "line_end": 50,
+ "line_start": 50,
"path": [],
"provenance": "direct",
- "reason": "batch_form_limited: io_in_loop at src/app/commits.py:30 repeats work per iteration."
+ "reason": "lazy_load_by_orm: lazy_load_in_loop at app/incidents/service.py:50 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -1120,17 +1409,18 @@
"loop_magnitude": "unknown"
},
"fix": {
- "api": ".in_(\"repo_id\", keys)",
- "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) is the bulk form; the per-key call limits, orders or shares the loop with other I/O.",
+ "rationale": "The relationship is declared lazy and the query that produced the rows does not load it; whether every iteration reaches the access, and whether another layer loads it first, is not proven.",
"safety": "advisory",
- "strategy": "batch_or_prefetch_io"
+ "strategy": "eager_load_relationship"
},
- "intervention_symbol": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "app/incidents/service.py::notify_owners",
+ "may_lead": false,
"observations_total": 1,
- "opportunity_id": "perf3_820a695aba4fe3a6496a",
+ "opportunity_id": "perf3_93a53323a7db0544017f",
"performance_model_version": 3,
"prerequisites": [
- "result_equivalence"
+ "relationship_not_loaded_elsewhere"
],
"provenance": "direct",
"rank_factors": {
@@ -1148,6 +1438,7 @@
"shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -1157,7 +1448,7 @@
{
"factor": "multiplier_shape",
"points": 4,
- "value": "io_in_loop"
+ "value": "lazy_load_in_loop"
},
{
"factor": "execution_context",
@@ -1171,25 +1462,23 @@
"actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "lazy_load_in_loop",
"biomarker_types": [
- "io_in_loop"
+ "lazy_load_in_loop"
],
"boundary_kind": "db",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/lone.py",
- "finding_id": "finding_9cfd6311dc82a0049c6a",
- "function_name": "run",
- "line_end": 11,
- "line_start": 9,
- "path": [
- "src/app/db.py::only_sink"
- ],
- "provenance": "call-site",
- "reason": "sink_without_caller: io_in_loop at src/app/lone.py:9 repeats work per iteration."
+ "biomarker_type": "lazy_load_in_loop",
+ "file_path": "app/issues/views.py",
+ "finding_id": "finding_c99dea746d7bfeb433cd",
+ "function_name": "issue_list",
+ "line_end": 30,
+ "line_start": 30,
+ "path": [],
+ "provenance": "direct",
+ "reason": "lazy_load_by_orm: lazy_load_in_loop at app/issues/views.py:30 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -1203,19 +1492,20 @@
"loop_magnitude": "unknown"
},
"fix": {
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "rationale": "The relationship is declared lazy and the query that produced the rows does not load it; whether every iteration reaches the access, and whether another layer loads it first, is not proven.",
"safety": "advisory",
- "strategy": "batch_or_prefetch_io"
+ "strategy": "eager_load_relationship"
},
- "intervention_symbol": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "app/issues/views.py::issue_list",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_f349f0c0ac6827ebfd86",
+ "opportunity_id": "perf3_942cceadc50a644175e4",
"performance_model_version": 3,
"prerequisites": [
- "batch_api_contract",
- "result_equivalence"
+ "relationship_not_loaded_elsewhere"
],
- "provenance": "call-site",
+ "provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
@@ -1228,11 +1518,10 @@
"rank_score": 17,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [
- "src/app/db.py::only_sink"
- ],
+ "shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -1242,7 +1531,7 @@
{
"factor": "multiplier_shape",
"points": 4,
- "value": "io_in_loop"
+ "value": "lazy_load_in_loop"
},
{
"factor": "execution_context",
@@ -1265,26 +1554,26 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "scripts/backfill.py",
- "finding_id": "finding_d8a564a824ecf8f12ecb",
- "function_name": "run",
- "line_end": 202,
- "line_start": 200,
+ "file_path": "src/app/orders.py",
+ "finding_id": "finding_8277702ee7a1de73ddf9",
+ "function_name": "handle",
+ "line_end": 12,
+ "line_start": 10,
"path": [
- "scripts/backfill.py::run",
+ "src/app/orders.py::handle",
"src/app/db.py::get_session"
],
"provenance": "call-site",
- "reason": "context_split: io_in_loop at scripts/backfill.py:200 repeats work per iteration."
+ "reason": "generic_infra_sink: io_in_loop at src/app/orders.py:10 repeats work per iteration."
}
],
"evidence_truncated": false,
- "execution_context": "tooling",
+ "execution_context": "production",
"facets": {
"actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "unknown",
+ "exposure": "not_entry_reachable",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
@@ -1293,9 +1582,11 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": "scripts/backfill.py::run",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/orders.py::handle",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_626e6b4848d036aede65",
+ "opportunity_id": "perf3_95567b0824b33141361d",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
@@ -1306,20 +1597,23 @@
"affected_call_sites": 2,
"boundary_kind": 4,
"entry_reachability": 0,
- "execution_context": 2,
+ "execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 16,
- "reliable_entry_reachability": null,
+ "rank_score": 17,
+ "reliable_entry_reachability": false,
"resource_fingerprints": [],
"shared_path_suffix": [
- "scripts/backfill.py::run",
+ "src/app/orders.py::handle",
"src/app/db.py::get_session"
],
"siblings": [],
"terminal_sink": "src/app/db.py::get_session",
+ "terminal_sinks": [
+ "src/app/db.py::get_session"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -1332,9 +1626,9 @@
"value": "io_in_loop"
},
{
- "factor": "provenance",
+ "factor": "execution_context",
"points": 3,
- "value": "call-site"
+ "value": "production"
}
]
},
@@ -1348,21 +1642,21 @@
"io_in_loop"
],
"boundary_kind": "db",
- "confidence": "medium",
+ "confidence": "high",
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/edge.py",
- "finding_id": "finding_323137fff890d9e629dc",
- "function_name": "run",
- "line_end": 232,
- "line_start": 230,
+ "file_path": "src/app/reports.py",
+ "finding_id": "finding_8e1d9d853534ecd57392",
+ "function_name": "handle",
+ "line_end": 14,
+ "line_start": 12,
"path": [
- "src/app/edge.py::run",
- "src/app/db.py::reliable_sink"
+ "src/app/reports.py::handle",
+ "src/app/db.py::get_session"
],
- "provenance": "reliable-edge",
- "reason": "provenance_mix: io_in_loop at src/app/edge.py:230 repeats work per iteration."
+ "provenance": "call-site",
+ "reason": "generic_infra_sink: io_in_loop at src/app/reports.py:12 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -1371,7 +1665,7 @@
"actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "unknown",
+ "exposure": "not_entry_reachable",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
@@ -1380,15 +1674,17 @@
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": "src/app/edge.py::run",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/reports.py::handle",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_cf3653d0149e79f7a1fb",
+ "opportunity_id": "perf3_a0ebb8db3cb33a2c555f",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
"result_equivalence"
],
- "provenance": "reliable-edge",
+ "provenance": "call-site",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
@@ -1396,17 +1692,20 @@
"execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
- "provenance": 2
+ "provenance": 3
},
- "rank_score": 16,
- "reliable_entry_reachability": null,
+ "rank_score": 17,
+ "reliable_entry_reachability": false,
"resource_fingerprints": [],
"shared_path_suffix": [
- "src/app/edge.py::run",
- "src/app/db.py::reliable_sink"
+ "src/app/reports.py::handle",
+ "src/app/db.py::get_session"
],
"siblings": [],
- "terminal_sink": "src/app/db.py::reliable_sink",
+ "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sinks": [
+ "src/app/db.py::get_session"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
@@ -1434,19 +1733,22 @@
"biomarker_types": [
"io_in_loop"
],
- "boundary_kind": "network",
+ "boundary_kind": "db",
"confidence": "high",
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/retry.py",
- "finding_id": "finding_0e8c0794491c7384f4c4",
- "function_name": "post_with_retry",
- "line_end": 52,
- "line_start": 50,
- "path": [],
- "provenance": "direct",
- "reason": "retry_loop: io_in_loop at src/app/retry.py:50 repeats work per iteration."
+ "file_path": "src/app/billing.py",
+ "finding_id": "finding_afbcfc0c666017b74c22",
+ "function_name": "handle",
+ "line_end": 13,
+ "line_start": 11,
+ "path": [
+ "src/app/billing.py::handle",
+ "src/app/db.py::get_session"
+ ],
+ "provenance": "call-site",
+ "reason": "generic_infra_sink: io_in_loop at src/app/billing.py:11 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -1455,44 +1757,52 @@
"actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
- "exposure": "unknown",
+ "exposure": "not_entry_reachable",
"leverage": "isolated",
- "loop_magnitude": "bounded"
+ "loop_magnitude": "unknown"
},
"fix": {
"rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
"safety": "advisory",
"strategy": "batch_or_prefetch_io"
},
- "intervention_symbol": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/billing.py::handle",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_dc58f1a585a816ec37e9",
+ "opportunity_id": "perf3_debc1e358c095e5fd0d8",
"performance_model_version": 3,
"prerequisites": [
"batch_api_contract",
"result_equivalence"
],
- "provenance": "direct",
+ "provenance": "call-site",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
"entry_reachability": 0,
"execution_context": 3,
- "loop_magnitude": 0,
+ "loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 16,
- "reliable_entry_reachability": null,
+ "rank_score": 17,
+ "reliable_entry_reachability": false,
"resource_fingerprints": [],
- "shared_path_suffix": [],
+ "shared_path_suffix": [
+ "src/app/billing.py::handle",
+ "src/app/db.py::get_session"
+ ],
"siblings": [],
- "terminal_sink": null,
+ "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sinks": [
+ "src/app/db.py::get_session"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "network"
+ "value": "db"
},
{
"factor": "multiplier_shape",
@@ -1507,117 +1817,106 @@
]
},
{
- "actionability_reason": "strategy_requires_validation",
- "actionability_state": "advisory",
+ "actionability_reason": "no_supported_strategy",
+ "actionability_state": "investigate",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "resource_construction_in_loop",
"biomarker_types": [
- "io_in_loop"
+ "resource_construction_in_loop"
],
- "boundary_kind": "db",
+ "boundary_kind": "network",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "io_in_loop",
- "file_path": "tests/test_job.py",
- "finding_id": "finding_e34ca4ba22d5f482348d",
- "function_name": "run",
- "line_end": 202,
- "line_start": 200,
- "path": [
- "tests/test_job.py::run",
- "src/app/db.py::get_session"
- ],
- "provenance": "call-site",
- "reason": "context_split: io_in_loop at tests/test_job.py:200 repeats work per iteration."
+ "biomarker_type": "resource_construction_in_loop",
+ "file_path": "src/app/clients.py",
+ "finding_id": "finding_b3099686f4d36c75f964",
+ "function_name": "each_varying",
+ "line_end": 182,
+ "line_start": 180,
+ "path": [],
+ "provenance": "direct",
+ "reason": "resource_construction: resource_construction_in_loop at src/app/clients.py:180 repeats work per iteration."
}
],
"evidence_truncated": false,
- "execution_context": "test",
+ "execution_context": "production",
"facets": {
- "actionability_confidence": "medium",
+ "actionability_confidence": "low",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": {
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
- "safety": "advisory",
- "strategy": "batch_or_prefetch_io"
- },
- "intervention_symbol": "tests/test_job.py::run",
+ "fix": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/clients.py::each_varying",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_b17b10884d21aeeb4df0",
+ "opportunity_id": "perf3_0bf2ff36ef95d9cf96f2",
"performance_model_version": 3,
"prerequisites": [
- "batch_api_contract",
- "result_equivalence"
+ "loop_invariant_construction_proof"
],
- "provenance": "call-site",
+ "provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
"entry_reachability": 0,
- "execution_context": 1,
+ "execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 15,
+ "rank_score": 17,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [
- "tests/test_job.py::run",
- "src/app/db.py::get_session"
- ],
+ "shared_path_suffix": [],
"siblings": [],
- "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "db"
+ "value": "network"
},
{
"factor": "multiplier_shape",
"points": 4,
- "value": "io_in_loop"
+ "value": "resource_construction_in_loop"
},
{
- "factor": "provenance",
+ "factor": "execution_context",
"points": 3,
- "value": "call-site"
+ "value": "production"
}
]
},
{
- "actionability_reason": "low_evidence_confidence",
- "actionability_state": "advisory",
+ "actionability_reason": "no_supported_strategy",
+ "actionability_state": "investigate",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "serial_await_in_loop",
"biomarker_types": [
- "io_in_loop"
+ "serial_await_in_loop"
],
- "boundary_kind": "db",
- "confidence": "low",
+ "boundary_kind": "network",
+ "confidence": "high",
"evidence": [
{
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/guess.py",
- "finding_id": "finding_e287cbc148e5a8ea8ca8",
- "function_name": "run",
- "line_end": 242,
- "line_start": 240,
- "path": [
- "src/app/guess.py::run",
- "src/app/db.py::guessed_sink"
- ],
- "provenance": "name-fallback",
- "reason": "provenance_mix: io_in_loop at src/app/guess.py:240 repeats work per iteration."
+ "biomarker_type": "serial_await_in_loop",
+ "file_path": "src/app/fanout.py",
+ "finding_id": "finding_6f5702e6e6af64656121",
+ "function_name": "gather_seq",
+ "line_end": 97,
+ "line_start": 95,
+ "path": [],
+ "provenance": "direct",
+ "reason": "async_serial_awaits: serial_await_in_loop at src/app/fanout.py:95 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -1630,21 +1929,17 @@
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": {
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
- "safety": "advisory",
- "strategy": "batch_or_prefetch_io"
- },
- "intervention_symbol": "src/app/guess.py::run",
+ "fix": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/fanout.py::gather_seq",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_a817f9001be1d323f8a2",
+ "opportunity_id": "perf3_350ba04f50fc0faf0d81",
"performance_model_version": 3,
"prerequisites": [
- "batch_api_contract",
- "result_equivalence",
- "reliable_call_path"
+ "loop_carried_dependence_proof"
],
- "provenance": "name-fallback",
+ "provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
@@ -1652,27 +1947,25 @@
"execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
- "provenance": 0
+ "provenance": 3
},
- "rank_score": 14,
+ "rank_score": 17,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [
- "src/app/guess.py::run",
- "src/app/db.py::guessed_sink"
- ],
+ "shared_path_suffix": [],
"siblings": [],
- "terminal_sink": "src/app/db.py::guessed_sink",
+ "terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "db"
+ "value": "network"
},
{
"factor": "multiplier_shape",
"points": 4,
- "value": "io_in_loop"
+ "value": "serial_await_in_loop"
},
{
"factor": "execution_context",
@@ -1682,383 +1975,444 @@
]
},
{
- "actionability_reason": "strategy_requires_validation",
- "actionability_state": "advisory",
+ "actionability_reason": "no_supported_strategy",
+ "actionability_state": "investigate",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "membership_test_against_list_in_loop",
+ "biomarker_type": "resource_construction_in_loop",
"biomarker_types": [
- "membership_test_against_list_in_loop"
+ "resource_construction_in_loop"
],
- "boundary_kind": null,
+ "boundary_kind": "network",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "membership_test_against_list_in_loop",
- "file_path": "src/app/filters.py",
- "finding_id": "finding_9fa77c322fa3d741a8c4",
- "function_name": "select",
- "line_end": 152,
- "line_start": 150,
+ "biomarker_type": "resource_construction_in_loop",
+ "file_path": "src/app/clients.py",
+ "finding_id": "finding_840a26ef5269b670f5a2",
+ "function_name": "each",
+ "line_end": 172,
+ "line_start": 170,
"path": [],
"provenance": "direct",
- "reason": "membership_scan: membership_test_against_list_in_loop at src/app/filters.py:150 repeats work per iteration."
+ "reason": "resource_construction: resource_construction_in_loop at src/app/clients.py:170 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "medium",
+ "actionability_confidence": "low",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": {
- "rationale": "The collection is proven list-backed; element hashability and ordering/identity use still require validation.",
- "safety": "advisory",
- "strategy": "replace_membership_collection"
- },
- "intervention_symbol": null,
+ "fix": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/clients.py::each",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_6b8f8be1ab10062f0a19",
+ "opportunity_id": "perf3_c6604021414ce017f289",
"performance_model_version": 3,
"prerequisites": [
- "element_hashability",
- "ordering_and_identity_use"
+ "loop_invariant_construction_proof"
],
"provenance": "direct",
"rank_factors": {
"affected_call_sites": 2,
- "boundary_kind": 0,
+ "boundary_kind": 4,
"entry_reachability": 0,
"execution_context": 3,
"loop_magnitude": 1,
- "multiplier_shape": 3,
+ "multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 12,
+ "rank_score": 17,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
"shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
- "factor": "execution_context",
- "points": 3,
- "value": "production"
+ "factor": "boundary_kind",
+ "points": 4,
+ "value": "network"
},
{
"factor": "multiplier_shape",
- "points": 3,
- "value": "membership_test_against_list_in_loop"
+ "points": 4,
+ "value": "resource_construction_in_loop"
},
{
- "factor": "provenance",
+ "factor": "execution_context",
"points": 3,
- "value": "direct"
+ "value": "production"
}
]
},
{
- "actionability_reason": "strategy_requires_validation",
- "actionability_state": "advisory",
- "affected_call_sites_total": 1,
- "affected_files_total": 1,
- "biomarker_type": "string_concat_in_loop",
+ "actionability_reason": "inherent_to_boundary",
+ "actionability_state": "expected",
+ "affected_call_sites_total": 4,
+ "affected_files_total": 4,
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "string_concat_in_loop"
+ "io_in_loop"
],
- "boundary_kind": null,
+ "boundary_kind": "filesystem",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "string_concat_in_loop",
- "file_path": "src/app/render.py",
- "finding_id": "finding_ffee3cf5c3bbf22b87ba",
- "function_name": "to_csv",
- "line_end": 162,
- "line_start": 160,
- "path": [],
- "provenance": "direct",
- "reason": "string_accumulation: string_concat_in_loop at src/app/render.py:160 repeats work per iteration."
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/formatter.py",
+ "finding_id": "finding_74b3cc4ea0afc2828ead",
+ "function_name": "run",
+ "line_end": 24,
+ "line_start": 22,
+ "path": [
+ "src/app/formatter.py::run",
+ "src/app/parse.py::_get_query",
+ "src/app/parse.py::_load_compiled_query"
+ ],
+ "provenance": "call-site",
+ "reason": "shared_dominator_fan_in: io_in_loop at src/app/formatter.py:22 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/lexer.py",
+ "finding_id": "finding_f1d7e9138afa40a0f1b7",
+ "function_name": "run",
+ "line_end": 22,
+ "line_start": 20,
+ "path": [
+ "src/app/lexer.py::run",
+ "src/app/parse.py::_get_query",
+ "src/app/parse.py::_load_compiled_query"
+ ],
+ "provenance": "call-site",
+ "reason": "shared_dominator_fan_in: io_in_loop at src/app/lexer.py:20 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/linter.py",
+ "finding_id": "finding_04801d753f6bc1eb8675",
+ "function_name": "run",
+ "line_end": 23,
+ "line_start": 21,
+ "path": [
+ "src/app/linter.py::run",
+ "src/app/parse.py::_get_query",
+ "src/app/parse.py::_load_compiled_query"
+ ],
+ "provenance": "call-site",
+ "reason": "shared_dominator_fan_in: io_in_loop at src/app/linter.py:21 repeats work per iteration."
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/resolver.py",
+ "finding_id": "finding_1bb5c282969f6d4c8f99",
+ "function_name": "run",
+ "line_end": 25,
+ "line_start": 23,
+ "path": [
+ "src/app/resolver.py::run",
+ "src/app/parse.py::_get_query",
+ "src/app/parse.py::_load_compiled_query"
+ ],
+ "provenance": "call-site",
+ "reason": "shared_dominator_fan_in: io_in_loop at src/app/resolver.py:23 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "medium",
+ "actionability_confidence": "low",
"amplification": "per_iteration",
- "change_risk": "contained",
+ "change_risk": "moderate",
"exposure": "unknown",
- "leverage": "isolated",
+ "leverage": "shared",
"loop_magnitude": "unknown"
},
- "fix": {
- "rationale": "Repeated string accumulation is proven; intermediate accumulator observations still require validation.",
- "safety": "advisory",
- "strategy": "buffer_string_accumulation"
- },
- "intervention_symbol": null,
- "observations_total": 1,
- "opportunity_id": "perf3_e82f5ad0e9c24fe3d1a1",
+ "fix": null,
+ "intervention_kind": "shared_helper",
+ "intervention_symbol": "src/app/parse.py::_get_query",
+ "may_lead": true,
+ "observations_total": 4,
+ "opportunity_id": "perf3_a20111da61b63349e305",
"performance_model_version": 3,
- "prerequisites": [
- "accumulator_not_observed"
- ],
- "provenance": "direct",
+ "prerequisites": [],
+ "provenance": "call-site",
"rank_factors": {
- "affected_call_sites": 2,
- "boundary_kind": 0,
+ "affected_call_sites": 4,
+ "boundary_kind": 2,
"entry_reachability": 0,
"execution_context": 3,
"loop_magnitude": 1,
- "multiplier_shape": 3,
+ "multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 12,
+ "rank_score": 17,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [],
+ "shared_path_suffix": [
+ "src/app/parse.py::_get_query",
+ "src/app/parse.py::_load_compiled_query"
+ ],
"siblings": [],
- "terminal_sink": null,
+ "terminal_sink": "src/app/parse.py::_load_compiled_query",
+ "terminal_sinks": [
+ "src/app/parse.py::_load_compiled_query"
+ ],
"why_ranked": [
{
- "factor": "execution_context",
- "points": 3,
- "value": "production"
+ "factor": "affected_call_sites",
+ "points": 4,
+ "value": 4
},
{
"factor": "multiplier_shape",
- "points": 3,
- "value": "string_concat_in_loop"
+ "points": 4,
+ "value": "io_in_loop"
},
{
- "factor": "provenance",
+ "factor": "execution_context",
"points": 3,
- "value": "direct"
+ "value": "production"
}
]
},
{
- "actionability_reason": "no_supported_strategy",
- "actionability_state": "investigate",
- "affected_call_sites_total": 2,
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "blocking_io_under_lock",
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "blocking_io_under_lock"
+ "io_in_loop"
],
- "boundary_kind": "db",
+ "boundary_kind": "network",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "blocking_io_under_lock",
- "file_path": "src/app/pool.py",
- "finding_id": "finding_2cca2a2e17c82f868f98",
- "function_name": "reaper",
- "line_end": 132,
- "line_start": 130,
- "path": [
- "src/app/pool.py::reaper",
- "src/app/store.py::flush_all",
- "src/app/store.py::flush"
- ],
- "provenance": "call-site",
- "reason": "distinct_lock_owners: blocking_io_under_lock at src/app/pool.py:130 repeats work per iteration."
- },
- {
- "biomarker_type": "blocking_io_under_lock",
- "file_path": "src/app/pool.py",
- "finding_id": "finding_401246625d2b912b7c5c",
- "function_name": "writer",
- "line_end": 132,
- "line_start": 130,
- "path": [
- "src/app/pool.py::writer",
- "src/app/store.py::flush_all",
- "src/app/store.py::flush"
- ],
- "provenance": "call-site",
- "reason": "distinct_lock_owners: blocking_io_under_lock at src/app/pool.py:130 repeats work per iteration."
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/retry.py",
+ "finding_id": "finding_0e8c0794491c7384f4c4",
+ "function_name": "post_with_retry",
+ "line_end": 52,
+ "line_start": 50,
+ "path": [],
+ "provenance": "direct",
+ "reason": "retry_loop: io_in_loop at src/app/retry.py:50 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "low",
+ "actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
- "leverage": "local",
- "loop_magnitude": "unknown"
+ "leverage": "isolated",
+ "loop_magnitude": "bounded"
},
- "fix": null,
- "intervention_symbol": "src/app/store.py::flush_all",
- "observations_total": 2,
- "opportunity_id": "perf3_bb39bb7c7b9f0b1fe7a1",
+ "fix": {
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/retry.py::post_with_retry",
+ "may_lead": true,
+ "observations_total": 1,
+ "opportunity_id": "perf3_bd36a05060a6d02a1245",
"performance_model_version": 3,
"prerequisites": [
- "single_lock_owner"
+ "batch_api_contract",
+ "result_equivalence"
],
- "provenance": "call-site",
+ "provenance": "direct",
"rank_factors": {
- "affected_call_sites": 3,
+ "affected_call_sites": 2,
"boundary_kind": 4,
"entry_reachability": 0,
"execution_context": 3,
- "loop_magnitude": 1,
- "multiplier_shape": 5,
+ "loop_magnitude": 0,
+ "multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 19,
+ "rank_score": 16,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [
- "src/app/store.py::flush_all",
- "src/app/store.py::flush"
- ],
+ "shared_path_suffix": [],
"siblings": [],
- "terminal_sink": "src/app/store.py::flush",
+ "terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
- "factor": "multiplier_shape",
- "points": 5,
- "value": "blocking_io_under_lock"
+ "factor": "boundary_kind",
+ "points": 4,
+ "value": "network"
},
{
- "factor": "boundary_kind",
+ "factor": "multiplier_shape",
"points": 4,
- "value": "db"
+ "value": "io_in_loop"
},
{
- "factor": "affected_call_sites",
+ "factor": "execution_context",
"points": 3,
- "value": 2
+ "value": "production"
}
]
},
{
- "actionability_reason": "no_supported_strategy",
- "actionability_state": "investigate",
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "resource_construction_in_loop",
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "resource_construction_in_loop"
+ "io_in_loop"
],
- "boundary_kind": "network",
+ "boundary_kind": "db",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "resource_construction_in_loop",
- "file_path": "src/app/clients.py",
- "finding_id": "finding_b3099686f4d36c75f964",
- "function_name": "each_varying",
- "line_end": 182,
- "line_start": 180,
- "path": [],
- "provenance": "direct",
- "reason": "resource_construction: resource_construction_in_loop at src/app/clients.py:180 repeats work per iteration."
+ "biomarker_type": "io_in_loop",
+ "file_path": "scripts/backfill.py",
+ "finding_id": "finding_d8a564a824ecf8f12ecb",
+ "function_name": "run",
+ "line_end": 202,
+ "line_start": 200,
+ "path": [
+ "scripts/backfill.py::run",
+ "src/app/db.py::get_session"
+ ],
+ "provenance": "call-site",
+ "reason": "context_split: io_in_loop at scripts/backfill.py:200 repeats work per iteration."
}
],
"evidence_truncated": false,
- "execution_context": "production",
+ "execution_context": "tooling",
"facets": {
- "actionability_confidence": "low",
+ "actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": null,
- "intervention_symbol": null,
+ "fix": {
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "scripts/backfill.py::run",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_266b6dd67d9b9e93e201",
+ "opportunity_id": "perf3_d5225971c0220c77ee7b",
"performance_model_version": 3,
"prerequisites": [
- "loop_invariant_construction_proof"
+ "batch_api_contract",
+ "result_equivalence"
],
- "provenance": "direct",
+ "provenance": "call-site",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
"entry_reachability": 0,
- "execution_context": 3,
+ "execution_context": 2,
"loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 17,
+ "rank_score": 16,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [],
+ "shared_path_suffix": [
+ "scripts/backfill.py::run",
+ "src/app/db.py::get_session"
+ ],
"siblings": [],
- "terminal_sink": null,
+ "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sinks": [
+ "src/app/db.py::get_session"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "network"
+ "value": "db"
},
{
"factor": "multiplier_shape",
"points": 4,
- "value": "resource_construction_in_loop"
+ "value": "io_in_loop"
},
{
- "factor": "execution_context",
+ "factor": "provenance",
"points": 3,
- "value": "production"
+ "value": "call-site"
}
]
},
{
- "actionability_reason": "no_supported_strategy",
- "actionability_state": "investigate",
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "resource_construction_in_loop",
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "resource_construction_in_loop"
+ "io_in_loop"
],
- "boundary_kind": "network",
- "confidence": "high",
+ "boundary_kind": "db",
+ "confidence": "medium",
"evidence": [
{
- "biomarker_type": "resource_construction_in_loop",
- "file_path": "src/app/clients.py",
- "finding_id": "finding_840a26ef5269b670f5a2",
- "function_name": "each",
- "line_end": 172,
- "line_start": 170,
- "path": [],
- "provenance": "direct",
- "reason": "resource_construction: resource_construction_in_loop at src/app/clients.py:170 repeats work per iteration."
+ "biomarker_type": "io_in_loop",
+ "file_path": "src/app/edge.py",
+ "finding_id": "finding_323137fff890d9e629dc",
+ "function_name": "run",
+ "line_end": 232,
+ "line_start": 230,
+ "path": [
+ "src/app/edge.py::run",
+ "src/app/db.py::reliable_sink"
+ ],
+ "provenance": "reliable-edge",
+ "reason": "provenance_mix: io_in_loop at src/app/edge.py:230 repeats work per iteration."
}
],
"evidence_truncated": false,
"execution_context": "production",
"facets": {
- "actionability_confidence": "low",
+ "actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": null,
- "intervention_symbol": null,
+ "fix": {
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/edge.py::run",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_386a99aa2876c0dd31bd",
+ "opportunity_id": "perf3_dc2d9734ec9693504602",
"performance_model_version": 3,
"prerequisites": [
- "loop_invariant_construction_proof"
+ "batch_api_contract",
+ "result_equivalence"
],
- "provenance": "direct",
+ "provenance": "reliable-edge",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
@@ -2066,24 +2420,30 @@
"execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
- "provenance": 3
+ "provenance": 2
},
- "rank_score": 17,
+ "rank_score": 16,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [],
+ "shared_path_suffix": [
+ "src/app/edge.py::run",
+ "src/app/db.py::reliable_sink"
+ ],
"siblings": [],
- "terminal_sink": null,
+ "terminal_sink": "src/app/db.py::reliable_sink",
+ "terminal_sinks": [
+ "src/app/db.py::reliable_sink"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "network"
+ "value": "db"
},
{
"factor": "multiplier_shape",
"points": 4,
- "value": "resource_construction_in_loop"
+ "value": "io_in_loop"
},
{
"factor": "execution_context",
@@ -2093,86 +2453,102 @@
]
},
{
- "actionability_reason": "no_supported_strategy",
- "actionability_state": "investigate",
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
- "biomarker_type": "serial_await_in_loop",
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "serial_await_in_loop"
+ "io_in_loop"
],
- "boundary_kind": "network",
+ "boundary_kind": "db",
"confidence": "high",
"evidence": [
{
- "biomarker_type": "serial_await_in_loop",
- "file_path": "src/app/fanout.py",
- "finding_id": "finding_6f5702e6e6af64656121",
- "function_name": "gather_seq",
- "line_end": 97,
- "line_start": 95,
- "path": [],
- "provenance": "direct",
- "reason": "async_serial_awaits: serial_await_in_loop at src/app/fanout.py:95 repeats work per iteration."
+ "biomarker_type": "io_in_loop",
+ "file_path": "tests/test_job.py",
+ "finding_id": "finding_e34ca4ba22d5f482348d",
+ "function_name": "run",
+ "line_end": 202,
+ "line_start": 200,
+ "path": [
+ "tests/test_job.py::run",
+ "src/app/db.py::get_session"
+ ],
+ "provenance": "call-site",
+ "reason": "context_split: io_in_loop at tests/test_job.py:200 repeats work per iteration."
}
],
"evidence_truncated": false,
- "execution_context": "production",
+ "execution_context": "test",
"facets": {
- "actionability_confidence": "low",
+ "actionability_confidence": "medium",
"amplification": "per_iteration",
"change_risk": "contained",
"exposure": "unknown",
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": null,
- "intervention_symbol": null,
+ "fix": {
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "tests/test_job.py::run",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_64fbd03504c61c115894",
+ "opportunity_id": "perf3_91d25fc7b3e4e8ad00c1",
"performance_model_version": 3,
"prerequisites": [
- "loop_carried_dependence_proof"
+ "batch_api_contract",
+ "result_equivalence"
],
- "provenance": "direct",
+ "provenance": "call-site",
"rank_factors": {
"affected_call_sites": 2,
"boundary_kind": 4,
"entry_reachability": 0,
- "execution_context": 3,
+ "execution_context": 1,
"loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 17,
+ "rank_score": 15,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
- "shared_path_suffix": [],
+ "shared_path_suffix": [
+ "tests/test_job.py::run",
+ "src/app/db.py::get_session"
+ ],
"siblings": [],
- "terminal_sink": null,
+ "terminal_sink": "src/app/db.py::get_session",
+ "terminal_sinks": [
+ "src/app/db.py::get_session"
+ ],
"why_ranked": [
{
"factor": "boundary_kind",
"points": 4,
- "value": "network"
+ "value": "db"
},
{
"factor": "multiplier_shape",
"points": 4,
- "value": "serial_await_in_loop"
+ "value": "io_in_loop"
},
{
- "factor": "execution_context",
+ "factor": "provenance",
"points": 3,
- "value": "production"
+ "value": "call-site"
}
]
},
{
"actionability_reason": "inherent_to_boundary",
"actionability_state": "expected",
- "affected_call_sites_total": 4,
- "affected_files_total": 4,
+ "affected_call_sites_total": 1,
+ "affected_files_total": 1,
"biomarker_type": "io_in_loop",
"biomarker_types": [
"io_in_loop"
@@ -2182,63 +2558,17 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/formatter.py",
- "finding_id": "finding_74b3cc4ea0afc2828ead",
- "function_name": "run",
- "line_end": 24,
- "line_start": 22,
- "path": [
- "src/app/formatter.py::run",
- "src/app/parse.py::_get_query",
- "src/app/parse.py::_load_compiled_query"
- ],
- "provenance": "call-site",
- "reason": "shared_dominator_fan_in: io_in_loop at src/app/formatter.py:22 repeats work per iteration."
- },
- {
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/lexer.py",
- "finding_id": "finding_f1d7e9138afa40a0f1b7",
- "function_name": "run",
- "line_end": 22,
- "line_start": 20,
- "path": [
- "src/app/lexer.py::run",
- "src/app/parse.py::_get_query",
- "src/app/parse.py::_load_compiled_query"
- ],
- "provenance": "call-site",
- "reason": "shared_dominator_fan_in: io_in_loop at src/app/lexer.py:20 repeats work per iteration."
- },
- {
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/linter.py",
- "finding_id": "finding_04801d753f6bc1eb8675",
- "function_name": "run",
- "line_end": 23,
- "line_start": 21,
- "path": [
- "src/app/linter.py::run",
- "src/app/parse.py::_get_query",
- "src/app/parse.py::_load_compiled_query"
- ],
- "provenance": "call-site",
- "reason": "shared_dominator_fan_in: io_in_loop at src/app/linter.py:21 repeats work per iteration."
- },
- {
- "biomarker_type": "io_in_loop",
- "file_path": "src/app/resolver.py",
- "finding_id": "finding_1bb5c282969f6d4c8f99",
- "function_name": "run",
- "line_end": 25,
- "line_start": 23,
+ "file_path": "src/app/walker.py",
+ "finding_id": "finding_57d0612e4678a6b34b8d",
+ "function_name": "index",
+ "line_end": 53,
+ "line_start": 51,
"path": [
- "src/app/resolver.py::run",
- "src/app/parse.py::_get_query",
- "src/app/parse.py::_load_compiled_query"
+ "src/app/walker.py::index",
+ "src/app/fsio.py::read_text"
],
"provenance": "call-site",
- "reason": "shared_dominator_fan_in: io_in_loop at src/app/resolver.py:23 repeats work per iteration."
+ "reason": "filesystem_fan_out: io_in_loop at src/app/walker.py:51 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -2246,20 +2576,22 @@
"facets": {
"actionability_confidence": "low",
"amplification": "per_iteration",
- "change_risk": "moderate",
+ "change_risk": "contained",
"exposure": "unknown",
- "leverage": "shared",
+ "leverage": "isolated",
"loop_magnitude": "unknown"
},
"fix": null,
- "intervention_symbol": "src/app/parse.py::_get_query",
- "observations_total": 4,
- "opportunity_id": "perf3_a445d6f2d021ddf6a425",
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/walker.py::index",
+ "may_lead": true,
+ "observations_total": 1,
+ "opportunity_id": "perf3_9c136e77dd1c7e4e69bf",
"performance_model_version": 3,
"prerequisites": [],
"provenance": "call-site",
"rank_factors": {
- "affected_call_sites": 4,
+ "affected_call_sites": 2,
"boundary_kind": 2,
"entry_reachability": 0,
"execution_context": 3,
@@ -2267,21 +2599,19 @@
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 17,
+ "rank_score": 15,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
"shared_path_suffix": [
- "src/app/parse.py::_get_query",
- "src/app/parse.py::_load_compiled_query"
+ "src/app/walker.py::index",
+ "src/app/fsio.py::read_text"
],
"siblings": [],
- "terminal_sink": "src/app/parse.py::_load_compiled_query",
- "why_ranked": [
- {
- "factor": "affected_call_sites",
- "points": 4,
- "value": 4
- },
+ "terminal_sink": "src/app/fsio.py::read_text",
+ "terminal_sinks": [
+ "src/app/fsio.py::read_text"
+ ],
+ "why_ranked": [
{
"factor": "multiplier_shape",
"points": 4,
@@ -2291,6 +2621,11 @@
"factor": "execution_context",
"points": 3,
"value": "production"
+ },
+ {
+ "factor": "provenance",
+ "points": 3,
+ "value": "call-site"
}
]
},
@@ -2332,9 +2667,11 @@
"loop_magnitude": "unknown"
},
"fix": null,
+ "intervention_kind": "function",
"intervention_symbol": "src/app/walker.py::scan",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_19a89b391403e23aed4d",
+ "opportunity_id": "perf3_9fea1c21a0c25dd7af23",
"performance_model_version": 3,
"prerequisites": [],
"provenance": "call-site",
@@ -2356,6 +2693,9 @@
],
"siblings": [],
"terminal_sink": "src/app/fsio.py::read_text",
+ "terminal_sinks": [
+ "src/app/fsio.py::read_text"
+ ],
"why_ranked": [
{
"factor": "multiplier_shape",
@@ -2375,30 +2715,30 @@
]
},
{
- "actionability_reason": "inherent_to_boundary",
- "actionability_state": "expected",
+ "actionability_reason": "low_evidence_confidence",
+ "actionability_state": "advisory",
"affected_call_sites_total": 1,
"affected_files_total": 1,
"biomarker_type": "io_in_loop",
"biomarker_types": [
"io_in_loop"
],
- "boundary_kind": "filesystem",
- "confidence": "high",
+ "boundary_kind": "db",
+ "confidence": "low",
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "src/app/walker.py",
- "finding_id": "finding_57d0612e4678a6b34b8d",
- "function_name": "index",
- "line_end": 53,
- "line_start": 51,
+ "file_path": "src/app/guess.py",
+ "finding_id": "finding_e287cbc148e5a8ea8ca8",
+ "function_name": "run",
+ "line_end": 242,
+ "line_start": 240,
"path": [
- "src/app/walker.py::index",
- "src/app/fsio.py::read_text"
+ "src/app/guess.py::run",
+ "src/app/db.py::guessed_sink"
],
- "provenance": "call-site",
- "reason": "filesystem_fan_out: io_in_loop at src/app/walker.py:51 repeats work per iteration."
+ "provenance": "name-fallback",
+ "reason": "provenance_mix: io_in_loop at src/app/guess.py:240 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -2411,32 +2751,50 @@
"leverage": "isolated",
"loop_magnitude": "unknown"
},
- "fix": null,
- "intervention_symbol": "src/app/walker.py::index",
+ "fix": {
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "safety": "advisory",
+ "strategy": "batch_or_prefetch_io"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/guess.py::run",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_68583bf925fadb4f4731",
+ "opportunity_id": "perf3_b4b1621506e7231c520b",
"performance_model_version": 3,
- "prerequisites": [],
- "provenance": "call-site",
+ "prerequisites": [
+ "batch_api_contract",
+ "result_equivalence",
+ "reliable_call_path"
+ ],
+ "provenance": "name-fallback",
"rank_factors": {
"affected_call_sites": 2,
- "boundary_kind": 2,
+ "boundary_kind": 4,
"entry_reachability": 0,
"execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
- "provenance": 3
+ "provenance": 0
},
- "rank_score": 15,
+ "rank_score": 14,
"reliable_entry_reachability": null,
"resource_fingerprints": [],
"shared_path_suffix": [
- "src/app/walker.py::index",
- "src/app/fsio.py::read_text"
+ "src/app/guess.py::run",
+ "src/app/db.py::guessed_sink"
],
"siblings": [],
- "terminal_sink": "src/app/fsio.py::read_text",
+ "terminal_sink": "src/app/db.py::guessed_sink",
+ "terminal_sinks": [
+ "src/app/db.py::guessed_sink"
+ ],
"why_ranked": [
+ {
+ "factor": "boundary_kind",
+ "points": 4,
+ "value": "db"
+ },
{
"factor": "multiplier_shape",
"points": 4,
@@ -2446,11 +2804,6 @@
"factor": "execution_context",
"points": 3,
"value": "production"
- },
- {
- "factor": "provenance",
- "points": 3,
- "value": "call-site"
}
]
},
@@ -2468,14 +2821,14 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "docs/snippets/walk.py",
- "finding_id": "finding_d0b10a5d5eeb35e40893",
- "function_name": "demo",
- "line_end": 10,
- "line_start": 8,
+ "file_path": "bootstrap.py",
+ "finding_id": "finding_a88c49a6ad4cfd7bc111",
+ "function_name": "main",
+ "line_end": 16,
+ "line_start": 14,
"path": [],
"provenance": "direct",
- "reason": "unclassified_context: io_in_loop at docs/snippets/walk.py:8 repeats work per iteration."
+ "reason": "unclassified_context: io_in_loop at bootstrap.py:14 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -2489,9 +2842,11 @@
"loop_magnitude": "unknown"
},
"fix": null,
- "intervention_symbol": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "bootstrap.py::main",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_8ffbe99d8409ad899a72",
+ "opportunity_id": "perf3_b328704ea27ecd3de70a",
"performance_model_version": 3,
"prerequisites": [],
"provenance": "direct",
@@ -2510,6 +2865,7 @@
"shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "multiplier_shape",
@@ -2542,14 +2898,14 @@
"evidence": [
{
"biomarker_type": "io_in_loop",
- "file_path": "bootstrap.py",
- "finding_id": "finding_a88c49a6ad4cfd7bc111",
- "function_name": "main",
- "line_end": 16,
- "line_start": 14,
+ "file_path": "docs/snippets/walk.py",
+ "finding_id": "finding_d0b10a5d5eeb35e40893",
+ "function_name": "demo",
+ "line_end": 10,
+ "line_start": 8,
"path": [],
"provenance": "direct",
- "reason": "unclassified_context: io_in_loop at bootstrap.py:14 repeats work per iteration."
+ "reason": "unclassified_context: io_in_loop at docs/snippets/walk.py:8 repeats work per iteration."
}
],
"evidence_truncated": false,
@@ -2563,9 +2919,11 @@
"loop_magnitude": "unknown"
},
"fix": null,
- "intervention_symbol": null,
+ "intervention_kind": "function",
+ "intervention_symbol": "docs/snippets/walk.py::demo",
+ "may_lead": true,
"observations_total": 1,
- "opportunity_id": "perf3_91e5b79c0937ef51ec73",
+ "opportunity_id": "perf3_b3b3f1bd1707d53f5d6e",
"performance_model_version": 3,
"prerequisites": [],
"provenance": "direct",
@@ -2584,6 +2942,7 @@
"shared_path_suffix": [],
"siblings": [],
"terminal_sink": null,
+ "terminal_sinks": [],
"why_ranked": [
{
"factor": "multiplier_shape",
@@ -2601,6 +2960,173 @@
"value": 1
}
]
+ },
+ {
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 1,
+ "affected_files_total": 1,
+ "biomarker_type": "membership_test_against_list_in_loop",
+ "biomarker_types": [
+ "membership_test_against_list_in_loop"
+ ],
+ "boundary_kind": null,
+ "confidence": "high",
+ "evidence": [
+ {
+ "biomarker_type": "membership_test_against_list_in_loop",
+ "file_path": "src/app/filters.py",
+ "finding_id": "finding_9fa77c322fa3d741a8c4",
+ "function_name": "select",
+ "line_end": 152,
+ "line_start": 150,
+ "path": [],
+ "provenance": "direct",
+ "reason": "membership_scan: membership_test_against_list_in_loop at src/app/filters.py:150 repeats work per iteration."
+ }
+ ],
+ "evidence_truncated": false,
+ "execution_context": "production",
+ "facets": {
+ "actionability_confidence": "medium",
+ "amplification": "per_iteration",
+ "change_risk": "contained",
+ "exposure": "unknown",
+ "leverage": "isolated",
+ "loop_magnitude": "unknown"
+ },
+ "fix": {
+ "rationale": "The collection is proven list-backed; element hashability and ordering/identity use still require validation.",
+ "safety": "advisory",
+ "strategy": "replace_membership_collection"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/filters.py::select",
+ "may_lead": true,
+ "observations_total": 1,
+ "opportunity_id": "perf3_68f6614ac285d1e8cb4a",
+ "performance_model_version": 3,
+ "prerequisites": [
+ "element_hashability",
+ "ordering_and_identity_use"
+ ],
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 0,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 3,
+ "provenance": 3
+ },
+ "rank_score": 12,
+ "reliable_entry_reachability": null,
+ "resource_fingerprints": [],
+ "shared_path_suffix": [],
+ "siblings": [],
+ "terminal_sink": null,
+ "terminal_sinks": [],
+ "why_ranked": [
+ {
+ "factor": "execution_context",
+ "points": 3,
+ "value": "production"
+ },
+ {
+ "factor": "multiplier_shape",
+ "points": 3,
+ "value": "membership_test_against_list_in_loop"
+ },
+ {
+ "factor": "provenance",
+ "points": 3,
+ "value": "direct"
+ }
+ ]
+ },
+ {
+ "actionability_reason": "strategy_requires_validation",
+ "actionability_state": "advisory",
+ "affected_call_sites_total": 1,
+ "affected_files_total": 1,
+ "biomarker_type": "string_concat_in_loop",
+ "biomarker_types": [
+ "string_concat_in_loop"
+ ],
+ "boundary_kind": null,
+ "confidence": "high",
+ "evidence": [
+ {
+ "biomarker_type": "string_concat_in_loop",
+ "file_path": "src/app/render.py",
+ "finding_id": "finding_ffee3cf5c3bbf22b87ba",
+ "function_name": "to_csv",
+ "line_end": 162,
+ "line_start": 160,
+ "path": [],
+ "provenance": "direct",
+ "reason": "string_accumulation: string_concat_in_loop at src/app/render.py:160 repeats work per iteration."
+ }
+ ],
+ "evidence_truncated": false,
+ "execution_context": "production",
+ "facets": {
+ "actionability_confidence": "medium",
+ "amplification": "per_iteration",
+ "change_risk": "contained",
+ "exposure": "unknown",
+ "leverage": "isolated",
+ "loop_magnitude": "unknown"
+ },
+ "fix": {
+ "rationale": "Repeated string accumulation is proven; intermediate accumulator observations still require validation.",
+ "safety": "advisory",
+ "strategy": "buffer_string_accumulation"
+ },
+ "intervention_kind": "function",
+ "intervention_symbol": "src/app/render.py::to_csv",
+ "may_lead": true,
+ "observations_total": 1,
+ "opportunity_id": "perf3_ea095ac8d3d612777176",
+ "performance_model_version": 3,
+ "prerequisites": [
+ "accumulator_not_observed"
+ ],
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 0,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 3,
+ "provenance": 3
+ },
+ "rank_score": 12,
+ "reliable_entry_reachability": null,
+ "resource_fingerprints": [],
+ "shared_path_suffix": [],
+ "siblings": [],
+ "terminal_sink": null,
+ "terminal_sinks": [],
+ "why_ranked": [
+ {
+ "factor": "execution_context",
+ "points": 3,
+ "value": "production"
+ },
+ {
+ "factor": "multiplier_shape",
+ "points": 3,
+ "value": "string_concat_in_loop"
+ },
+ {
+ "factor": "provenance",
+ "points": 3,
+ "value": "direct"
+ }
+ ]
}
]
}
diff --git a/tests/fixtures/perf_corpus/golden_plans.json b/tests/fixtures/perf_corpus/golden_plans.json
index 9431a4b3d..e07d322f0 100644
--- a/tests/fixtures/perf_corpus/golden_plans.json
+++ b/tests/fixtures/perf_corpus/golden_plans.json
@@ -2,145 +2,236 @@
"plans": [
{
"blast_radius": {
- "call_sites": 1,
+ "call_sites": 3,
"file_count": 1,
"files": [
- "src/app/owners.py"
+ "src/app/jobs.py"
]
},
- "confidence": "high",
+ "confidence": "medium",
"evidence": {
"affected_files_total": 1,
- "biomarker_type": "io_in_loop",
+ "biomarker_type": "nested_loop_with_io",
"biomarker_types": [
- "io_in_loop"
+ "io_in_loop",
+ "nested_loop_with_io"
],
"boundary_kind": "db",
"execution_context": "production",
- "observations_total": 1,
- "provenance": "direct",
+ "observations_total": 3,
+ "provenance": "call-site",
"rank_factors": {
- "affected_call_sites": 2,
+ "affected_call_sites": 4,
"boundary_kind": 4,
- "entry_reachability": 0,
+ "entry_reachability": 3,
"execution_context": 3,
- "loop_magnitude": 2,
- "multiplier_shape": 4,
+ "loop_magnitude": 1,
+ "multiplier_shape": 6,
"provenance": 3
},
- "rank_score": 18,
- "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) covers the same rows, and nothing else in the loop can observe the difference.",
- "reliable_entry_reachability": null
+ "rank_score": 24,
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "reliable_entry_reachability": true
},
- "file_path": "src/app/owners.py",
+ "file_path": "src/app/jobs.py",
"impact_delta": 0.0,
- "line_end": 22,
- "line_start": 20,
+ "line_end": 40,
+ "line_start": 40,
"plan": {
"affected_locations": [
{
- "file_path": "src/app/owners.py",
- "function_name": "load_owners",
- "line_end": 22,
- "line_start": 20
+ "file_path": "src/app/jobs.py",
+ "function_name": "drain",
+ "line_end": 40,
+ "line_start": 40
+ },
+ {
+ "file_path": "src/app/jobs.py",
+ "function_name": "drain",
+ "line_end": 42,
+ "line_start": 42
+ },
+ {
+ "file_path": "src/app/jobs.py",
+ "function_name": "drain",
+ "line_end": 44,
+ "line_start": 44
}
],
- "affected_locations_total": 1,
- "api": ".in_(\"repo_id\", keys)",
+ "affected_locations_total": 3,
+ "api": null,
"evidence_truncated": false,
- "intervention_symbol": null,
- "judgment_steps": 0,
- "mechanical_steps": 1,
- "opportunity_id": "perf3_e1734c647c3b26b6dfc4",
- "paths": [],
- "paths_total": 1,
- "safety": "proven",
+ "intervention_symbol": "src/app/jobs.py::drain",
+ "judgment_steps": 4,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_d41b04897cfde2a9eed6",
+ "paths": [
+ [
+ "src/app/jobs.py::drain",
+ "src/app/db.py::save"
+ ]
+ ],
+ "paths_total": 3,
+ "safety": "advisory",
"steps": [
{
- "action": "Collect the keys before the loop and make one call with .in_(\"repo_id\", keys) in place of the per-key call",
- "applicability": "mechanical",
- "file_path": "src/app/owners.py",
- "line": 20,
+ "action": "Add a form of save that takes every key at once",
+ "applicability": "judgment",
+ "file_path": "src/app/db.py",
+ "line": null,
"order": 1,
- "symbol": "load_owners"
+ "symbol": "src/app/db.py::save"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/jobs.py",
+ "line": 40,
+ "order": 2,
+ "symbol": "drain"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/jobs.py",
+ "line": 42,
+ "order": 3,
+ "symbol": "drain"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/jobs.py",
+ "line": 44,
+ "order": 4,
+ "symbol": "drain"
}
],
"strategy": "batch_or_prefetch_io"
},
"refactoring_type": "performance_fix",
- "source_biomarker": "io_in_loop",
- "target_symbol": "load_owners"
+ "source_biomarker": "nested_loop_with_io",
+ "target_symbol": "src/app/jobs.py::drain"
},
{
"blast_radius": {
- "call_sites": 1,
+ "call_sites": 3,
"file_count": 1,
"files": [
- "src/app/fetch.py"
+ "src/app/migrate.py"
]
},
- "confidence": "high",
+ "confidence": "medium",
"evidence": {
"affected_files_total": 1,
- "biomarker_type": "serial_await_in_loop",
+ "biomarker_type": "io_in_loop",
"biomarker_types": [
- "serial_await_in_loop"
+ "io_in_loop"
],
- "boundary_kind": "network",
+ "boundary_kind": "db",
"execution_context": "production",
- "observations_total": 1,
- "provenance": "direct",
+ "observations_total": 3,
+ "provenance": "call-site",
"rank_factors": {
- "affected_call_sites": 2,
+ "affected_call_sites": 4,
"boundary_kind": 4,
- "entry_reachability": 0,
+ "entry_reachability": 3,
"execution_context": 3,
"loop_magnitude": 1,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 17,
- "rationale": "Iterations are independent and each await already runs under self._sem.",
- "reliable_entry_reachability": null
+ "rank_score": 22,
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "reliable_entry_reachability": true
},
- "file_path": "src/app/fetch.py",
+ "file_path": "src/app/migrate.py",
"impact_delta": 0.0,
- "line_end": 42,
- "line_start": 40,
+ "line_end": 587,
+ "line_start": 587,
"plan": {
"affected_locations": [
{
- "file_path": "src/app/fetch.py",
- "function_name": "fetch_each",
- "line_end": 42,
- "line_start": 40
+ "file_path": "src/app/migrate.py",
+ "function_name": "apply",
+ "line_end": 587,
+ "line_start": 587
+ },
+ {
+ "file_path": "src/app/migrate.py",
+ "function_name": "apply",
+ "line_end": 590,
+ "line_start": 590
+ },
+ {
+ "file_path": "src/app/migrate.py",
+ "function_name": "apply",
+ "line_end": 591,
+ "line_start": 591
}
],
- "affected_locations_total": 1,
- "api": "self._sem",
+ "affected_locations_total": 3,
+ "api": null,
"evidence_truncated": false,
- "intervention_symbol": null,
- "judgment_steps": 0,
- "mechanical_steps": 1,
- "opportunity_id": "perf3_cc802c5285ea0c31b02a",
- "paths": [],
- "paths_total": 1,
- "safety": "proven",
+ "intervention_symbol": "src/app/migrate.py::apply",
+ "judgment_steps": 4,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_b03c60fe41fa017130c6",
+ "paths": [
+ [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_move"
+ ],
+ [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_fold_one"
+ ],
+ [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_write_alias"
+ ]
+ ],
+ "paths_total": 3,
+ "safety": "advisory",
"steps": [
{
- "action": "Run the independent awaits concurrently, each still inside self._sem",
- "applicability": "mechanical",
- "file_path": "src/app/fetch.py",
- "line": 40,
+ "action": "Add a form of the per-key call that takes every key at once",
+ "applicability": "judgment",
+ "file_path": null,
+ "line": null,
"order": 1,
- "symbol": "fetch_each"
+ "symbol": null
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/migrate.py",
+ "line": 587,
+ "order": 2,
+ "symbol": "apply"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/migrate.py",
+ "line": 590,
+ "order": 3,
+ "symbol": "apply"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/migrate.py",
+ "line": 591,
+ "order": 4,
+ "symbol": "apply"
}
],
- "strategy": "parallelize_independent_awaits"
+ "strategy": "batch_or_prefetch_io"
},
"refactoring_type": "performance_fix",
- "source_biomarker": "serial_await_in_loop",
- "target_symbol": "fetch_each"
+ "source_biomarker": "io_in_loop",
+ "target_symbol": "src/app/migrate.py::apply"
},
{
"blast_radius": {
@@ -199,7 +290,7 @@
"intervention_symbol": "src/app/entry.py::_hit",
"judgment_steps": 3,
"mechanical_steps": 0,
- "opportunity_id": "perf3_0673587e7abbea99fc0b",
+ "opportunity_id": "perf3_6690af4c5e3f269c266e",
"paths": [
[
"src/app/entry.py::a",
@@ -303,7 +394,7 @@
"intervention_symbol": "src/app/repo.py::fetch_page",
"judgment_steps": 3,
"mechanical_steps": 0,
- "opportunity_id": "perf3_89348be6c2ba0311a0e8",
+ "opportunity_id": "perf3_8456a319d03ac90c6041",
"paths": [
[
"src/app/api.py::list_users",
@@ -408,7 +499,7 @@
"intervention_symbol": "src/app/reindex.py::_write",
"judgment_steps": 3,
"mechanical_steps": 0,
- "opportunity_id": "perf3_3d62fcebb00bdf408f2c",
+ "opportunity_id": "perf3_a123c4c38fdb1cabaa6a",
"paths": [
[
"src/app/reindex.py::one",
@@ -455,6 +546,77 @@
"source_biomarker": "nested_loop_with_io",
"target_symbol": "src/app/reindex.py::_write"
},
+ {
+ "blast_radius": {
+ "call_sites": 1,
+ "file_count": 1,
+ "files": [
+ "src/app/owners.py"
+ ]
+ },
+ "confidence": "high",
+ "evidence": {
+ "affected_files_total": 1,
+ "biomarker_type": "io_in_loop",
+ "biomarker_types": [
+ "io_in_loop"
+ ],
+ "boundary_kind": "db",
+ "execution_context": "production",
+ "observations_total": 1,
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 2,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 18,
+ "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) covers the same rows, and nothing else in the loop can observe the difference.",
+ "reliable_entry_reachability": null
+ },
+ "file_path": "src/app/owners.py",
+ "impact_delta": 0.0,
+ "line_end": 22,
+ "line_start": 20,
+ "plan": {
+ "affected_locations": [
+ {
+ "file_path": "src/app/owners.py",
+ "function_name": "load_owners",
+ "line_end": 22,
+ "line_start": 20
+ }
+ ],
+ "affected_locations_total": 1,
+ "api": ".in_(\"repo_id\", keys)",
+ "evidence_truncated": false,
+ "intervention_symbol": "src/app/owners.py::load_owners",
+ "judgment_steps": 0,
+ "mechanical_steps": 1,
+ "opportunity_id": "perf3_83d258547498bed60226",
+ "paths": [],
+ "paths_total": 1,
+ "safety": "proven",
+ "steps": [
+ {
+ "action": "Collect the keys before the loop and make one call with .in_(\"repo_id\", keys) in place of the per-key call",
+ "applicability": "mechanical",
+ "file_path": "src/app/owners.py",
+ "line": 20,
+ "order": 1,
+ "symbol": "load_owners"
+ }
+ ],
+ "strategy": "batch_or_prefetch_io"
+ },
+ "refactoring_type": "performance_fix",
+ "source_biomarker": "io_in_loop",
+ "target_symbol": "src/app/owners.py::load_owners"
+ },
{
"blast_radius": {
"call_sites": 2,
@@ -512,7 +674,7 @@
"intervention_symbol": "src/app/sync.py::_load",
"judgment_steps": 3,
"mechanical_steps": 0,
- "opportunity_id": "perf3_af29fc10103a555c8652",
+ "opportunity_id": "perf3_8845956c083937dad1ec",
"paths": [
[
"src/app/sync.py::sync_one",
@@ -610,7 +772,7 @@
"intervention_symbol": "src/app/cache.py::refresh",
"judgment_steps": 1,
"mechanical_steps": 0,
- "opportunity_id": "perf3_9dfe577bc9c8b799355e",
+ "opportunity_id": "perf3_600194da489eff07f26a",
"paths": [
[
"src/app/cache.py::refresh",
@@ -640,10 +802,10 @@
"call_sites": 1,
"file_count": 1,
"files": [
- "src/app/fanout.py"
+ "src/app/fetch.py"
]
},
- "confidence": "medium",
+ "confidence": "high",
"evidence": {
"affected_files_total": 1,
"biomarker_type": "serial_await_in_loop",
@@ -664,54 +826,196 @@
"provenance": 3
},
"rank_score": 17,
- "rationale": "Iteration independence is proven; the concurrency the fan-out would create is not bounded by anything this group can see.",
+ "rationale": "Iterations are independent and each await already runs under self._sem.",
"reliable_entry_reachability": null
},
- "file_path": "src/app/fanout.py",
+ "file_path": "src/app/fetch.py",
"impact_delta": 0.0,
- "line_end": 92,
- "line_start": 90,
+ "line_end": 42,
+ "line_start": 40,
"plan": {
"affected_locations": [
{
- "file_path": "src/app/fanout.py",
- "function_name": "gather_all",
- "line_end": 92,
- "line_start": 90
+ "file_path": "src/app/fetch.py",
+ "function_name": "fetch_each",
+ "line_end": 42,
+ "line_start": 40
}
],
"affected_locations_total": 1,
- "api": null,
+ "api": "self._sem",
"evidence_truncated": false,
- "intervention_symbol": null,
- "judgment_steps": 1,
- "mechanical_steps": 0,
- "opportunity_id": "perf3_182b2a7c053167959285",
+ "intervention_symbol": "src/app/fetch.py::fetch_each",
+ "judgment_steps": 0,
+ "mechanical_steps": 1,
+ "opportunity_id": "perf3_877f87ea6dac79fd92fc",
"paths": [],
"paths_total": 1,
- "safety": "advisory",
+ "safety": "proven",
"steps": [
{
- "action": "Run the independent awaits concurrently, with a bound on how many at once",
- "applicability": "judgment",
- "file_path": "src/app/fanout.py",
- "line": 90,
- "order": 1,
- "symbol": "gather_all"
- }
+ "action": "Run the independent awaits concurrently, each still inside self._sem",
+ "applicability": "mechanical",
+ "file_path": "src/app/fetch.py",
+ "line": 40,
+ "order": 1,
+ "symbol": "fetch_each"
+ }
],
"strategy": "parallelize_independent_awaits"
},
"refactoring_type": "performance_fix",
"source_biomarker": "serial_await_in_loop",
- "target_symbol": "gather_all"
+ "target_symbol": "src/app/fetch.py::fetch_each"
},
{
"blast_radius": {
"call_sites": 1,
"file_count": 1,
"files": [
- "src/app/billing.py"
+ "src/app/commits.py"
+ ]
+ },
+ "confidence": "medium",
+ "evidence": {
+ "affected_files_total": 1,
+ "biomarker_type": "io_in_loop",
+ "biomarker_types": [
+ "io_in_loop"
+ ],
+ "boundary_kind": "db",
+ "execution_context": "production",
+ "observations_total": 1,
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 17,
+ "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) is the bulk form; the per-key call limits, orders or shares the loop with other I/O.",
+ "reliable_entry_reachability": null
+ },
+ "file_path": "src/app/commits.py",
+ "impact_delta": 0.0,
+ "line_end": 32,
+ "line_start": 30,
+ "plan": {
+ "affected_locations": [
+ {
+ "file_path": "src/app/commits.py",
+ "function_name": "first_commit_each",
+ "line_end": 32,
+ "line_start": 30
+ }
+ ],
+ "affected_locations_total": 1,
+ "api": ".in_(\"repo_id\", keys)",
+ "evidence_truncated": false,
+ "intervention_symbol": "src/app/commits.py::first_commit_each",
+ "judgment_steps": 1,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_2a6f52da25a5ede16116",
+ "paths": [],
+ "paths_total": 1,
+ "safety": "advisory",
+ "steps": [
+ {
+ "action": "Collect the keys before the loop and make one call with .in_(\"repo_id\", keys) in place of the per-key call",
+ "applicability": "judgment",
+ "file_path": "src/app/commits.py",
+ "line": 30,
+ "order": 1,
+ "symbol": "first_commit_each"
+ }
+ ],
+ "strategy": "batch_or_prefetch_io"
+ },
+ "refactoring_type": "performance_fix",
+ "source_biomarker": "io_in_loop",
+ "target_symbol": "src/app/commits.py::first_commit_each"
+ },
+ {
+ "blast_radius": {
+ "call_sites": 1,
+ "file_count": 1,
+ "files": [
+ "src/app/fanout.py"
+ ]
+ },
+ "confidence": "medium",
+ "evidence": {
+ "affected_files_total": 1,
+ "biomarker_type": "serial_await_in_loop",
+ "biomarker_types": [
+ "serial_await_in_loop"
+ ],
+ "boundary_kind": "network",
+ "execution_context": "production",
+ "observations_total": 1,
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 17,
+ "rationale": "Iteration independence is proven; the concurrency the fan-out would create is not bounded by anything this group can see.",
+ "reliable_entry_reachability": null
+ },
+ "file_path": "src/app/fanout.py",
+ "impact_delta": 0.0,
+ "line_end": 92,
+ "line_start": 90,
+ "plan": {
+ "affected_locations": [
+ {
+ "file_path": "src/app/fanout.py",
+ "function_name": "gather_all",
+ "line_end": 92,
+ "line_start": 90
+ }
+ ],
+ "affected_locations_total": 1,
+ "api": null,
+ "evidence_truncated": false,
+ "intervention_symbol": "src/app/fanout.py::gather_all",
+ "judgment_steps": 1,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_445b62193f1ff0db3cb4",
+ "paths": [],
+ "paths_total": 1,
+ "safety": "advisory",
+ "steps": [
+ {
+ "action": "Run the independent awaits concurrently, with a bound on how many at once",
+ "applicability": "judgment",
+ "file_path": "src/app/fanout.py",
+ "line": 90,
+ "order": 1,
+ "symbol": "gather_all"
+ }
+ ],
+ "strategy": "parallelize_independent_awaits"
+ },
+ "refactoring_type": "performance_fix",
+ "source_biomarker": "serial_await_in_loop",
+ "target_symbol": "src/app/fanout.py::gather_all"
+ },
+ {
+ "blast_radius": {
+ "call_sites": 1,
+ "file_count": 1,
+ "files": [
+ "src/app/job.py"
]
},
"confidence": "medium",
@@ -735,60 +1039,267 @@
"provenance": 3
},
"rank_score": 17,
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
- "reliable_entry_reachability": false
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "reliable_entry_reachability": null
+ },
+ "file_path": "src/app/job.py",
+ "impact_delta": 0.0,
+ "line_end": 202,
+ "line_start": 200,
+ "plan": {
+ "affected_locations": [
+ {
+ "file_path": "src/app/job.py",
+ "function_name": "run",
+ "line_end": 202,
+ "line_start": 200
+ }
+ ],
+ "affected_locations_total": 1,
+ "api": null,
+ "evidence_truncated": false,
+ "intervention_symbol": "src/app/job.py::run",
+ "judgment_steps": 2,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_4e3feb071c73aa51a6a4",
+ "paths": [
+ [
+ "src/app/job.py::run",
+ "src/app/db.py::get_session"
+ ]
+ ],
+ "paths_total": 1,
+ "safety": "advisory",
+ "steps": [
+ {
+ "action": "Add a form of get_session that takes every key at once",
+ "applicability": "judgment",
+ "file_path": "src/app/db.py",
+ "line": null,
+ "order": 1,
+ "symbol": "src/app/db.py::get_session"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/job.py",
+ "line": 200,
+ "order": 2,
+ "symbol": "run"
+ }
+ ],
+ "strategy": "batch_or_prefetch_io"
+ },
+ "refactoring_type": "performance_fix",
+ "source_biomarker": "io_in_loop",
+ "target_symbol": "src/app/job.py::run"
+ },
+ {
+ "blast_radius": {
+ "call_sites": 1,
+ "file_count": 1,
+ "files": [
+ "src/app/lone.py"
+ ]
+ },
+ "confidence": "medium",
+ "evidence": {
+ "affected_files_total": 1,
+ "biomarker_type": "io_in_loop",
+ "biomarker_types": [
+ "io_in_loop"
+ ],
+ "boundary_kind": "db",
+ "execution_context": "production",
+ "observations_total": 1,
+ "provenance": "call-site",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 17,
+ "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
+ "reliable_entry_reachability": null
+ },
+ "file_path": "src/app/lone.py",
+ "impact_delta": 0.0,
+ "line_end": 11,
+ "line_start": 9,
+ "plan": {
+ "affected_locations": [
+ {
+ "file_path": "src/app/lone.py",
+ "function_name": "run",
+ "line_end": 11,
+ "line_start": 9
+ }
+ ],
+ "affected_locations_total": 1,
+ "api": null,
+ "evidence_truncated": false,
+ "intervention_symbol": "src/app/lone.py::run",
+ "judgment_steps": 2,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_919d91fe15e89966b389",
+ "paths": [
+ [
+ "src/app/db.py::only_sink"
+ ]
+ ],
+ "paths_total": 1,
+ "safety": "advisory",
+ "steps": [
+ {
+ "action": "Add a form of only_sink that takes every key at once",
+ "applicability": "judgment",
+ "file_path": "src/app/db.py",
+ "line": null,
+ "order": 1,
+ "symbol": "src/app/db.py::only_sink"
+ },
+ {
+ "action": "Collect the keys before the loop and call the batched form once",
+ "applicability": "judgment",
+ "file_path": "src/app/lone.py",
+ "line": 9,
+ "order": 2,
+ "symbol": "run"
+ }
+ ],
+ "strategy": "batch_or_prefetch_io"
+ },
+ "refactoring_type": "performance_fix",
+ "source_biomarker": "io_in_loop",
+ "target_symbol": "src/app/lone.py::run"
+ },
+ {
+ "blast_radius": {
+ "call_sites": 1,
+ "file_count": 1,
+ "files": [
+ "app/incidents/service.py"
+ ]
+ },
+ "confidence": "medium",
+ "evidence": {
+ "affected_files_total": 1,
+ "biomarker_type": "lazy_load_in_loop",
+ "biomarker_types": [
+ "lazy_load_in_loop"
+ ],
+ "boundary_kind": "db",
+ "execution_context": "production",
+ "observations_total": 1,
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 17,
+ "rationale": "The relationship is declared lazy and the query that produced the rows does not load it; whether every iteration reaches the access, and whether another layer loads it first, is not proven.",
+ "reliable_entry_reachability": null
+ },
+ "file_path": "app/incidents/service.py",
+ "impact_delta": 0.0,
+ "line_end": 50,
+ "line_start": 50,
+ "plan": {
+ "affected_locations": [
+ {
+ "file_path": "app/incidents/service.py",
+ "function_name": "notify_owners",
+ "line_end": 50,
+ "line_start": 50
+ }
+ ],
+ "affected_locations_total": 1,
+ "api": null,
+ "evidence_truncated": false,
+ "intervention_symbol": "app/incidents/service.py::notify_owners",
+ "judgment_steps": 0,
+ "mechanical_steps": 0,
+ "opportunity_id": "perf3_93a53323a7db0544017f",
+ "paths": [],
+ "paths_total": 1,
+ "safety": "advisory",
+ "steps": [],
+ "strategy": "eager_load_relationship"
+ },
+ "refactoring_type": "performance_fix",
+ "source_biomarker": "lazy_load_in_loop",
+ "target_symbol": "app/incidents/service.py::notify_owners"
+ },
+ {
+ "blast_radius": {
+ "call_sites": 1,
+ "file_count": 1,
+ "files": [
+ "app/issues/views.py"
+ ]
+ },
+ "confidence": "medium",
+ "evidence": {
+ "affected_files_total": 1,
+ "biomarker_type": "lazy_load_in_loop",
+ "biomarker_types": [
+ "lazy_load_in_loop"
+ ],
+ "boundary_kind": "db",
+ "execution_context": "production",
+ "observations_total": 1,
+ "provenance": "direct",
+ "rank_factors": {
+ "affected_call_sites": 2,
+ "boundary_kind": 4,
+ "entry_reachability": 0,
+ "execution_context": 3,
+ "loop_magnitude": 1,
+ "multiplier_shape": 4,
+ "provenance": 3
+ },
+ "rank_score": 17,
+ "rationale": "The relationship is declared lazy and the query that produced the rows does not load it; whether every iteration reaches the access, and whether another layer loads it first, is not proven.",
+ "reliable_entry_reachability": null
},
- "file_path": "src/app/billing.py",
+ "file_path": "app/issues/views.py",
"impact_delta": 0.0,
- "line_end": 13,
- "line_start": 11,
+ "line_end": 30,
+ "line_start": 30,
"plan": {
"affected_locations": [
{
- "file_path": "src/app/billing.py",
- "function_name": "handle",
- "line_end": 13,
- "line_start": 11
+ "file_path": "app/issues/views.py",
+ "function_name": "issue_list",
+ "line_end": 30,
+ "line_start": 30
}
],
"affected_locations_total": 1,
"api": null,
"evidence_truncated": false,
- "intervention_symbol": "src/app/billing.py::handle",
- "judgment_steps": 2,
+ "intervention_symbol": "app/issues/views.py::issue_list",
+ "judgment_steps": 0,
"mechanical_steps": 0,
- "opportunity_id": "perf3_3d4056f8405c9313d004",
- "paths": [
- [
- "src/app/billing.py::handle",
- "src/app/db.py::get_session"
- ]
- ],
+ "opportunity_id": "perf3_942cceadc50a644175e4",
+ "paths": [],
"paths_total": 1,
"safety": "advisory",
- "steps": [
- {
- "action": "Add a form of handle that takes every key at once",
- "applicability": "judgment",
- "file_path": "src/app/billing.py",
- "line": null,
- "order": 1,
- "symbol": "src/app/billing.py::handle"
- },
- {
- "action": "Collect the keys before the loop and call the batched form once",
- "applicability": "judgment",
- "file_path": "src/app/billing.py",
- "line": 11,
- "order": 2,
- "symbol": "handle"
- }
- ],
- "strategy": "batch_or_prefetch_io"
+ "steps": [],
+ "strategy": "eager_load_relationship"
},
"refactoring_type": "performance_fix",
- "source_biomarker": "io_in_loop",
- "target_symbol": "src/app/billing.py::handle"
+ "source_biomarker": "lazy_load_in_loop",
+ "target_symbol": "app/issues/views.py::issue_list"
},
{
"blast_radius": {
@@ -841,7 +1352,7 @@
"intervention_symbol": "src/app/orders.py::handle",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_5abe869788cb2cebf6cf",
+ "opportunity_id": "perf3_95567b0824b33141361d",
"paths": [
[
"src/app/orders.py::handle",
@@ -852,12 +1363,12 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of handle that takes every key at once",
+ "action": "Add a form of get_session that takes every key at once",
"applicability": "judgment",
- "file_path": "src/app/orders.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "src/app/orders.py::handle"
+ "symbol": "src/app/db.py::get_session"
},
{
"action": "Collect the keys before the loop and call the batched form once",
@@ -925,7 +1436,7 @@
"intervention_symbol": "src/app/reports.py::handle",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_7d6b729c3f43753626f2",
+ "opportunity_id": "perf3_a0ebb8db3cb33a2c555f",
"paths": [
[
"src/app/reports.py::handle",
@@ -936,12 +1447,12 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of handle that takes every key at once",
+ "action": "Add a form of get_session that takes every key at once",
"applicability": "judgment",
- "file_path": "src/app/reports.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "src/app/reports.py::handle"
+ "symbol": "src/app/db.py::get_session"
},
{
"action": "Collect the keys before the loop and call the batched form once",
@@ -963,7 +1474,7 @@
"call_sites": 1,
"file_count": 1,
"files": [
- "src/app/job.py"
+ "src/app/billing.py"
]
},
"confidence": "medium",
@@ -988,31 +1499,31 @@
},
"rank_score": 17,
"rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
- "reliable_entry_reachability": null
+ "reliable_entry_reachability": false
},
- "file_path": "src/app/job.py",
+ "file_path": "src/app/billing.py",
"impact_delta": 0.0,
- "line_end": 202,
- "line_start": 200,
+ "line_end": 13,
+ "line_start": 11,
"plan": {
"affected_locations": [
{
- "file_path": "src/app/job.py",
- "function_name": "run",
- "line_end": 202,
- "line_start": 200
+ "file_path": "src/app/billing.py",
+ "function_name": "handle",
+ "line_end": 13,
+ "line_start": 11
}
],
"affected_locations_total": 1,
"api": null,
"evidence_truncated": false,
- "intervention_symbol": "src/app/job.py::run",
+ "intervention_symbol": "src/app/billing.py::handle",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_811bb33b8d8f9e744638",
+ "opportunity_id": "perf3_debc1e358c095e5fd0d8",
"paths": [
[
- "src/app/job.py::run",
+ "src/app/billing.py::handle",
"src/app/db.py::get_session"
]
],
@@ -1020,34 +1531,34 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of run that takes every key at once",
+ "action": "Add a form of get_session that takes every key at once",
"applicability": "judgment",
- "file_path": "src/app/job.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "src/app/job.py::run"
+ "symbol": "src/app/db.py::get_session"
},
{
"action": "Collect the keys before the loop and call the batched form once",
"applicability": "judgment",
- "file_path": "src/app/job.py",
- "line": 200,
+ "file_path": "src/app/billing.py",
+ "line": 11,
"order": 2,
- "symbol": "run"
+ "symbol": "handle"
}
],
"strategy": "batch_or_prefetch_io"
},
"refactoring_type": "performance_fix",
"source_biomarker": "io_in_loop",
- "target_symbol": "src/app/job.py::run"
+ "target_symbol": "src/app/billing.py::handle"
},
{
"blast_radius": {
"call_sites": 1,
"file_count": 1,
"files": [
- "src/app/commits.py"
+ "src/app/retry.py"
]
},
"confidence": "medium",
@@ -1057,7 +1568,7 @@
"biomarker_types": [
"io_in_loop"
],
- "boundary_kind": "db",
+ "boundary_kind": "network",
"execution_context": "production",
"observations_total": 1,
"provenance": "direct",
@@ -1066,115 +1577,40 @@
"boundary_kind": 4,
"entry_reachability": 0,
"execution_context": 3,
- "loop_magnitude": 1,
- "multiplier_shape": 4,
- "provenance": 3
- },
- "rank_score": 17,
- "rationale": "Every call filters on the loop's own key, so .in_(\"repo_id\", keys) is the bulk form; the per-key call limits, orders or shares the loop with other I/O.",
- "reliable_entry_reachability": null
- },
- "file_path": "src/app/commits.py",
- "impact_delta": 0.0,
- "line_end": 32,
- "line_start": 30,
- "plan": {
- "affected_locations": [
- {
- "file_path": "src/app/commits.py",
- "function_name": "first_commit_each",
- "line_end": 32,
- "line_start": 30
- }
- ],
- "affected_locations_total": 1,
- "api": ".in_(\"repo_id\", keys)",
- "evidence_truncated": false,
- "intervention_symbol": null,
- "judgment_steps": 1,
- "mechanical_steps": 0,
- "opportunity_id": "perf3_820a695aba4fe3a6496a",
- "paths": [],
- "paths_total": 1,
- "safety": "advisory",
- "steps": [
- {
- "action": "Collect the keys before the loop and make one call with .in_(\"repo_id\", keys) in place of the per-key call",
- "applicability": "judgment",
- "file_path": "src/app/commits.py",
- "line": 30,
- "order": 1,
- "symbol": "first_commit_each"
- }
- ],
- "strategy": "batch_or_prefetch_io"
- },
- "refactoring_type": "performance_fix",
- "source_biomarker": "io_in_loop",
- "target_symbol": "first_commit_each"
- },
- {
- "blast_radius": {
- "call_sites": 1,
- "file_count": 1,
- "files": [
- "src/app/lone.py"
- ]
- },
- "confidence": "medium",
- "evidence": {
- "affected_files_total": 1,
- "biomarker_type": "io_in_loop",
- "biomarker_types": [
- "io_in_loop"
- ],
- "boundary_kind": "db",
- "execution_context": "production",
- "observations_total": 1,
- "provenance": "call-site",
- "rank_factors": {
- "affected_call_sites": 2,
- "boundary_kind": 4,
- "entry_reachability": 0,
- "execution_context": 3,
- "loop_magnitude": 1,
+ "loop_magnitude": 0,
"multiplier_shape": 4,
"provenance": 3
},
- "rank_score": 17,
+ "rank_score": 16,
"rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
"reliable_entry_reachability": null
},
- "file_path": "src/app/lone.py",
+ "file_path": "src/app/retry.py",
"impact_delta": 0.0,
- "line_end": 11,
- "line_start": 9,
+ "line_end": 52,
+ "line_start": 50,
"plan": {
"affected_locations": [
{
- "file_path": "src/app/lone.py",
- "function_name": "run",
- "line_end": 11,
- "line_start": 9
+ "file_path": "src/app/retry.py",
+ "function_name": "post_with_retry",
+ "line_end": 52,
+ "line_start": 50
}
],
"affected_locations_total": 1,
"api": null,
"evidence_truncated": false,
- "intervention_symbol": null,
+ "intervention_symbol": "src/app/retry.py::post_with_retry",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_f349f0c0ac6827ebfd86",
- "paths": [
- [
- "src/app/db.py::only_sink"
- ]
- ],
+ "opportunity_id": "perf3_bd36a05060a6d02a1245",
+ "paths": [],
"paths_total": 1,
"safety": "advisory",
"steps": [
{
- "action": "Add a form of the shared sink that takes every key at once",
+ "action": "Add a form of the per-key call that takes every key at once",
"applicability": "judgment",
"file_path": null,
"line": null,
@@ -1184,17 +1620,17 @@
{
"action": "Collect the keys before the loop and call the batched form once",
"applicability": "judgment",
- "file_path": "src/app/lone.py",
- "line": 9,
+ "file_path": "src/app/retry.py",
+ "line": 50,
"order": 2,
- "symbol": "run"
+ "symbol": "post_with_retry"
}
],
"strategy": "batch_or_prefetch_io"
},
"refactoring_type": "performance_fix",
"source_biomarker": "io_in_loop",
- "target_symbol": "run"
+ "target_symbol": "src/app/retry.py::post_with_retry"
},
{
"blast_radius": {
@@ -1247,7 +1683,7 @@
"intervention_symbol": "scripts/backfill.py::run",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_626e6b4848d036aede65",
+ "opportunity_id": "perf3_d5225971c0220c77ee7b",
"paths": [
[
"scripts/backfill.py::run",
@@ -1258,12 +1694,12 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of run that takes every key at once",
+ "action": "Add a form of get_session that takes every key at once",
"applicability": "judgment",
- "file_path": "scripts/backfill.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "scripts/backfill.py::run"
+ "symbol": "src/app/db.py::get_session"
},
{
"action": "Collect the keys before the loop and call the batched form once",
@@ -1331,7 +1767,7 @@
"intervention_symbol": "src/app/edge.py::run",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_cf3653d0149e79f7a1fb",
+ "opportunity_id": "perf3_dc2d9734ec9693504602",
"paths": [
[
"src/app/edge.py::run",
@@ -1342,12 +1778,12 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of run that takes every key at once",
+ "action": "Add a form of reliable_sink that takes every key at once",
"applicability": "judgment",
- "file_path": "src/app/edge.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "src/app/edge.py::run"
+ "symbol": "src/app/db.py::reliable_sink"
},
{
"action": "Collect the keys before the loop and call the batched form once",
@@ -1364,85 +1800,6 @@
"source_biomarker": "io_in_loop",
"target_symbol": "src/app/edge.py::run"
},
- {
- "blast_radius": {
- "call_sites": 1,
- "file_count": 1,
- "files": [
- "src/app/retry.py"
- ]
- },
- "confidence": "medium",
- "evidence": {
- "affected_files_total": 1,
- "biomarker_type": "io_in_loop",
- "biomarker_types": [
- "io_in_loop"
- ],
- "boundary_kind": "network",
- "execution_context": "production",
- "observations_total": 1,
- "provenance": "direct",
- "rank_factors": {
- "affected_call_sites": 2,
- "boundary_kind": 4,
- "entry_reachability": 0,
- "execution_context": 3,
- "loop_magnitude": 0,
- "multiplier_shape": 4,
- "provenance": 3
- },
- "rank_score": 16,
- "rationale": "The shared I/O sink is proven; no concrete batch API or result-equivalence proof is available.",
- "reliable_entry_reachability": null
- },
- "file_path": "src/app/retry.py",
- "impact_delta": 0.0,
- "line_end": 52,
- "line_start": 50,
- "plan": {
- "affected_locations": [
- {
- "file_path": "src/app/retry.py",
- "function_name": "post_with_retry",
- "line_end": 52,
- "line_start": 50
- }
- ],
- "affected_locations_total": 1,
- "api": null,
- "evidence_truncated": false,
- "intervention_symbol": null,
- "judgment_steps": 2,
- "mechanical_steps": 0,
- "opportunity_id": "perf3_dc58f1a585a816ec37e9",
- "paths": [],
- "paths_total": 1,
- "safety": "advisory",
- "steps": [
- {
- "action": "Add a form of the shared sink that takes every key at once",
- "applicability": "judgment",
- "file_path": null,
- "line": null,
- "order": 1,
- "symbol": null
- },
- {
- "action": "Collect the keys before the loop and call the batched form once",
- "applicability": "judgment",
- "file_path": "src/app/retry.py",
- "line": 50,
- "order": 2,
- "symbol": "post_with_retry"
- }
- ],
- "strategy": "batch_or_prefetch_io"
- },
- "refactoring_type": "performance_fix",
- "source_biomarker": "io_in_loop",
- "target_symbol": "post_with_retry"
- },
{
"blast_radius": {
"call_sites": 1,
@@ -1494,7 +1851,7 @@
"intervention_symbol": "tests/test_job.py::run",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_b17b10884d21aeeb4df0",
+ "opportunity_id": "perf3_91d25fc7b3e4e8ad00c1",
"paths": [
[
"tests/test_job.py::run",
@@ -1505,12 +1862,12 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of run that takes every key at once",
+ "action": "Add a form of get_session that takes every key at once",
"applicability": "judgment",
- "file_path": "tests/test_job.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "tests/test_job.py::run"
+ "symbol": "src/app/db.py::get_session"
},
{
"action": "Collect the keys before the loop and call the batched form once",
@@ -1578,7 +1935,7 @@
"intervention_symbol": "src/app/guess.py::run",
"judgment_steps": 2,
"mechanical_steps": 0,
- "opportunity_id": "perf3_a817f9001be1d323f8a2",
+ "opportunity_id": "perf3_b4b1621506e7231c520b",
"paths": [
[
"src/app/guess.py::run",
@@ -1589,12 +1946,12 @@
"safety": "advisory",
"steps": [
{
- "action": "Add a form of run that takes every key at once",
+ "action": "Add a form of guessed_sink that takes every key at once",
"applicability": "judgment",
- "file_path": "src/app/guess.py",
+ "file_path": "src/app/db.py",
"line": null,
"order": 1,
- "symbol": "src/app/guess.py::run"
+ "symbol": "src/app/db.py::guessed_sink"
},
{
"action": "Collect the keys before the loop and call the batched form once",
@@ -1659,10 +2016,10 @@
"affected_locations_total": 1,
"api": null,
"evidence_truncated": false,
- "intervention_symbol": null,
+ "intervention_symbol": "src/app/filters.py::select",
"judgment_steps": 1,
"mechanical_steps": 0,
- "opportunity_id": "perf3_6b8f8be1ab10062f0a19",
+ "opportunity_id": "perf3_68f6614ac285d1e8cb4a",
"paths": [],
"paths_total": 1,
"safety": "advisory",
@@ -1680,7 +2037,7 @@
},
"refactoring_type": "performance_fix",
"source_biomarker": "membership_test_against_list_in_loop",
- "target_symbol": "select"
+ "target_symbol": "src/app/filters.py::select"
},
{
"blast_radius": {
@@ -1730,10 +2087,10 @@
"affected_locations_total": 1,
"api": null,
"evidence_truncated": false,
- "intervention_symbol": null,
+ "intervention_symbol": "src/app/render.py::to_csv",
"judgment_steps": 1,
"mechanical_steps": 0,
- "opportunity_id": "perf3_e82f5ad0e9c24fe3d1a1",
+ "opportunity_id": "perf3_ea095ac8d3d612777176",
"paths": [],
"paths_total": 1,
"safety": "advisory",
@@ -1751,7 +2108,7 @@
},
"refactoring_type": "performance_fix",
"source_biomarker": "string_concat_in_loop",
- "target_symbol": "to_csv"
+ "target_symbol": "src/app/render.py::to_csv"
}
]
}
diff --git a/tests/fixtures/perf_corpus/manifest.json b/tests/fixtures/perf_corpus/manifest.json
index 3df7d592d..06aeb9a84 100644
--- a/tests/fixtures/perf_corpus/manifest.json
+++ b/tests/fixtures/perf_corpus/manifest.json
@@ -28,7 +28,10 @@
"batch_form_equivalent",
"batch_form_limited",
"bounded_fan_out",
- "retry_loop"
+ "retry_loop",
+ "one_loop_many_sinks",
+ "one_loop_mixed_shapes",
+ "lazy_load_by_orm"
],
"note": "Database boundary through a shared session/query helper."
},
diff --git a/tests/fixtures/perf_corpus/observations.json b/tests/fixtures/perf_corpus/observations.json
index 5c9cfab63..4e3716cce 100644
--- a/tests/fixtures/perf_corpus/observations.json
+++ b/tests/fixtures/perf_corpus/observations.json
@@ -674,6 +674,146 @@
"reason": "retry_loop: io_in_loop at src/app/retry.py:50 repeats work per iteration.",
"reliable_entry_reachability": null,
"resolution_basis": "direct"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "boundary_kind": "db",
+ "case": "one_loop_many_sinks",
+ "extra": {},
+ "file_path": "src/app/migrate.py",
+ "finding_ref": "one_loop_many_sinks-00",
+ "function_name": "apply",
+ "line_end": 587,
+ "line_start": 587,
+ "path": [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_move"
+ ],
+ "reason": "one_loop_many_sinks: io_in_loop at src/app/migrate.py:587 repeats work per iteration.",
+ "reliable_entry_reachability": true,
+ "resolution_basis": "call-site"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "boundary_kind": "db",
+ "case": "one_loop_many_sinks",
+ "extra": {},
+ "file_path": "src/app/migrate.py",
+ "finding_ref": "one_loop_many_sinks-01",
+ "function_name": "apply",
+ "line_end": 590,
+ "line_start": 590,
+ "path": [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_fold_one"
+ ],
+ "reason": "one_loop_many_sinks: io_in_loop at src/app/migrate.py:590 repeats work per iteration.",
+ "reliable_entry_reachability": true,
+ "resolution_basis": "call-site"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "boundary_kind": "db",
+ "case": "one_loop_many_sinks",
+ "extra": {},
+ "file_path": "src/app/migrate.py",
+ "finding_ref": "one_loop_many_sinks-02",
+ "function_name": "apply",
+ "line_end": 591,
+ "line_start": 591,
+ "path": [
+ "src/app/migrate.py::apply",
+ "src/app/migrate.py::_write_alias"
+ ],
+ "reason": "one_loop_many_sinks: io_in_loop at src/app/migrate.py:591 repeats work per iteration.",
+ "reliable_entry_reachability": true,
+ "resolution_basis": "call-site"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "boundary_kind": "db",
+ "case": "one_loop_mixed_shapes",
+ "extra": {},
+ "file_path": "src/app/jobs.py",
+ "finding_ref": "one_loop_mixed_shapes-00",
+ "function_name": "drain",
+ "line_end": 40,
+ "line_start": 40,
+ "path": [],
+ "reason": "one_loop_mixed_shapes: io_in_loop at src/app/jobs.py:40 repeats work per iteration.",
+ "reliable_entry_reachability": true,
+ "resolution_basis": "direct"
+ },
+ {
+ "biomarker_type": "nested_loop_with_io",
+ "boundary_kind": "db",
+ "case": "one_loop_mixed_shapes",
+ "extra": {},
+ "file_path": "src/app/jobs.py",
+ "finding_ref": "one_loop_mixed_shapes-01",
+ "function_name": "drain",
+ "line_end": 42,
+ "line_start": 42,
+ "path": [],
+ "reason": "one_loop_mixed_shapes: nested_loop_with_io at src/app/jobs.py:42 repeats work per iteration.",
+ "reliable_entry_reachability": true,
+ "resolution_basis": "direct"
+ },
+ {
+ "biomarker_type": "io_in_loop",
+ "boundary_kind": "db",
+ "case": "one_loop_mixed_shapes",
+ "extra": {},
+ "file_path": "src/app/jobs.py",
+ "finding_ref": "one_loop_mixed_shapes-02",
+ "function_name": "drain",
+ "line_end": 44,
+ "line_start": 44,
+ "path": [
+ "src/app/jobs.py::drain",
+ "src/app/db.py::save"
+ ],
+ "reason": "one_loop_mixed_shapes: io_in_loop at src/app/jobs.py:44 repeats work per iteration.",
+ "reliable_entry_reachability": true,
+ "resolution_basis": "call-site"
+ },
+ {
+ "biomarker_type": "lazy_load_in_loop",
+ "boundary_kind": "db",
+ "case": "lazy_load_by_orm",
+ "extra": {
+ "eager_load": "select_related(\"project\")",
+ "orm": "django",
+ "relationship": "Issue.project"
+ },
+ "file_path": "app/issues/views.py",
+ "finding_ref": "lazy_load_by_orm-00",
+ "function_name": "issue_list",
+ "line_end": 30,
+ "line_start": 30,
+ "path": [],
+ "reason": "lazy_load_by_orm: lazy_load_in_loop at app/issues/views.py:30 repeats work per iteration.",
+ "reliable_entry_reachability": null,
+ "resolution_basis": "direct"
+ },
+ {
+ "biomarker_type": "lazy_load_in_loop",
+ "boundary_kind": "db",
+ "case": "lazy_load_by_orm",
+ "extra": {
+ "eager_load": "selectinload(Incident.owner)",
+ "orm": "sqlalchemy",
+ "relationship": "Incident.owner"
+ },
+ "file_path": "app/incidents/service.py",
+ "finding_ref": "lazy_load_by_orm-01",
+ "function_name": "notify_owners",
+ "line_end": 50,
+ "line_start": 50,
+ "path": [],
+ "reason": "lazy_load_by_orm: lazy_load_in_loop at app/incidents/service.py:50 repeats work per iteration.",
+ "reliable_entry_reachability": null,
+ "resolution_basis": "direct"
}
]
}
diff --git a/tests/unit/health/test_fix_first_build.py b/tests/unit/health/test_fix_first_build.py
index 4a5fdc8d7..3e6f0d5bb 100644
--- a/tests/unit/health/test_fix_first_build.py
+++ b/tests/unit/health/test_fix_first_build.py
@@ -40,9 +40,12 @@ def test_each_exclusion_is_counted_by_reason() -> None:
# The test file's plan and its own findings are two candidates.
"test": 2,
"tooling": 1,
+ "unknown": 0,
"generated": 0,
"expected": 1,
- "no_plan": 1,
+ # An investigate cause has no strategy: the perf default queue's reason.
+ "no_strategy": 1,
+ "no_plan": 0,
"below_min_worth": 1,
"history_only": 1,
}
diff --git a/tests/unit/health/test_perf_corpus_golden.py b/tests/unit/health/test_perf_corpus_golden.py
index 95361673e..712557211 100644
--- a/tests/unit/health/test_perf_corpus_golden.py
+++ b/tests/unit/health/test_perf_corpus_golden.py
@@ -14,7 +14,12 @@ from repowise.core.analysis.health.perf.opportunities import (
build_performance_opportunities,
link_performance_findings,
)
-from repowise.core.analysis.health.perf.opportunity_rank import ACTIONABILITY_ORDER
+from repowise.core.analysis.health.perf.opportunity_rank import (
+ ACTIONABILITY_ORDER,
+ DEFAULT_QUEUE_EXCLUSIONS,
+ default_queue_counts,
+ default_queue_exclusion,
+)
from repowise.core.analysis.health.refactoring.performance_fix import (
performance_fix_suggestions,
)
@@ -154,6 +159,12 @@ def test_linking_stamps_the_id_the_builder_derives() -> None:
("reachability_states", 1, {"batch_or_prefetch_io"}),
("unclassified_context", 2, {None}),
("sink_without_caller", 1, {"batch_or_prefetch_io"}),
+ # One loop reaching three sinks is one intervention with three sinks under it.
+ ("one_loop_many_sinks", 1, {"batch_or_prefetch_io"}),
+ # A direct sink, its nested co-signal and a helper call in one loop: one edit.
+ ("one_loop_mixed_shapes", 1, {"batch_or_prefetch_io"}),
+ # One marker, two ORMs: the ORM is a fact on the finding, not an identity.
+ ("lazy_load_by_orm", 2, {"eager_load_relationship"}),
],
)
def test_case_membership_and_actionability(case, expected_groups, expected_strategies) -> None:
@@ -189,11 +200,12 @@ def test_an_unclassifiable_path_is_not_reported_as_production() -> None:
assert contexts == {"unknown"}
-def test_a_path_that_names_no_caller_is_keyed_locally() -> None:
- """A single-node path is a destination with no journey to it."""
+def test_a_path_that_names_no_caller_is_keyed_by_its_loop() -> None:
+ """A single-node path names a sink and no helper, so the loop is the edit."""
item = build_performance_opportunities(rows_for("sink_without_caller"))[0]
- assert item.intervention_symbol is None
- assert item.terminal_sink is None
+ assert item.intervention_symbol == "src/app/lone.py::run"
+ assert item.intervention_kind == "function"
+ assert item.terminal_sink == "src/app/db.py::only_sink"
def test_every_group_reports_an_actionability_state_and_a_reason() -> None:
@@ -207,10 +219,20 @@ def test_every_group_reports_an_actionability_state_and_a_reason() -> None:
assert item.prerequisites, item.opportunity_id
-def test_actionable_groups_sort_above_higher_scoring_evidence() -> None:
- """Raw magnitude must not bury work somebody could start today."""
- order = [item.actionability_state for item in _opportunities()]
- assert order == sorted(order, key=ACTIONABILITY_ORDER.__getitem__)
+def test_value_leads_and_actionability_breaks_a_tie() -> None:
+ """A higher-value cause outranks an easier one; at equal value the plan wins.
+
+ The sibling pass may move a superseded remedy to just after its leader, so
+ the order is checked over items that lead their own position.
+ """
+ ordered = [item for item in _opportunities() if not _follows_a_sibling(item)]
+ keys = [(-item.rank_score, ACTIONABILITY_ORDER[item.actionability_state]) for item in ordered]
+ assert keys == sorted(keys)
+ assert len({item.rank_score for item in ordered}) > 1
+
+
+def _follows_a_sibling(item) -> bool:
+ return any(sibling["relation"] == "preferred" for sibling in item.siblings)
def test_rank_rationale_is_bounded_and_never_pads_with_nothing() -> None:
@@ -273,3 +295,28 @@ def test_a_loop_that_grows_with_data_outranks_a_bounded_one() -> None:
assert grows.facets["loop_magnitude"] == "grows_with_data"
assert bounded.facets["loop_magnitude"] == "bounded"
assert grows.rank_factors["loop_magnitude"] > bounded.rank_factors["loop_magnitude"]
+
+
+def test_the_default_queue_counts_everything_it_leaves_out() -> None:
+ """Production work with a strategy is queued; every other cause has one reason."""
+ items = _opportunities()
+ counts = default_queue_counts(items)
+ assert counts["total"] + sum(counts["excluded"].values()) == len(items)
+ assert tuple(counts["excluded"]) == DEFAULT_QUEUE_EXCLUSIONS
+ # The corpus exercises each reason a real repository produces most.
+ assert all(counts["excluded"][reason] for reason in ("test", "expected", "no_strategy"))
+ for item in items:
+ reason = default_queue_exclusion(item)
+ if reason is None:
+ assert item.execution_context == "production"
+ assert item.fix is not None
+ elif reason == "no_strategy":
+ assert item.fix is None and item.actionability_state == "investigate"
+
+
+def test_a_lazy_load_leads_only_where_its_orm_cleared_the_bar() -> None:
+ by_orm = {
+ item.evidence[0]["file_path"]: item.may_lead
+ for item in build_performance_opportunities(rows_for("lazy_load_by_orm"))
+ }
+ assert by_orm == {"app/issues/views.py": True, "app/incidents/service.py": False}
diff --git a/tests/unit/health/test_perf_identity_contract.py b/tests/unit/health/test_perf_identity_contract.py
index 35043753d..e5ddecfd4 100644
--- a/tests/unit/health/test_perf_identity_contract.py
+++ b/tests/unit/health/test_perf_identity_contract.py
@@ -30,8 +30,10 @@ from repowise.core.analysis.health.refactoring.performance_fix import (
)
# The v3 kernel, pinned. A change to either string is a model-version change.
-CROSS_FUNCTION_ID = "perf3_5662c38bc84c9a677164"
-LOCAL_ID = "perf3_f13beed790fd3cb29ac1"
+# A loop is one cause whether its sink sits in the loop or behind a call, so a
+# same-function row and a two-node cross-function row in ``run`` share one id.
+LOOP_ID = "perf3_50c66a6cb588ad3e8cda"
+HELPER_ID = "perf3_95f1f1ce1ad1162a1399"
def _row(**overrides):
@@ -59,9 +61,13 @@ def _row(**overrides):
def _local_row(**overrides):
- return _row(
- details={"cross_function": False, "path": [], "resolution_basis": "direct"}, **overrides
- )
+ details = {"cross_function": False, "path": [], "resolution_basis": "direct"}
+ return _row(details={**details, **overrides.pop("details", {})}, **overrides)
+
+
+def _helper_row(**overrides):
+ path = ["src/app/a.py::run", "src/app/repo.py::fetch", "src/app/db.py::get_session"]
+ return _row(details={"path": path, **overrides.pop("details", {})}, **overrides)
def test_the_model_version_is_pinned_and_is_carried_by_the_id_prefix() -> None:
@@ -72,15 +78,16 @@ def test_the_model_version_is_pinned_and_is_carried_by_the_id_prefix() -> None:
stale one is told to refresh instead of being handed the wrong group.
"""
assert PERFORMANCE_MODEL_VERSION == 3
- assert opportunity_id_for_finding(_row()) == CROSS_FUNCTION_ID
- assert opportunity_id_for_finding(_local_row()) == LOCAL_ID
- assert CROSS_FUNCTION_ID.startswith(f"perf{PERFORMANCE_MODEL_VERSION}_")
+ assert opportunity_id_for_finding(_row()) == LOOP_ID
+ assert opportunity_id_for_finding(_local_row()) == LOOP_ID
+ assert opportunity_id_for_finding(_helper_row()) == HELPER_ID
+ assert LOOP_ID.startswith(f"perf{PERFORMANCE_MODEL_VERSION}_")
@pytest.mark.parametrize(
("opportunity_id", "state", "version"),
[
- (CROSS_FUNCTION_ID, "current", 3),
+ (LOOP_ID, "current", 3),
("perf2_5662c38bc84c9a677164", "stale_model", 2),
("perf_e358397251b660183fdd", "stale_model", 1),
("perf9_e358397251b660183fdd", "stale_model", 9),
@@ -114,8 +121,9 @@ def test_an_id_reports_its_own_model_and_whether_it_still_resolves(
],
)
def test_display_only_fields_are_outside_the_opportunity_kernel(field, value) -> None:
- assert opportunity_id_for_finding(_row(**{field: value})) == CROSS_FUNCTION_ID
- assert opportunity_id_for_finding(_local_row(**{field: value})) == LOCAL_ID
+ assert opportunity_id_for_finding(_row(**{field: value})) == LOOP_ID
+ assert opportunity_id_for_finding(_local_row(**{field: value})) == LOOP_ID
+ assert opportunity_id_for_finding(_helper_row(**{field: value})) == HELPER_ID
@pytest.mark.parametrize(
@@ -137,7 +145,22 @@ def test_derived_and_ranking_details_are_outside_the_opportunity_kernel(field, v
is deliberately not an identity input, so a call-graph confidence upgrade
does not renumber opportunities.
"""
- assert opportunity_id_for_finding(_row(details={field: value})) == CROSS_FUNCTION_ID
+ assert opportunity_id_for_finding(_row(details={field: value})) == LOOP_ID
+
+
+ ("mutate", "reason"),
+ [
+ ({"file_path": "tests/test_a.py"}, "execution context"),
+ ({"details": {"boundary_kind": "filesystem"}}, "boundary"),
+ ({"function_name": "other"}, "loop owner"),
+ ({"file_path": "src/app/b.py"}, "loop owner's file"),
+ ({"biomarker_type": "membership_test_against_list_in_loop"}, "cost family"),
+ ],
+)
+def test_loop_kernel_inputs_each_move_the_identity(mutate, reason) -> None:
+ assert opportunity_id_for_finding(_row(**copy.deepcopy(mutate))) != LOOP_ID, reason
+ assert opportunity_id_for_finding(_local_row(**copy.deepcopy(mutate))) != LOOP_ID, reason
@pytest.mark.parametrize(
@@ -145,42 +168,100 @@ def test_derived_and_ranking_details_are_outside_the_opportunity_kernel(field, v
[
({"file_path": "tests/test_a.py"}, "execution context"),
({"details": {"boundary_kind": "filesystem"}}, "boundary"),
- ({"details": {"path": ["src/app/a.py::run", "src/app/db.py::other"]}}, "terminal sink"),
(
- {"details": {"path": ["src/app/a.py::other", "src/app/db.py::get_session"]}},
- "meaningful predecessor",
+ {
+ "details": {
+ "path": [
+ "src/app/a.py::run",
+ "src/app/repo.py::other",
+ "src/app/db.py::get_session",
+ ]
+ }
+ },
+ "shared helper",
),
- ({"biomarker_type": "membership_test_against_list_in_loop"}, "cost shape"),
+ ({"biomarker_type": "membership_test_against_list_in_loop"}, "cost family"),
],
)
-def test_cross_function_kernel_inputs_each_move_the_identity(mutate, reason) -> None:
- assert opportunity_id_for_finding(_row(**copy.deepcopy(mutate))) != CROSS_FUNCTION_ID, reason
+def test_shared_helper_kernel_inputs_each_move_the_identity(mutate, reason) -> None:
+ assert opportunity_id_for_finding(_helper_row(**copy.deepcopy(mutate))) != HELPER_ID, reason
+
+ ("row", "expected"),
+ [
+ # The sink is a member's fact: a loop reaching another sink is the same edit.
+ (
+ lambda: _row(details={"path": ["src/app/a.py::run", "src/app/db.py::other"]}),
+ LOOP_ID,
+ ),
+ # Two loops in one function are one edit site.
+ (lambda: _local_row(line_start=40, line_end=41), LOOP_ID),
+ # One cost family: the nested co-signal joins the loop it nests in.
+ (lambda: _local_row(biomarker_type="nested_loop_with_io"), LOOP_ID),
+ # Every caller reaching the helper is the helper's cause.
+ (
+ lambda: _helper_row(
+ file_path="src/app/b.py",
+ function_name="other",
+ details={
+ "path": [
+ "src/app/b.py::other",
+ "src/app/repo.py::fetch",
+ "src/app/db.py::write",
+ ]
+ },
+ ),
+ HELPER_ID,
+ ),
+ ],
+)
+def test_what_is_evidence_under_one_intervention_never_moves_the_identity(row, expected) -> None:
+ assert opportunity_id_for_finding(row()) == expected
-def test_a_new_call_site_behind_the_same_caller_never_changes_the_identity() -> None:
- """The shared cause is the identity; individual call sites are evidence.
- ``file_path``, ``function_name``, and ``line_start`` are kernel inputs for a
- same-function observation and deliberately are not for a cross-function one:
- a second loop in the same caller adds evidence, not a cause.
+def test_one_loop_reaching_three_sinks_is_one_opportunity() -> None:
+ """The ``apply_id_migration`` shape: one loop, three helper calls, three sinks.
+
+ Under the v2 kernel the sink was an identity input, so this was three
+ opportunities differing only in their last path node.
"""
- original = _row()
- same_caller = _row(line_start=77, line_end=79)
- assert opportunity_id_for_finding(same_caller) == CROSS_FUNCTION_ID
- assert len(build_performance_opportunities([original, same_caller])) == 1
+ rows = [
+ _row(line_start=line, details={"path": ["src/app/a.py::run", f"src/app/db.py::{sink}"]})
+ for line, sink in ((10, "fold"), (11, "write_alias"), (12, "move"))
+ ]
+ (opportunity,) = build_performance_opportunities(rows)
+ assert opportunity.opportunity_id == LOOP_ID
+ assert opportunity.intervention_symbol == "src/app/a.py::run"
+ assert opportunity.intervention_kind == "function"
+ assert opportunity.terminal_sinks == (
+ "src/app/db.py::fold",
+ "src/app/db.py::move",
+ "src/app/db.py::write_alias",
+ )
+ # No one sink is shared, so none is claimed.
+ assert opportunity.terminal_sink is None
+ assert opportunity.affected_call_sites_total == 3
+
+
+def test_a_loop_with_a_direct_sink_and_a_helper_call_is_one_opportunity() -> None:
+ (opportunity,) = build_performance_opportunities([_row(), _local_row(line_start=11)])
+ assert opportunity.opportunity_id == LOOP_ID
+ assert opportunity.terminal_sinks == ("src/app/db.py::get_session",)
+ assert opportunity.terminal_sink == "src/app/db.py::get_session"
def test_an_unrelated_caller_on_the_same_sink_is_a_different_cause() -> None:
"""A shared destination is not a shared cause.
Naming a group by its sink alone merged every workflow that happened to
- open a session. Requiring the caller to match splits those, while callers
+ open a session. Each loop owner is its own intervention, while callers
that reach the sink through one helper stay together.
"""
original = _row()
unrelated = _row(file_path="src/app/b.py", function_name="other", line_start=77)
unrelated["details"]["path"] = ["src/app/b.py::other", "src/app/db.py::get_session"]
- assert opportunity_id_for_finding(unrelated) != CROSS_FUNCTION_ID
+ assert opportunity_id_for_finding(unrelated) != LOOP_ID
assert len(build_performance_opportunities([original, unrelated])) == 2
through_helper = [_row(), _row(file_path="src/app/b.py", function_name="other")]
@@ -193,47 +274,33 @@ def test_an_unrelated_caller_on_the_same_sink_is_a_different_cause() -> None:
merged = build_performance_opportunities(through_helper)
assert len(merged) == 1
assert merged[0].intervention_symbol == "src/app/repo.py::fetch"
+ assert merged[0].intervention_kind == "shared_helper"
@pytest.mark.parametrize(
- "mutate",
- [
- {"file_path": "src/app/b.py"},
- {"function_name": "other"},
- {"line_start": 11},
- {"biomarker_type": "nested_loop_with_io"},
- ],
+ "path", [[], [5], [None], [""], ["", "src/app/db.py::get_session"], ["src/app/db.py::get_session"]]
)
-def test_local_kernel_inputs_each_move_the_identity(mutate) -> None:
- assert opportunity_id_for_finding(_local_row(**mutate)) != LOCAL_ID
-
+def test_a_cross_function_flag_without_a_named_caller_is_keyed_by_its_loop(path) -> None:
+ """The flag alone does not name a shared helper.
-def test_the_cost_shape_merge_applies_to_cross_function_identity_only() -> None:
- """``io_in_loop`` and ``nested_loop_with_io`` share one cross-function cause.
-
- The local kernel keeps the literal marker. The asymmetry is deliberate and
- load-bearing: a split that unified the two branches would regroup the whole
- repository.
+ A path with nothing usable in it, or with only the sink, names no caller,
+ so the observation is keyed by the function holding its loop.
"""
- nested = _row(biomarker_type="nested_loop_with_io")
- assert opportunity_id_for_finding(nested) == CROSS_FUNCTION_ID
- assert opportunity_id_for_finding(_local_row(biomarker_type="nested_loop_with_io")) != LOCAL_ID
+ row = _row(details={"path": path})
+ assert opportunity_id_for_finding(row) == LOOP_ID
- "path", [[], [5], [None], [""], ["", "src/app/db.py::get_session"], ["src/app/db.py::get_session"]]
-)
-def test_a_cross_function_flag_without_a_named_caller_falls_back_to_the_local_kernel(
- path,
-) -> None:
- """The flag alone does not make an observation cross-function.
+def test_every_opportunity_names_where_to_edit() -> None:
+ """No anonymous rows: a loop names its function, top-level code its module."""
+ (in_function,) = build_performance_opportunities([_local_row()])
+ assert in_function.intervention_symbol == "src/app/a.py::run"
+ assert in_function.intervention_kind == "function"
- A cause needs both ends: a sink that pays the cost and a caller that
- repeats it. A path with nothing usable in it, or with only the sink, names
- one end, so the observation is keyed by its own location instead.
- """
- row = _row(details={"path": path})
- assert opportunity_id_for_finding(row) == LOCAL_ID
+ (top_level,) = build_performance_opportunities(
+ [_local_row(file_path="scripts/backfill.py", function_name=None)]
+ )
+ assert top_level.intervention_symbol == "scripts/backfill.py::__module__"
+ assert top_level.intervention_kind == "module"
def _shared_helper_rows():
@@ -289,7 +356,7 @@ def test_evidence_is_addressed_by_a_content_derived_public_reference() -> None:
"finding_already_stored"
)
link_performance_findings([persisted])
- assert persisted["details"]["opportunity_id"] == CROSS_FUNCTION_ID
+ assert persisted["details"]["opportunity_id"] == LOOP_ID
def test_the_public_finding_id_ignores_prose_and_derived_details() -> None:
@@ -311,9 +378,8 @@ def test_the_public_finding_id_ignores_prose_and_derived_details() -> None:
def test_a_path_node_that_names_nothing_never_becomes_an_intervention_symbol() -> None:
- """An empty node is absence, not a symbol called \"\"."""
+ """An empty node is absence, not a symbol called \"\"; the loop is named instead."""
row = _row(details={"path": ["", "src/app/db.py::get_session"]})
opportunity = build_performance_opportunities([row])[0]
- assert opportunity.intervention_symbol is None
- assert opportunity.terminal_sink is None
- assert opportunity.opportunity_id == LOCAL_ID
+ assert opportunity.intervention_symbol == "src/app/a.py::run"
+ assert opportunity.opportunity_id == LOOP_ID
diff --git a/tests/unit/health/test_perf_io_in_loop.py b/tests/unit/health/test_perf_io_in_loop.py
index 7b9784fba..1e60a9f13 100644
--- a/tests/unit/health/test_perf_io_in_loop.py
+++ b/tests/unit/health/test_perf_io_in_loop.py
@@ -440,3 +440,47 @@ def test_a_sink_in_a_chunked_loop_carries_the_fact(header: str, chunked: bool):
assert all((h.loop is not None and h.loop.chunked) is chunked for h in loop_hits)
finding = IoInLoopDetector().detect(_ctx(loop_hits))[0]
assert finding.details.get("chunked_iteration", False) is chunked
+
+
+ ("source", "expected"),
+ [
+ # A function bound to a name is named for it.
+ (
+ "const build = (parts: string[]) => {\n"
+ " for (const p of parts) {\n"
+ " fs.readFileSync(p)\n"
+ " }\n"
+ "}\n",
+ "build",
+ ),
+ # A callback is named for the call it is passed to, as the walker names it.
+ (
+ "it('reads', () => {\n"
+ " for (const p of parts) {\n"
+ " fs.readFileSync(p)\n"
+ " }\n"
+ "})\n",
+ "it callback",
+ ),
+ # A lambda inside a named function keeps that function's name.
+ (
+ "function render(parts: string[]) {\n"
+ " return parts.map((p) => {\n"
+ " for (const c of p) {\n"
+ " fs.readFileSync(c)\n"
+ " }\n"
+ " })\n"
+ "}\n",
+ "render",
+ ),
+ # Top-level script code has no function to name.
+ ("for (const p of parts) {\n fs.readFileSync(p)\n}\n", None),
+ ],
+)
+def test_a_hit_is_named_for_its_enclosing_function(source: str, expected: str | None):
+ fc = walk_file("f.ts", "typescript", source.encode())
+ hits = [h for h in fc.perf_hits if h.kind == "io_in_loop"]
+ if not hits:
+ pytest.skip("typescript grammar unavailable")
+ assert {h.function for h in hits} == {expected}
diff --git a/tests/unit/health/test_perf_lazy_load.py b/tests/unit/health/test_perf_lazy_load.py
index 709d0a38b..d53739efa 100644
--- a/tests/unit/health/test_perf_lazy_load.py
+++ b/tests/unit/health/test_perf_lazy_load.py
@@ -78,7 +78,7 @@ def test_sa_query_filter_all(tmp_path: Path):
assert len(hits) == 1
assert hits[0].function == "f"
assert hits[0].detail == "db"
- assert hits[0].path == ("Incident.owner", "selectinload(Incident.owner)")
+ assert hits[0].path == ("Incident.owner", "selectinload(Incident.owner)", "sqlalchemy")
assert hits[0].loop is not None
assert hits[0].loop.magnitude == "grows_with_data"
@@ -97,7 +97,7 @@ def test_sa_flask_query_filter_by(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Users.profile", "selectinload(Users.profile)")
+ assert hits[0].path == ("Users.profile", "selectinload(Users.profile)", "sqlalchemy")
def test_sa_select_via_scalars(tmp_path: Path):
@@ -115,7 +115,7 @@ def test_sa_select_via_scalars(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Build.repo", "selectinload(Build.repo)")
+ assert hits[0].path == ("Build.repo", "selectinload(Build.repo)", "sqlalchemy")
def test_sa_execute_scalars(tmp_path: Path):
@@ -148,7 +148,7 @@ def test_sa_mapped_relationship(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Team.members", "selectinload(Team.members)")
+ assert hits[0].path == ("Team.members", "selectinload(Team.members)", "sqlalchemy")
def test_sa_declared_attr_on_mixin(tmp_path: Path):
@@ -170,7 +170,7 @@ def test_sa_declared_attr_on_mixin(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Incident.owner", "selectinload(Incident.owner)")
+ assert hits[0].path == ("Incident.owner", "selectinload(Incident.owner)", "sqlalchemy")
def test_sa_backref(tmp_path: Path):
@@ -190,7 +190,7 @@ def test_sa_backref(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Child.parent", "selectinload(Child.parent)")
+ assert hits[0].path == ("Child.parent", "selectinload(Child.parent)", "sqlalchemy")
def test_sa_lazy_dynamic(tmp_path: Path):
@@ -459,7 +459,7 @@ def test_django_objects_filter(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Issue.project", 'select_related("project")')
+ assert hits[0].path == ("Issue.project", 'select_related("project")', "django")
assert hits[0].loop.magnitude == "grows_with_data"
@@ -483,7 +483,7 @@ def test_django_reverse_default_related_name(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Project.issue_set", 'prefetch_related("issue_set")')
+ assert hits[0].path == ("Project.issue_set", 'prefetch_related("issue_set")', "django")
def test_django_related_name(tmp_path: Path):
@@ -504,7 +504,7 @@ def test_django_related_name(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Project.issues", 'prefetch_related("issues")')
+ assert hits[0].path == ("Project.issues", 'prefetch_related("issues")', "django")
def test_django_m2m_all(tmp_path: Path):
@@ -522,7 +522,7 @@ def test_django_m2m_all(tmp_path: Path):
""",
)
assert len(hits) == 1
- assert hits[0].path == ("Issue.tags", 'prefetch_related("tags")')
+ assert hits[0].path == ("Issue.tags", 'prefetch_related("tags")', "django")
def test_django_refinement(tmp_path: Path):
diff --git a/tests/unit/health/test_perf_opportunities.py b/tests/unit/health/test_perf_opportunities.py
index 40215aa47..af5bfc035 100644
--- a/tests/unit/health/test_perf_opportunities.py
+++ b/tests/unit/health/test_perf_opportunities.py
@@ -1,5 +1,7 @@
from __future__ import annotations
+import pytest
+
from repowise.core.analysis.health.models import HealthFindingData, Severity
from repowise.core.analysis.health.perf.opportunities import (
build_performance_opportunities,
@@ -426,7 +428,34 @@ def test_a_plan_lists_its_edits_and_marks_only_proven_ones_mechanical():
parallel_plan = performance_fix_suggestions(proven)[0].plan
assert [step["order"] for step in batch_plan["steps"]] == [1, 2]
- assert batch_plan["steps"][0]["symbol"] == "a.py::run"
+ # The bulk form goes on the callee the loop repeats, not on the loop's owner.
+ assert batch_plan["steps"][0]["symbol"] == "db.py::fetch"
+ assert batch_plan["intervention_symbol"] == "a.py::run"
assert batch_plan["steps"][1]["line"] == 2
assert (batch_plan["mechanical_steps"], batch_plan["judgment_steps"]) == (0, 2)
assert (parallel_plan["mechanical_steps"], parallel_plan["judgment_steps"]) == (1, 0)
+
+
+ ("orms", "leads"),
+ [
+ (("django",), True),
+ (("sqlalchemy",), False),
+ # One unmeasured member keeps the group from leading.
+ (("django", "sqlalchemy"), False),
+ # A store written before the ORM was recorded.
+ ((None,), False),
+ ],
+)
+def test_a_lazy_load_may_lead_only_on_an_orm_that_cleared_the_bar(orms, leads):
+ rows = [
+ _finding("app/views.py", 10 + index, marker="lazy_load_in_loop", orm=orm)
+ for index, orm in enumerate(orms)
+ ]
+ (opportunity,) = build_performance_opportunities(rows)
+ assert opportunity.may_lead is leads
+
+
+def test_every_other_marker_may_lead():
+ (opportunity,) = build_performance_opportunities([_finding("a.py", 1)])
+ assert opportunity.may_lead is True
diff --git a/tests/unit/health/test_scoring_dimensions.py b/tests/unit/health/test_scoring_dimensions.py
index b1a099ba4..e945b1b3b 100644
--- a/tests/unit/health/test_scoring_dimensions.py
+++ b/tests/unit/health/test_scoring_dimensions.py
@@ -17,6 +17,10 @@ still pins the whole algorithm.
from __future__ import annotations
+from dataclasses import replace
+
+import pytest
+
from repowise.core.analysis.health.biomarkers.base import BiomarkerResult
from repowise.core.analysis.health.models import Severity
from repowise.core.analysis.health.scoring import (
@@ -313,6 +317,21 @@ def test_perf_bonus_markers_advisory_weight():
assert s2["performance"] == round(10.0 - 0.49, 2)
+ ("orm", "weight"),
+ [("django", 0.7), ("sqlalchemy", 0.4), (None, 0.4)],
+)
+def test_lazy_load_weight_is_read_per_finding_from_its_orm(orm, weight):
+ """Django cleared its held-out bar; SQLAlchemy and an unrecorded ORM did not."""
+ finding = replace(
+ _r("lazy_load_in_loop", Severity.LOW), details={} if orm is None else {"orm": orm}
+ )
+ scores, deductions = score_file([finding])
+ assert scores["performance"] == round(10.0 - 0.3 * weight, 2)
+ assert scores["defect"] == 10.0
+ assert deductions == [0.0]
+
+
def test_perf_home_dimension():
assert biomarker_dimension("io_in_loop") == "performance"
assert biomarker_dimension("string_concat_in_loop") == "performance"
diff --git a/tests/unit/persistence/test_full_health_report_writer.py b/tests/unit/persistence/test_full_health_report_writer.py
index 9eb553b2b..15333b6cd 100644
--- a/tests/unit/persistence/test_full_health_report_writer.py
+++ b/tests/unit/persistence/test_full_health_report_writer.py
@@ -24,7 +24,11 @@ from tests.unit.persistence.helpers import insert_repo
def _perf_finding(
- line: int, *, path: str = "src/app.py", sink: str = "src/db.py::fetch"
+ line: int,
+ *,
+ path: str = "src/app.py",
+ helper: str = "src/shared.py::load",
+ sink: str = "src/db.py::fetch",
) -> HealthFindingData:
return HealthFindingData(
biomarker_type="serial_await_in_loop",
@@ -36,7 +40,7 @@ def _perf_finding(
details={
"boundary_kind": "db",
"cross_function": True,
- "path": [f"{path}::run", "src/shared.py::load", sink],
+ "path": [f"{path}::run", helper, sink],
"resolution_basis": "call-site",
"dataflow_verified": True,
},
@@ -108,14 +112,21 @@ class TestSaveFullHealthReport:
before = await _open_perf_ids(async_session, repo_id)
assert len(before) == 1
- # The repeated work now lands on a different sink, which is a
- # different cause. The re-score deleted the finding the first one was
- # built from, so the queue must stop serving it.
+ # The repeated work now goes through a different helper to a different
+ # sink, which is a different cause. The re-score deleted the finding the
+ # first one was built from, so the queue must stop serving it.
await save_full_health_report(
async_session,
repo_id,
_report(
- [_perf_finding(10, path="src/other.py", sink="src/cache.py::lookup")],
+ [
+ _perf_finding(
+ 10,
+ path="src/other.py",
+ helper="src/cache.py::cached",
+ sink="src/cache.py::lookup",
+ )
+ ],
metrics=[_metric("src/other.py")],
),
analyzed_commit="b" * 40,
diff --git a/tests/unit/persistence/test_performance_materialization.py b/tests/unit/persistence/test_performance_materialization.py
index 76a6482c1..73c11ed53 100644
--- a/tests/unit/persistence/test_performance_materialization.py
+++ b/tests/unit/persistence/test_performance_materialization.py
@@ -377,15 +377,15 @@ def test_a_non_leading_marker_never_leads_the_summary():
from repowise.core.persistence.crud.analysis.performance import _summary_payload
- def _opp(oid: str, marker: str):
+ def _opp(oid: str, marker: str, may_lead: bool):
return SimpleNamespace(
opportunity_id=oid, actionability_state="advisory", biomarker_type=marker,
boundary_kind="db", execution_context="production", intervention_symbol=None,
terminal_sink=None, evidence=[{"file_path": "a.py"}], observations_total=1,
affected_call_sites_total=1, affected_files_total=1, why_ranked=[],
- prerequisites=(), actionability_reason="",
+ prerequisites=(), actionability_reason="", may_lead=may_lead,
)
- ranked = [_opp("lazy", "lazy_load_in_loop"), _opp("io", "io_in_loop")]
+ ranked = [_opp("lazy", "lazy_load_in_loop", False), _opp("io", "io_in_loop", True)]
assert _summary_payload(ranked, {})["lead"]["opportunity_id"] == "io"
assert _summary_payload(ranked[:1], {})["lead"] is None
diff --git a/tests/unit/server/mcp/test_performance_levels.py b/tests/unit/server/mcp/test_performance_levels.py
index f084f4d05..17403e76d 100644
--- a/tests/unit/server/mcp/test_performance_levels.py
+++ b/tests/unit/server/mcp/test_performance_levels.py
@@ -349,7 +349,7 @@ async def test_the_summary_costs_the_same_however_many_causes_there_are(
for index in range(40):
row = _row(materialized, f"src/bulk_{index}.py", 500 + index)
row.details_json = row.details_json.replace(
- "src/db.py::fetch", f"src/db.py::fetch_{index}"
+ "src/shared.py::load", f"src/shared.py::load_{index}"
)
session.add(row)
await session.flush()
@@ -413,10 +413,10 @@ async def test_the_queue_costs_the_same_however_many_opportunities_there_are(
await get_health(include=["performance"], only=["performance_opportunities"], limit=2)
for index in range(40):
- # A distinct sink per row, so these are forty causes rather than one.
+ # A distinct helper per row, so these are forty causes rather than one.
row = _row(materialized, f"src/bulk_{index}.py", 500 + index)
row.details_json = row.details_json.replace(
- "src/db.py::fetch", f"src/db.py::fetch_{index}"
+ "src/shared.py::load", f"src/shared.py::load_{index}"
)
session.add(row)
await session.flush()
diff --git a/tests/unit/server/test_performance_opportunities.py b/tests/unit/server/test_performance_opportunities.py
index 0c42940f3..7775b614b 100644
--- a/tests/unit/server/test_performance_opportunities.py
+++ b/tests/unit/server/test_performance_opportunities.py
@@ -52,6 +52,11 @@ def _findings() -> list:
]
+def _two_production_causes() -> list:
+ """The shared-helper cause above plus a one-site production loop, both queued."""
+ return [*_findings(), _finding("src/c.py", 40, ["src/c.py::run", "src/db.py::fetch"])]
+
+
async def _materialize(app, repo_id: str, findings: list) -> None:
link_performance_findings(findings)
async with app.state.session_factory() as session:
@@ -133,7 +138,9 @@ async def test_opportunities_are_grouped_bounded_and_split_by_context(
assert every["summary"]["repository_total"] == 2
assert every["summary"]["context"] == {"production": 1, "test": 1}
- test_page = await _page(client, repo_id, context="test")
+ # The test-suite cause has no strategy, so it is asked for, not queued.
+ assert (await _page(client, repo_id, context="test"))["total"] == 0
+ test_page = await _page(client, repo_id, context="test", actionability="investigate")
assert test_page["total"] == 1
assert test_page["items"][0]["plan_id"] is None
assert test_page["items"][0]["plan_status"] == "no_safe_plan"
@@ -290,6 +297,37 @@ async def test_expected_sits_out_of_the_default_queue_but_not_the_facet(
assert only_expected["items"][0]["actionability_reason"] == "inherent_to_boundary"
+async def test_the_default_queue_reports_what_it_leaves_out(app, client: AsyncClient) -> None:
+ """No strategy, expected, and non-production causes are counted, never dropped."""
+ no_strategy = HealthFindingData(
+ biomarker_type="resource_construction_in_loop",
+ severity=Severity.MEDIUM,
+ file_path="src/clients.py",
+ function_name="each",
+ line_start=5,
+ line_end=5,
+ details={"boundary_kind": "network"},
+ health_impact=0.0,
+ reason="A client is built for every loop iteration.",
+ dimension="performance",
+ )
+ findings = [
+ *_findings(),
+ no_strategy,
+ _filesystem_finding("src/fs.py", 1, ["src/fs.py::run", "src/fs.py::read"]),
+ ]
+ repo_id, _ = await _seed(app, client, findings)
+
+ default = await _page(client, repo_id)
+ assert [item["intervention_symbol"] for item in default["items"]] == ["src/shared.py::load"]
+ assert default["summary"]["default_queue"] == {
+ "total": 1,
+ "excluded": {"test": 1, "tooling": 0, "unknown": 0, "expected": 1, "no_strategy": 1},
+ }
+ asked = await _page(client, repo_id, actionability="investigate")
+ assert [item["intervention_symbol"] for item in asked["items"]] == ["src/clients.py::each"]
+
+
async def test_an_expected_row_never_leads(app, client: AsyncClient) -> None:
import json
@@ -300,6 +338,7 @@ async def test_an_expected_row_never_leads(app, client: AsyncClient) -> None:
summary = json.loads(row.summary_json)
assert summary["lead"] is None
assert summary["actionability"] == {"expected": 1}
+ assert summary["default_queue"]["excluded"]["expected"] == 1
async def test_an_id_from_an_older_model_reports_stale_rather_than_no_plan(
@@ -368,11 +407,16 @@ async def test_an_alternative_order_is_applied_before_the_page_not_after(
app, client: AsyncClient
) -> None:
"""Sorting the fetched page would order twenty rows right and the repo wrong."""
- repo_id, opportunity_id = await _seed(app, client)
+ repo_id, _ = await _seed(app, client, _two_production_causes())
+ opportunity_id = next(
+ item["opportunity_id"]
+ for item in (await _page(client, repo_id))["items"]
+ if item["intervention_symbol"] == "src/shared.py::load"
+ )
by_leverage = await _page(client, repo_id, context="all", sort="leverage", limit=1)
assert by_leverage["total"] == 2
- # The production cause carries two call sites; the test one carries a
- # single site, so leverage puts production first whatever its rank is.
+ # The shared-helper cause carries two call sites and the other one, so
+ # leverage puts it first whatever its rank is.
assert by_leverage["items"][0]["opportunity_id"] == opportunity_id
assert by_leverage["items"][0]["affected_call_sites_total"] == 2
@@ -405,7 +449,8 @@ async def test_a_page_costs_the_page_not_the_repository(app, client: AsyncClient
await session.commit()
page = await _page(client, repo_id, context="all", limit=1)
- assert page["total"] == 2
+ # The test-suite cause has no strategy: counted, not queued.
+ assert page["total"] == 1
assert len(page["items"]) == 1
assert page["summary"]["total"] == 2
@@ -417,7 +462,7 @@ async def test_the_queue_scopes_to_one_file_on_the_server(app, client):
causes and no others. Narrowing a page it already received would show
whatever survived the cap, which is not the same question.
"""
- repo_id, _ = await _seed(app, client)
+ repo_id, _ = await _seed(app, client, _two_production_causes())
whole = await _page(client, repo_id, context="all")
# Scope to whichever file the grouping named as the place to intervene: the
# column is the intervention site, not every file the evidence touches.