fix: isolate internal error details from user-facing messages

- run(): remove exception text from user-visible error message
- error_diagnosis: remove exc from metadata and ai_confirmation
- RAG retrieval: remove exception detail from warning string
- All exception details now only go to logs with exc_info=True
This commit is contained in:
unknown
2026-05-21 01:11:07 +08:00
parent 7099424354
commit 70e12ea31c
2 changed files with 9 additions and 7 deletions

View File

@@ -264,7 +264,7 @@ class GuidedLearningCapability(BaseCapability):
except Exception as e:
import logging
logging.getLogger(__name__).warning(f"RAG retrieval failed: {e}")
return ("", f"RAG 检索失败: {e}")
return ("", "RAG 检索失败")
# ── Real LLM call ───────────────────────────────────────────────────
@@ -372,9 +372,9 @@ class GuidedLearningCapability(BaseCapability):
await stream.content(w, metadata={"type": "rag_error"})
except Exception as e:
import logging
logging.getLogger(__name__).error(f"Stage {stage} failed: {e}")
logging.getLogger(__name__).error(f"Stage {stage} failed: {e}", exc_info=True)
async with stream.stage("error", source=self.manifest.name):
await stream.content(f"阶段执行失败: {e}。进度已保存,下次将继续此阶段。")
await stream.content("阶段执行失败,进度已保存,下次将继续此阶段。")
finally:
_turn_call_llm.reset(token)
self._service.save(progress)
@@ -829,14 +829,16 @@ class GuidedLearningCapability(BaseCapability):
timeout=self._ERROR_DIAGNOSIS_TIMEOUT_SECONDS,
)
except (Exception, asyncio.TimeoutError) as exc:
import logging
logging.getLogger(__name__).warning("error_diagnosis failed: %s", exc, exc_info=True)
progress.stage_failure_counts["error_diagnosis"] = progress.stage_failure_counts.get("error_diagnosis", 0) + 1
progress.stage_failure_notes["error_diagnosis"] = str(exc)
for rec in active_errors:
rec.ai_confirmation = f"error_diagnosis_unavailable: {exc}"
rec.ai_confirmation = "error_diagnosis_unavailable"
await stream.content(
"错因诊断暂时不可用,已保留现有错误分类并继续后续模块测试。",
source=self.manifest.name,
metadata={"type": "error_diagnosis_unavailable", "error": str(exc)},
metadata={"type": "error_diagnosis_unavailable"},
)
self._service.advance_stage(progress, LearningStage.MODULE_TEST)
return

View File

@@ -82,7 +82,7 @@ async def test_error_diagnosis_llm_failure_advances_to_module_test():
assert progress.current_stage == LearningStage.MODULE_TEST
assert progress.error_records[0].error_type == ErrorType.APPLICATION_ERROR
assert progress.error_records[0].ai_confirmation.startswith("error_diagnosis_unavailable:")
assert progress.error_records[0].ai_confirmation == "error_diagnosis_unavailable"
assert any("错因诊断暂时不可用" in text for kind, text in stream.events if kind == "content")
@@ -102,7 +102,7 @@ async def test_error_diagnosis_llm_timeout_advances_to_module_test():
await cap._run_error_diagnosis(progress, None, stream)
assert progress.current_stage == LearningStage.MODULE_TEST
assert progress.error_records[0].ai_confirmation.startswith("error_diagnosis_unavailable:")
assert progress.error_records[0].ai_confirmation == "error_diagnosis_unavailable"
@pytest.mark.asyncio