Repository navigation
Description
Version
codebase-memory-mcp dev
Platform
Linux (x64)
Install channel
Built from source
Binary variant
standard
What happened, and what did you expect?
A Python call through a dynamically selected strategy is stored as a single concrete CALLS edge to the SD3 implementation, even though the resolver reports five candidates and very low confidence:
callee: Sd3DiffusionTrainingStrategy.process_batch
strategy: suffix_match
confidence: 0.17
candidates: 5
trace_path consequently reports only SD3 as the callee of _run_epoch_steps().
The graph already contains the relevant polymorphic relationships: OVERRIDE edges correctly connect the SD, SD3, SDXL, and test implementations to the abstract DiffusionTrainingStrategy.process_batch contract. However, the call-site trace does not use those relationships and presents the heuristic SD3 selection as the sole target.
The runtime concrete type is selected from configuration, so a static analyzer cannot identify one target. I expected conservative behavior instead:
- Link the call to the abstract
DiffusionTrainingStrategy.process_batchmethod and optionally expand inboundOVERRIDEedges; or - Return all possible implementation targets / preserve the ambiguity in
trace_path.
Selecting one concrete override is misleading for caller/callee tracing and impact analysis.
This appears related to the graph/traversal correctness umbrella #594 and the general instance-method resolution area in #1153, but it is not the same failure: the CALLS edge exists here and points to a function; it is the wrong single polymorphic target.
Reproduction
Public source
Repository and commit:
- https://github.com/Enferlain/sd-scripts/tree/de2dd0ebae40174e8336157e8928e36cfd013284
- Call site: https://github.com/Enferlain/sd-scripts/blob/de2dd0ebae40174e8336157e8928e36cfd013284/library/training/phases/training_loop.py#L461-L520
- Trainer field assignment and type: https://github.com/Enferlain/sd-scripts/blob/de2dd0ebae40174e8336157e8928e36cfd013284/library/training/runners/trainer.py#L130-L148
- Dynamic strategy registry: https://github.com/Enferlain/sd-scripts/blob/de2dd0ebae40174e8336157e8928e36cfd013284/library/strategies/factory.py#L13-L34
- Abstract method: https://github.com/Enferlain/sd-scripts/blob/de2dd0ebae40174e8336157e8928e36cfd013284/library/strategies/base/contracts.py#L376-L403
The relevant pattern is:
def _run_epoch_steps(trainer: Trainer, *, epoch_ctx: EpochContext):
strategies = trainer.strategies
# ...
batch_loss = strategies.process_batch(...)Trainer.__init__ receives strategies: TrainingStrategy and assigns self.strategies = strategies. The factory returns one of SdTrainingStrategy, SdxlTrainingStrategy, or Sd3TrainingStrategy based on cfg.model.model_type. Each top-level class receives process_batch through a model-family diffusion-strategy mixin.
Index
Run a full index of the repository. The reproduced index reported:
12,095 nodes / 70,815 edges
coverage_version: 1
generation_matches: true
All source paths cited above returned no_recorded_issue from check_index_coverage.
Find the caller
{
"project": "home-imi-Projects-sd-scripts",
"name_pattern": ".*_run_epoch_steps.*",
"limit": 50,
"format": "json"
}Qualified name:
home-imi-Projects-sd-scripts.library.training.phases.training_loop._run_epoch_steps
Inspect its direct CALLS edges
{
"project": "home-imi-Projects-sd-scripts",
"query": "MATCH (a)-[r:CALLS]->(b) WHERE a.qualified_name = \"home-imi-Projects-sd-scripts.library.training.phases.training_loop._run_epoch_steps\" RETURN b.name, b.qualified_name, r.line, r.callee, r.strategy, r.confidence, r.candidates ORDER BY r.line"
}Relevant row:
process_batch
home-imi-Projects-sd-scripts.library.strategies.sd3.diffusion.Sd3DiffusionTrainingStrategy.process_batch
line=506
callee=strategies.process_batch
strategy=suffix_match
confidence=0.17
candidates=5
Trace the caller
{
"project": "home-imi-Projects-sd-scripts",
"function_name": "home-imi-Projects-sd-scripts.library.training.phases.training_loop._run_epoch_steps",
"direction": "outbound",
"depth": 1,
"limit": 100,
"include_tests": true,
"format": "json",
"mode": "calls"
}Actual result includes only:
home-imi-Projects-sd-scripts.library.strategies.sd3.diffusion.Sd3DiffusionTrainingStrategy.process_batch
It omits the abstract contract and the SD/SDXL possible implementations.
Verify that the graph knows the overrides
{
"project": "home-imi-Projects-sd-scripts",
"query": "MATCH (s)-[r:OVERRIDE]->(i) WHERE s.name = 'process_batch' OR i.name = 'process_batch' RETURN s.qualified_name, i.qualified_name LIMIT 100"
}Actual result correctly includes:
SdDiffusionTrainingStrategy.process_batch -> DiffusionTrainingStrategy.process_batch
Sd3DiffusionTrainingStrategy.process_batch -> DiffusionTrainingStrategy.process_batch
SdxlDiffusionTrainingStrategy.process_batch -> DiffusionTrainingStrategy.process_batch
_DummyDiffusionStrategy.process_batch -> DiffusionTrainingStrategy.process_batch
A manual override trace also works:
{
"project": "home-imi-Projects-sd-scripts",
"function_name": "home-imi-Projects-sd-scripts.library.strategies.base.contracts.DiffusionTrainingStrategy.process_batch",
"direction": "inbound",
"depth": 1,
"limit": 50,
"include_tests": true,
"format": "json",
"mode": "calls",
"edge_types": ["OVERRIDE"]
}That returns all four override methods. The information needed for a conservative polymorphic answer is therefore present in the graph, but it is not connected to or expanded from the call-site trace.
Confirmed resolver behavior
Further investigation confirms that the incorrect single target is introduced while constructing the CALLS edge, rather than by trace_path.
When Python receiver/type resolution does not yield a target, the call-resolution pass falls back to the generic registry. For a same-name candidate set between 2 and 256 entries, resolve_name_lookup() / resolve_multi_with_imports() select one candidate using best_by_import_distance(). If imports do not identify a target, the scoring falls back to namespace proximity; ties select one registry candidate. The result is still emitted as an ordinary CALLS edge.
The candidate penalty only lowers edge metadata such as:
strategy=suffix_match
confidence=0.17
candidates=5
It does not preserve the candidate set, link the call to the abstract contract, or prevent the speculative concrete target from being stored. Once the graph contains only the SD3 edge, trace_path has no representation of the discarded alternatives to expand. It also does not expose the confidence/candidate metadata in its normal result, so the target appears more certain than it is.
This means the failure has two connected parts:
- edge construction collapses an unresolved polymorphic call to one concrete override; and
- traversal presents that speculative edge without surfacing its ambiguity.
A regression test should exercise the complete extraction-to-graph-to-traversal path, not only the intermediate resolver result. Given an abstract/base-typed receiver with multiple overrides, it should verify that the graph does not represent one low-confidence suffix match as the sole concrete target. Acceptable conservative outcomes include an edge to the abstract method with optional OVERRIDE expansion, an explicit multi-target/ambiguous representation, or an unresolved call that retains its candidate metadata.
Impact
Low-confidence attribute calls can silently produce incorrect impact sets. A user asking what _run_epoch_steps() calls is told that it calls only the SD3 implementation, even though SD and SDXL are valid runtime targets.
The current workaround is to inspect the CALLS edge metadata, recognize suffix_match plus candidates > 1, locate the abstract method, and separately trace inbound OVERRIDE edges.
Logs
No runtime errors were emitted. This is a graph correctness issue visible in the structured edge properties and traversal output.
Project scale
12,095 nodes / 70,815 edges / 801 indexed files
Confirmations
- I searched existing issues and this is not a duplicate.
- My reproduction uses shareable code from a public OSS repository, not proprietary code.
Independent trace-only reproducer
A smaller controlled fixture confirms that dispatch-aware traversal is independently missing even when receiver inference and CALLS construction are correct.
from abc import ABC, abstractmethod
class LocalProcessor(ABC):
@abstractmethod
def process(self) -> str:
raise NotImplementedError
class LocalAlphaProcessor(LocalProcessor):
def process(self) -> str:
return "alpha"
class LocalBetaProcessor(LocalProcessor):
def process(self) -> str:
return "beta"
def run_local(processor: LocalProcessor) -> str:
return processor.process()A fresh full index produced the correct canonical call:
run_local -> LocalProcessor.process
confidence=0.90
strategy=lsp_method
It also produced both direct override relations:
LocalAlphaProcessor.process -> LocalProcessor.process [OVERRIDE]
LocalBetaProcessor.process -> LocalProcessor.process [OVERRIDE]
However, outbound trace_path from run_local returned only LocalProcessor.process. Supplying both edge types did not expand the possible implementations:
{
"function_name": "fixture.single_file.run_local",
"direction": "outbound",
"depth": 3,
"mode": "calls",
"edge_types": ["CALLS", "OVERRIDE"]
}Tracing inbound from LocalAlphaProcessor.process likewise reported zero callers. A manual mixed-direction query returned both candidates:
MATCH (caller:Function)-[c:CALLS]->(base:Method)<-[o:OVERRIDE]-(impl:Method)
WHERE caller.name = 'run_local'
RETURN caller.qualified_name, base.qualified_name, impl.qualified_nameThis proves the traversal problem is not only a consequence of the bad suffix_match edge in the original reproduction. The graph has enough information, but generic BFS follows one direction for every selected edge and cannot perform the dispatch path:
caller -CALLS-> contract <-OVERRIDE- possible implementations
The preferred representation is one canonical CALLS edge to the statically known contract plus dispatch-aware expansion in tracing, with declared and possible targets distinguished. Ordinary CALLS edges should not be duplicated to every override because that would present possible runtime targets as definite calls.
Activity
DeusData commentedon Jul 28, 2026
Thanks for following the failure from edge construction through traversal and then adding the smaller dispatch-only fixture.
Current main's generic resolver chooses one candidate through best_by_import_distance and returns it as suffix_match even when several candidates remain (src/pipeline/registry.c:695-720). trace_path then performs one-direction BFS over stored edges (src/mcp/mcp.c:6244-6255), so it cannot express the CALLS-forward then OVERRIDE-reverse dispatch path. Both halves of the report are therefore present in current code.
This is routed to 0.9.1-rc at priority/high. Thank you for distinguishing declared targets from possible runtime targets.
DeusData commentedon Sep 26, 2026
Thank you, @Enferlain, for tracing this from edge construction all the way to traversal!
Current main has fixed the misleading part. Since b6a2284 (distilled from your #1324, in v0.11.0), an untyped receiver is no longer bound to one arbitrary concrete
process_batchat 0.17. A receiver typed as the abstract contract now resolves toDiffusionTrainingStrategy.process_batchitself, which is your conservative option 1. The OVERRIDE edges from every implementation are in place.Two things remain:
Trainer. That hits Python cross-file receiver inference loses typed instance fields #1277, so today that call gets no edge at all.trace_pathdoesn't yet offer an expansion from an abstract method to its implementations.We'll keep this open for the traversal half and fix #1277 first.
DeusData commentedon Oct 19, 2026
Thank you again for separating false target selection from dispatch-aware traversal. The last response left abstract-to-implementation expansion open and the imported-field receiver case tracked in #1277. I have no new result for either remaining part to report.
DeusData commentedon Oct 25, 2026
Thank you for separating declared targets from possible implementations. Dispatch-aware traversal and the imported-field case in #1277 remain the outstanding work. Sorry for the delay; this is waiting on maintainer follow-up, and I’ll follow up soon.