fix: getAgentModels 删除/非法 agent 回退不抛异常; parse 拒绝越界 score

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
SerenNoble 2026-06-28 18:23:57 +08:00
parent b94536fe7a
commit 6ef80fd76f
2 changed files with 12 additions and 1 deletions

View file

@ -142,6 +142,10 @@ public class PersonaMatcherServiceImpl implements PersonaMatcherService {
MatchResult mr = new MatchResult();
mr.agentId = j.getStr("agent_id");
mr.score = new BigDecimal(j.getStr("score", "0"));
// score 越界(DB 列 DECIMAL(4,2) 上限 9.99,且语义上仅 [0,1] 有意义)视为不可解析,跳过写入
if (mr.score.signum() < 0 || mr.score.compareTo(BigDecimal.ONE) > 0) {
return null;
}
mr.reason = j.getStr("reason");
return (mr.agentId == null || mr.agentId.isBlank()) ? null : mr;
} catch (Exception ex) {

View file

@ -277,7 +277,14 @@ public class ConfigServiceImpl implements ConfigService {
if (a == null || a.getAgentId() == null) {
return fallback;
}
AgentEntity matched = agentService.getAgentById(a.getAgentId());
// getAgentById 在 agent 不存在(被删除/LLM 返回非法 id)时会抛 RenException,
// 此处必须回退设备 agent,绝不能让异常冒泡导致设备连不上。
AgentEntity matched;
try {
matched = agentService.getAgentById(a.getAgentId());
} catch (RenException e) {
matched = null;
}
if (matched != null && matched.getSystemPrompt() != null && !matched.getSystemPrompt().isBlank()) {
return matched.getSystemPrompt();
}