mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-03 16:51:29 +08:00
fix(errors): finish the sweep for failure notices that hide their cause
#1356 was reported as "retrieval hides embedding connectivity failures". The adapter had always raised a ConnectionError naming the endpoint and the remedy; the text was discarded a layer above, where the template had no placeholder to put it in.4e816d79converged the tool-dispatch half. This is the audit for the rest of it. Two scans, both over the AST rather than by eye: handlers that raise or return a generic literal without touching the exception they caught, and handlers that log the cause but hand the user a literal. The result is smaller than expected and worth recording — the codebase is mostly honest here, and the sites that do hide a cause almost all do it on purpose. `knowledge.py` refuses to echo an upstream message from a credential-bearing flow, and says so at the site; WeCom onboarding does the same. Those stay. Three did not have a reason: * the agent loop's forced finish told the reader "a step failed" while the caller was logging the exception on the line above; * the question pipeline's tool summarizer did the same, in the same shape, two lines apart; * the update check turned every transport failure into "Unable to check for updates", which cannot distinguish being offline from a proxy that blocks github.com. The release URL is public and carries no credentials, so there was nothing to protect. All three now carry what they already knew, through the same `{error}` placeholder4e816d79established, in both locales. The test is the durable half. A key the runtime formats with a cause must have a slot for it in every locale that defines it — the exact drift that let #1356 ship, where the code passed a cause the template could not accept and nothing complained. 6925 passed, 24 skipped.
This commit is contained in:
@@ -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."
|
||||
|
||||
@@ -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: "模型服务中断了本次回答,请重试。"
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -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 之前没有出过题)"
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
74
tests/agents/test_failure_notices_name_the_cause.py
Normal file
74
tests/agents/test_failure_notices_name_the_cause.py
Normal file
@@ -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}"
|
||||
)
|
||||
Reference in New Issue
Block a user