Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(mcp): keep non-path node ids out of get_answer fallback_targets (#769)
Raghav Chamadiya23087bfb4d62
diff --git a/packages/server/src/repowise/server/mcp_server/tool_answer/answer.py b/packages/server/src/repowise/server/mcp_server/tool_answer/answer.pyindex 17b13e421..928d95ffa 100644--- a/packages/server/src/repowise/server/mcp_server/tool_answer/answer.py+++ b/packages/server/src/repowise/server/mcp_server/tool_answer/answer.py@@ -140,6 +140,25 @@ def _cache_entry_expired(created_at) -> bool:return (datetime.now(UTC) - ts) > timedelta(days=_ANSWER_CACHE_TTL_DAYS)+def _is_readable_path(target: str) -> bool:+ """Whether a fallback_target is a file the agent can actually Read.++ Non-file graph nodes (community/SCC nodes, architectural layers) can ride in+ on retrieval hits with a ``target_path`` like ``"scc-607"`` or+ ``"layer:application"``: internal ids with no path separator and no file+ extension. An agent handed one in ``fallback_targets`` will try to Read it and+ dead-end, so keep only path-shaped entries (2026-07-10 dogfood finding).+ """+ t = (target or "").strip()+ if not t:+ return False+ if "/" in t or "\\" in t:+ return True+ dot = t.rfind(".")+ ext = t[dot + 1:] if dot != -1 else ""+ return bool(ext) and ext.isalnum() and len(ext) <= 6++def _gather_code_rationale(ctx, hits: list[dict], fallback_targets: list[str], question: str):"""Mine in-code rationale comments for a low-confidence answer.@@ -419,7 +438,10 @@ async def get_answer(session, repo_id, hits, ctx, question_ids=question_ids)- fallback_targets = [h["target_path"] for h in hits if h.get("target_path")]+ fallback_targets = [+ h["target_path"] for h in hits+ if h.get("target_path") and _is_readable_path(h["target_path"])+ ]if not hits:return {diff --git a/tests/unit/server/mcp/test_answer_payload.py b/tests/unit/server/mcp/test_answer_payload.pyindex cd003f280..acac0dd62 100644--- a/tests/unit/server/mcp/test_answer_payload.py+++ b/tests/unit/server/mcp/test_answer_payload.py@@ -13,8 +13,34 @@ from types import SimpleNamespaceimport pytest+from repowise.server.mcp_server.tool_answer.answer import _is_readable_pathfrom repowise.server.mcp_server.tool_answer.retrieval import serialize_hits+# ---------------------------------------------------------------------------+# fallback_targets must be Read-able paths, never internal graph node ids+# (2026-07-10 dogfood finding: "scc-607" / "layer:application" leaked in)+# ---------------------------------------------------------------------------+++class TestIsReadablePath:+ @pytest.mark.parametrize(+ "target,expected",+ [+ ("src/flask/app.py", True),+ ("app.py", True),+ ("pkg/sub/mod.py", True),+ ("cluster-config/x.py", True), # hyphen in a real dir must not trip it+ ("scc-607", False), # community/SCC node id+ ("layer:application", False), # architectural-layer scheme token+ ("comm-12", False),+ ("README", False), # no separator, no extension+ ("", False),+ ],+ )+ def test_filters_node_ids_keeps_paths(self, target, expected) -> None:+ assert _is_readable_path(target) is expected++# ---------------------------------------------------------------------------# serialize_hits unit tests# ---------------------------------------------------------------------------