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.

fix(answer): gated-path excerpts died to a silently-swallowed AttributeError (#896)

Swati Ahujabe04de199841
diff --git a/packages/server/src/repowise/server/mcp_server/tool_answer/retrieval.py b/packages/server/src/repowise/server/mcp_server/tool_answer/retrieval.py
index b54d77ae8..592ad6a61 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_answer/retrieval.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_answer/retrieval.py
@@ -165,7 +165,7 @@ async def _enrich_gated_excerpts(hits: list[dict], ctx: Any = None) -> None:
try:
async with get_session(ctx.session_factory) as session:
res = await session.execute(
- select(Page.id, Page.content_md).where(Page.id.in_(page_ids))
+ select(Page.id, Page.content).where(Page.id.in_(page_ids))
)
content_by_id = {row[0]: (row[1] or "") for row in res.all()}
except Exception:
diff --git a/tests/unit/server/mcp/test_answer_calibration.py b/tests/unit/server/mcp/test_answer_calibration.py
index d9c8e064d..bfba83283 100644
--- a/tests/unit/server/mcp/test_answer_calibration.py
+++ b/tests/unit/server/mcp/test_answer_calibration.py
@@ -1021,3 +1021,25 @@ async def test_frame_gated_answer_surfaces_code_rationale(setup_mcp, monkeypatch
assert result["confidence"] == "medium"
assert "code_rationale" in result
assert any("floods the synthesis context" in r["comment"] for r in result["code_rationale"])
+
+
+# ---------------------------------------------------------------------------
+# Gated-path excerpt enrichment
+# ---------------------------------------------------------------------------
+
+
+class TestGatedExcerptEnrichment:
+ """_enrich_gated_excerpts must run its real query against the real Page
+ model — a silently-swallowed AttributeError here shipped pointers-only
+ gated payloads and re-opened the 8-15 call fallback spree the excerpts
+ exist to prevent."""
+
+ async def test_excerpts_attached_from_real_page_rows(self, factory, populated_db):
+ from repowise.server.mcp_server.tool_answer.retrieval import (
+ _enrich_gated_excerpts,
+ )
+
+ hits = [{"page_id": "repo_overview:test-repo", "score": 1.0}]
+ ctx = SimpleNamespace(session_factory=factory)
+ await _enrich_gated_excerpts(hits, ctx)
+ assert hits[0].get("excerpt", "").startswith("# Test Repo")