codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

Java: interface implementations produce almost no IMPLEMENTS edges; nested interface names truncated

Open masesas opened this issue 4 months ago • 6 comments

Environment

  • codebase-memory-mcp 0.9.0 (macOS arm64, Darwin 25.0.0)
  • Project: Java 21 / Spring Boot 3 monorepo, ~1,358 Java files, indexed in full mode (20,530 nodes / 70,485 edges)

Summary

On a Java codebase with 188 class X implements Y declarations (verified via grep -rE "class \w+.*implements "), the graph contains only 3 IMPLEMENTS edges. Most implements relationships either land on INHERITS (460 edges, mixed with actual extends) or are missing entirely.

Additionally, when the implemented interface is a nested interface, the target name is truncated to the inner segment only.

Repro

Source:

public class TrxRentCustomRepositoryImpl implements TrxRentRepository.Custom {

Cypher:

MATCH (c:Class {name:'TrxRentCustomRepositoryImpl'})-[r:INHERITS|IMPLEMENTS]->(t)
RETURN type(r), t.name

Result:

INHERITS -> "Custom"

Expected: an IMPLEMENTS (or at least correctly-typed) edge to TrxRentRepository.Custom resolved to the actual nested interface node.

Aggregate check:

MATCH ()-[r:IMPLEMENTS]->() RETURN count(r)   // 3

vs 188 implements clauses in source.

Impact

"Who implements interface X" queries are unusable for Java — we have to fall back to grep. This is one of the most common questions for Spring codebases (interface -> impl indirection is everywhere).

Notes

Happy to provide more samples or test a nightly build.

masesas avatar Jul 23 '26 15:07 masesas

Thanks for the quantified report. Current Java coverage exercises simple implementation cases but does not protect nested interface qualified names or the distinction between IMPLEMENTS and class inheritance at this scale. The RED should require the complete nested interface QN and exact implementation edge counts, with no fallback to a truncated short-name match. High priority for 0.9.1-rc under #592.

DeusData avatar Jul 24 '26 14:07 DeusData

Thank you, @masesas, for the quantified report! "188 implements clauses vs 3 IMPLEMENTS edges" was exactly the number that exposed this.

On corpora large enough to use the parallel resolver, that path wrote every base relation as INHERITS; only the sequential path told interfaces apart. Fixed in 4a3aac64 (shipped since v0.9.1-rc.1, in v0.11.0). Both paths now pick IMPLEMENTS or INHERITS from the target's label. On elasticsearch, IMPLEMENTS went from 3 to 11,182. Your exact shape on current main gives TrxRentCustomRepositoryImpl IMPLEMENTS TrxRentRepository.Custom, with the full nested name.

Could you re-index your Spring monorepo on v0.11.0 and confirm that IMPLEMENTS is now close to your 188?

DeusData avatar Sep 26 '26 04:09 DeusData

Thanks for the report! To move this forward we need a bit more so we can reproduce it ourselves:

  • the codebase-memory-mcp --version you're on
  • the exact steps or command you ran
  • a public repo (or a small dummy snippet) that shows the problem — please don't paste proprietary code

Once that's here we'll pick it straight back up. Heads-up: issues left awaiting-reporter are automatically closed after a few weeks of silence, but a comment reopens the door anytime.

github-actions[bot] avatar Sep 26 '26 17:09 github-actions[bot]

Thank you again for quantifying the missing Java IMPLEMENTS relationships. The latest update identified the parallel-path fix and requested the Spring-monorepo retest, including the nested interface name. I have no new result from your project to report.

DeusData avatar Oct 19 '26 22:10 DeusData

Retested today on the same Spring monorepo. Short version: the missing-edge part is fixed, but nested interfaces now resolve to the wrong owner in 5 of 8 cases, and I have a 4-file repro.

Environment

  • codebase-memory-mcp 0.12.1 (macOS arm64, daemon build 0.12.1)
  • index_repository mode full: 56,996 nodes / 367,090 edges. The repo grew since the original report (~3,860 Java files now), so the numbers below are recounted from today's source.

1. Plain implements — fixed ✅

Counted from source (excluding build output):

count
class X implements … declarations 413
(class, interface) pairs 433
… targeting an interface declared in the repo 278
… targeting JDK/Spring types (Serializable ×119, AttributeConverter, HandlerInterceptor, WebMvcConfigurer, …) 155

Graph: MATCH ()-[r:IMPLEMENTS]->() RETURN count(r) → 287 (was 3). Of the 267 classes that implement at least one in-repo interface, 266 have an IMPLEMENTS edge; the single miss is a file whose body is entirely commented out, so that is expected. Pairs targeting JDK/Spring interfaces get no edge because there is no node for them, which I assume is by design.

INHERITS is 728 and all of its targets are Class nodes, so the INHERITS/IMPLEMENTS mix-up is gone.

2. Nested interfaces — edge exists, qualified name is complete, but the owner is wrong ❌

8 classes implement a nested XRepository.Custom / XRepository.Raw. All 8 now have an IMPLEMENTS edge and t.qualified_name is the full nested name (truncation fixed). But:

Impl class Source says Graph target
AdminAuditLogCustomRepositoryImpl AdminAuditLogRepository.Custom ✅
AdminUserCustomRepositoryImpl AdminUserRepository.Custom ❌ AdminAuditLogRepository.Custom
TrxPaymentVirtualAccountCustomRepository TrxPaymentVirtualAccountRepository.Custom ❌ VehiclePhotoRepository.Custom
TrxRentCustomRepositoryImpl TrxRentRepository.Custom ❌ VehiclePhotoRepository.Custom
TrxRentInvoiceCustomRepositoryImpl TrxRentInvoiceRepository.Custom ❌ VehiclePhotoRepository.Custom
VehicleExtraRepositoryRawImpl VehicleExtraRepository.Raw ✅
VehiclePhotoCustomRepositoryImpl VehiclePhotoRepository.Custom ✅
VehiclePricingRawRepositoryImpl VehiclePricingRepository.Raw ❌ VehicleExtraRepository.Raw

All 8 correct target nodes exist in the graph (MATCH (i:Interface) WHERE i.name IN ['Custom','Raw'] returns exactly the 8 expected qualified names). The resolver just matches on the short name Custom and picks the first candidate in the same package/module, ignoring the TrxRentRepository. qualifier and the explicit import in the impl file. The 3 Trx* impls live in feature/marketplace, their interfaces in domain/transaction; the graph picked the only Custom that exists inside feature/marketplace.

Consequence for the "who implements X" use case:

MATCH (c)-[:IMPLEMENTS]->(t:Interface) WHERE t.name = 'Custom'
RETURN t.qualified_name, collect(c.name)
// VehiclePhotoRepository.Custom   -> 4 implementors (3 of them wrong)
// AdminAuditLogRepository.Custom  -> 2 implementors (1 wrong)
// TrxRentRepository.Custom        -> absent (0 implementors)

This is worse than a missing edge: the answer is confidently wrong, with no signal.

3. Minimal repro (4 files, no proprietary code)

src/main/java/demo/repo/AlphaRepository.java
src/main/java/demo/repo/BetaRepository.java
src/main/java/demo/impl/AlphaCustomRepositoryImpl.java
src/main/java/demo/impl/BetaCustomRepositoryImpl.java
package demo.repo;
public interface AlphaRepository { interface Custom { String alpha(); } }
package demo.repo;
public interface BetaRepository { interface Custom { String beta(); } }
package demo.impl;
import demo.repo.BetaRepository;
public class BetaCustomRepositoryImpl implements BetaRepository.Custom {
    @Override public String beta() { return "beta"; }
}

(AlphaCustomRepositoryImpl is the same shape against AlphaRepository.Custom.)

Steps: index_repository(repo_path=…, mode="fast") on 0.12.1, then

MATCH (c:Class)-[r:IMPLEMENTS|INHERITS]->(t) RETURN c.name, type(r), t.qualified_name

Result:

AlphaCustomRepositoryImpl  IMPLEMENTS  …demo.repo.AlphaRepository.Custom   // ok
BetaCustomRepositoryImpl   IMPLEMENTS  …demo.repo.AlphaRepository.Custom   // wrong, expected BetaRepository.Custom

Both AlphaRepository.Custom and BetaRepository.Custom exist as Interface nodes, so this is resolution, not parsing.

Side note (may be intentional)

interface VehicleRepository extends FltVehicleRepository is recorded as IMPLEMENTS (Interface→Interface), 6 such edges here. Fine if that is the chosen semantics, just flagging it since it is extends in source.

Happy to re-run on a nightly. If you prefer, I can open the nested-owner resolution as a separate issue and let this one close on the count fix.

masesas avatar Oct 20 '26 09:10 masesas

Thank you for the detailed 0.12.1 retest and four-file case. The implementation-count fix is confirmed on your project, but wrong-owner resolution of nested interfaces remains open; your supplied fixture is enough for the next maintainer step. Sorry for the delay; this is waiting on maintainer follow-up, and I’ll follow up soon.

DeusData avatar Oct 25 '26 17:10 DeusData