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 get_answer reasoning propagation (#1714)

linhaixin45-cmyk4501a68c61aa
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.py
index 5ab030bd2..f7dd73da6 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
@@ -180,6 +180,7 @@ from repowise.server.mcp_server.tool_answer.symbols import (
from repowise.server.mcp_server.tool_answer.synthesis import (
_hash_question,
_resolve_provider_for_answer,
+ _resolve_reasoning_for_answer,
synthesize,
)
@@ -667,6 +668,7 @@ async def get_answer(
provider,
_SYSTEM_PROMPT,
user_prompt,
+ reasoning=_resolve_reasoning_for_answer(getattr(ctx, "path", None)),
session_factory=getattr(ctx, "session_factory", None),
repo_id=repo_id,
)
diff --git a/packages/server/src/repowise/server/mcp_server/tool_answer/synthesis.py b/packages/server/src/repowise/server/mcp_server/tool_answer/synthesis.py
index 588d0db2f..b41796d4a 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_answer/synthesis.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_answer/synthesis.py
@@ -15,6 +15,8 @@ import math
import os
from pathlib import Path
+from repowise.core.reasoning import ReasoningMode, resolve_reasoning
+from repowise.core.repo_config import load_repo_config
from repowise.server.mcp_server.tool_answer.config import (
_SYNTHESIS_MAX_TOKENS,
_SYNTHESIS_TEMPERATURE,
@@ -46,6 +48,12 @@ def _hash_question(question: str) -> str:
return hashlib.sha256(norm.encode("utf-8")).hexdigest()
+def _resolve_reasoning_for_answer(repo_path: Path | None) -> ReasoningMode:
+ """Resolve the synthesis reasoning mode from env and repo config."""
+ config = load_repo_config(repo_path) if repo_path is not None else None
+ return resolve_reasoning(config=config)
+
+
def _load_repo_provider_config(
repo_path: Path | None,
) -> tuple[str | None, str | None, dict[str, str]]:
@@ -392,6 +400,7 @@ async def synthesize(
system_prompt: str,
user_prompt: str,
*,
+ reasoning: ReasoningMode = "auto",
session_factory=None,
repo_id: str | None = None,
) -> tuple[str, str | None]:
@@ -424,6 +433,7 @@ async def synthesize(
user_prompt=user_prompt,
max_tokens=_SYNTHESIS_MAX_TOKENS,
temperature=_SYNTHESIS_TEMPERATURE,
+ reasoning=reasoning,
),
None,
)
diff --git a/tests/unit/server/mcp/test_answer_always_synthesize.py b/tests/unit/server/mcp/test_answer_always_synthesize.py
index 1cb181d85..08d42c807 100644
--- a/tests/unit/server/mcp/test_answer_always_synthesize.py
+++ b/tests/unit/server/mcp/test_answer_always_synthesize.py
@@ -82,6 +82,50 @@ async def test_non_dominant_returns_prose_at_medium_with_evidence(setup_mcp, mon
assert "ambiguous" in result["note"]
+async def test_configured_reasoning_reaches_synthesis(setup_mcp, monkeypatch):
+ import repowise.server.mcp_server.tool_answer.answer as answer_mod
+ from repowise.server.mcp_server import get_answer
+
+ _patch_pipeline(monkeypatch, answer_mod, scores=(2.0, 1.9))
+ _patch_provider(monkeypatch, answer_mod, "The go() function drives it (pkg/alpha/one.py).")
+ monkeypatch.setenv("REPOWISE_REASONING", "off")
+ seen: dict = {}
+
+ async def _capture_synthesis(provider, system_prompt, user_prompt, **kwargs):
+ seen.update(kwargs)
+ return "The go() function drives it (pkg/alpha/one.py).", None
+
+ monkeypatch.setattr(answer_mod, "synthesize", _capture_synthesis)
+
+ await get_answer("how does the alpha module go function work")
+
+ assert seen["reasoning"] == "off"
+
+
+async def test_repo_reasoning_resolution_reaches_synthesis(setup_mcp, monkeypatch):
+ import repowise.server.mcp_server.tool_answer.answer as answer_mod
+ from repowise.server.mcp_server import get_answer
+
+ _patch_pipeline(monkeypatch, answer_mod, scores=(2.0, 1.9))
+ _patch_provider(monkeypatch, answer_mod, "The go() function drives it (pkg/alpha/one.py).")
+ monkeypatch.setattr(
+ answer_mod, "_resolve_reasoning_for_answer", lambda _path: "low", raising=False
+ )
+ seen: dict = {}
+
+ async def _capture_synthesis(provider, system_prompt, user_prompt, **kwargs):
+ seen.update(kwargs)
+ return "The go() function drives it (pkg/alpha/one.py).", None
+
+ monkeypatch.setattr(answer_mod, "synthesize", _capture_synthesis)
+
+ await get_answer("how does the alpha module go function work")
+
+ assert seen["reasoning"] == "low"
+
+
@pytest.mark.asyncio
async def test_hedged_non_dominant_demotes_low_but_keeps_prose(setup_mcp, monkeypatch):
"""(b) A hedged synthesis on non-dominant retrieval still demotes to low,
diff --git a/tests/unit/server/mcp/test_answer_synthesis_timeout.py b/tests/unit/server/mcp/test_answer_synthesis_timeout.py
index a4ba326d0..2a4f1ad1b 100644
--- a/tests/unit/server/mcp/test_answer_synthesis_timeout.py
+++ b/tests/unit/server/mcp/test_answer_synthesis_timeout.py
@@ -306,9 +306,18 @@ async def test_prompts_and_sampling_are_passed_through_unchanged():
"user_prompt": "the user prompt",
"max_tokens": _SYNTHESIS_MAX_TOKENS,
"temperature": _SYNTHESIS_TEMPERATURE,
+ "reasoning": "auto",
}
+async def test_reasoning_mode_is_passed_to_the_provider():
+ provider = _SlowProvider(duration=0, budget=30.0)
+
+ await synthesize(provider, "system", "user", reasoning="off")
+
+ assert provider.calls[0]["reasoning"] == "off"
+
+
async def test_a_non_timeout_failure_is_not_reported_as_a_budget_overrun():
"""A socket timeout IS a builtin TimeoutError, so sniffing the type lies."""
diff --git a/tests/unit/server/mcp/test_provider_resolution.py b/tests/unit/server/mcp/test_provider_resolution.py
index dc32fb681..d8bc5cbca 100644
--- a/tests/unit/server/mcp/test_provider_resolution.py
+++ b/tests/unit/server/mcp/test_provider_resolution.py
@@ -13,6 +13,7 @@ import json as _json
import pytest
+from repowise.server.mcp_server.tool_answer import synthesis as synthesis_module
from repowise.server.mcp_server.tool_answer.synthesis import (
_load_repo_provider_config,
_resolve_provider_for_answer,
@@ -25,6 +26,7 @@ def _clean_env(monkeypatch):
"REPOWISE_PROVIDER",
"REPOWISE_DOC_MODEL",
"REPOWISE_MODEL",
+ "REPOWISE_REASONING",
"OPENAI_API_KEY",
"ANTHROPIC_API_KEY",
"GEMINI_API_KEY",
@@ -72,6 +74,12 @@ def test_state_json_still_used_when_config_lacks_provider(tmp_path):
assert model == "gpt-5.4-nano"
+def test_reasoning_is_loaded_from_repo_config(tmp_path):
+ repo = _write_repo(tmp_path, config={"reasoning": "low"})
+
+ assert synthesis_module._resolve_reasoning_for_answer(repo) == "low"
+
+
def test_keyless_persisted_provider_falls_back_to_available_key(tmp_path, monkeypatch):
"""gemini persisted, only OPENAI_API_KEY present -> openai provider, not None."""
repo = _write_repo(tmp_path, state={"provider": "gemini", "model": "gemini-3.1-flash"})