diff --git a/deeptutor/agents/chat/prompts/en/agentic_chat.yaml b/deeptutor/agents/chat/prompts/en/agentic_chat.yaml index 41c908162..f98664b8b 100644 --- a/deeptutor/agents/chat/prompts/en/agentic_chat.yaml +++ b/deeptutor/agents/chat/prompts/en/agentic_chat.yaml @@ -134,7 +134,7 @@ notices: loop_budget_exhausted: "Exploration budget reached; answering with what has been gathered." loop_settlement: "Exploration budget reached; completing required follow-up before the final answer." output_truncated: "The model output reached its token limit; asked it to continue." - loop_error_finish: "A step failed; answering with what has been gathered." + loop_error_finish: "A step failed ({error}); answering with what has been gathered." provider_retry: "The model provider connection was interrupted; retrying." provider_unavailable: "Unable to reach the model provider. Please retry." provider_stream_interrupted: "The model provider interrupted this response. Please retry." diff --git a/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml b/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml index ad75be434..378928355 100644 --- a/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml +++ b/deeptutor/agents/chat/prompts/zh/agentic_chat.yaml @@ -98,7 +98,7 @@ notices: loop_budget_exhausted: "探索轮次预算已用尽,将基于已收集的材料作答。" loop_settlement: "探索轮次预算已用尽;正在完成必要收尾,然后给出最终回答。" output_truncated: "模型输出达到 token 上限,已要求其继续完成回答。" - loop_error_finish: "某一步执行失败,将基于已收集的材料作答。" + loop_error_finish: "某一步执行失败({error}),将基于已收集的材料作答。" provider_retry: "模型服务连接中断,正在重试。" provider_unavailable: "无法连接模型服务,请重试。" provider_stream_interrupted: "模型服务中断了本次回答,请重试。" diff --git a/deeptutor/agents/loop/agent_loop.py b/deeptutor/agents/loop/agent_loop.py index b953ef7a2..75fe6caaa 100644 --- a/deeptutor/agents/loop/agent_loop.py +++ b/deeptutor/agents/loop/agent_loop.py @@ -342,6 +342,7 @@ class AgentLoop: messages, state, reason="error", + error=str(exc), continued_answer_parts=continued_answer_parts, ) state.rounds += 1 @@ -627,12 +628,19 @@ class AgentLoop: state: AgentLoopState, *, reason: str = "budget", + error: str = "", continued_answer_parts: list[str] | None = None, ) -> LoopOutcome: if reason == "error": + # The caller has the exception and logs it; without it here the + # reader is told a step failed and never which one or why — the + # same silence ``tool_error_message_factory`` was built to end. notice = self.pipeline._t( "notices.loop_error_finish", - default="A step failed; answering with what has been gathered.", + error=error, + default=f"A step failed ({error}); answering with what has been gathered." + if error + else "A step failed; answering with what has been gathered.", ) else: notice = self.pipeline._t( diff --git a/deeptutor/agents/question/pipeline.py b/deeptutor/agents/question/pipeline.py index f11f5146b..fdbbaa9bd 100644 --- a/deeptutor/agents/question/pipeline.py +++ b/deeptutor/agents/question/pipeline.py @@ -1114,7 +1114,14 @@ class QuestionPipeline: except Exception as exc: logger.warning("Tool summarizer failed for %s: %s", tool_name, exc) await stream.progress( - self._t("notices.tool_summarizer_failed"), + self._t( + "notices.tool_summarizer_failed", + error=str(exc), + default=( + f"Tool summarizer could not produce a summary ({exc}); " + "passing raw tool result forward." + ), + ), source=SOURCE, stage=STAGE_EXPLORING, metadata=merge_trace_metadata( diff --git a/deeptutor/agents/question/prompts/en/pipeline.yaml b/deeptutor/agents/question/prompts/en/pipeline.yaml index cb8eb30f6..fc327529f 100644 --- a/deeptutor/agents/question/prompts/en/pipeline.yaml +++ b/deeptutor/agents/question/prompts/en/pipeline.yaml @@ -331,7 +331,7 @@ notices: plan_reasoning_retry: "The planner spent its whole budget reasoning and produced no plan; asking again with less thinking." repair_attempted: "The previous question payload was invalid; repairing the schema once." repair_failed: "Repair did not fully fix the question; emitting the best-effort version." - tool_summarizer_failed: "Tool summarizer could not produce a summary; passing raw tool result forward." + tool_summarizer_failed: "Tool summarizer could not produce a summary ({error}); passing raw tool result forward." empty: no_quiz_history: "(no prior quiz turns in this session)" diff --git a/deeptutor/agents/question/prompts/zh/pipeline.yaml b/deeptutor/agents/question/prompts/zh/pipeline.yaml index 546f5f1db..7e934a537 100644 --- a/deeptutor/agents/question/prompts/zh/pipeline.yaml +++ b/deeptutor/agents/question/prompts/zh/pipeline.yaml @@ -312,7 +312,7 @@ notices: plan_reasoning_retry: "规划阶段把预算全部用在思考上,没有产出方案;正在降低思考强度重试。" repair_attempted: "上一轮题目载荷不合法;做一次 schema 修复。" repair_failed: "修复未能完全修正题目;使用尽力版本输出。" - tool_summarizer_failed: "工具结果概括失败;将把原始工具结果传给下一轮。" + tool_summarizer_failed: "工具结果概括失败({error});将把原始工具结果传给下一轮。" empty: no_quiz_history: "(本 session 之前没有出过题)" diff --git a/deeptutor/services/app_update.py b/deeptutor/services/app_update.py index c565e9ea5..037746030 100644 --- a/deeptutor/services/app_update.py +++ b/deeptutor/services/app_update.py @@ -321,8 +321,12 @@ class VersionCheckService: else: response.raise_for_status() release_url = str(response.url) - except httpx.HTTPError: - raise VersionCheckError("Unable to check for updates") from None + except httpx.HTTPError as exc: + # The release URL is public and carries no credentials, so the + # transport reason is safe to show — and it is the difference + # between "try again" and "you are offline" / "your proxy blocked + # github.com". + raise VersionCheckError(f"Unable to check for updates: {exc}") from None return _release_from_latest_url(release_url) diff --git a/tests/agents/test_failure_notices_name_the_cause.py b/tests/agents/test_failure_notices_name_the_cause.py new file mode 100644 index 000000000..ece889cc6 --- /dev/null +++ b/tests/agents/test_failure_notices_name_the_cause.py @@ -0,0 +1,74 @@ +"""A notice about a failure must say what failed. + +#1356 was reported as "knowledge retrieval hides embedding connectivity +failures". The adapter had always raised a `ConnectionError` naming the +endpoint and the remedy, and the dispatcher had always caught it — the text +was discarded one layer above, where a template said "An unknown error +occurred while executing rag." and had no placeholder to put the cause in. + +That is the whole failure mode: the code passes a cause the template cannot +accept, and nothing complains. This test is the thing that complains. A key +listed here is one the runtime formats with `error=`, so every locale that +defines it has to have somewhere to put it. +""" + +from __future__ import annotations + +import pathlib + +import pytest +import yaml + +# Notice keys the runtime formats with a cause. Adding a key here without +# adding `{error}` to its templates fails; adding the placeholder without +# passing the cause is caught by the call-site tests next to each capability. +CAUSE_BEARING_NOTICES = ( + "tool_error", + "loop_error_finish", + "tool_summarizer_failed", +) + +_PROMPTS = pathlib.Path(__file__).resolve().parents[2] / "deeptutor" / "agents" + + +def _notice_definitions(key: str) -> list[tuple[pathlib.Path, str]]: + found: list[tuple[pathlib.Path, str]] = [] + for path in _PROMPTS.rglob("prompts/*/*.yaml"): + try: + data = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + except Exception: # pragma: no cover - a broken bundle is its own test + continue + notices = data.get("notices") + if isinstance(notices, dict) and isinstance(notices.get(key), str): + found.append((path, notices[key])) + return found + + +@pytest.mark.parametrize("key", CAUSE_BEARING_NOTICES) +def test_every_locale_of_a_failure_notice_can_hold_its_cause(key: str) -> None: + definitions = _notice_definitions(key) + assert definitions, ( + f"notices.{key} is defined in no prompt bundle — either it was renamed " + "and this list is stale, or the notice was dropped and the runtime " + "still formats it" + ) + missing = [str(path) for path, text in definitions if "{error}" not in text] + assert not missing, ( + f"notices.{key} has no {{error}} placeholder in: {missing}. " + "The runtime passes the cause; a template without a slot for it " + "silently drops what the user needs to act on (#1356)." + ) + + +def test_a_failure_notice_is_translated_everywhere_it_is_defined() -> None: + """A cause that only reaches English readers is half a fix. + + #1356's convergence touched six files for one key precisely because en and + zh have to move together; a key present in one locale and absent from the + other falls back to English mid-sentence. + """ + for key in CAUSE_BEARING_NOTICES: + locales = {path.parent.name for path, _text in _notice_definitions(key)} + assert {"en", "zh"} <= locales, ( + f"notices.{key} is missing from locales {{'en', 'zh'}} - {locales}" + )