fix(外观专利): 覆盖率分母改为解析全行并启用阈值,修「904 行只检 1 行仍报成功」

三处叠加导致塌陷不可见:
1. validateCompleteLlmCoverage 收到的 receivedRows 已经按「拿到结果」过滤过分母,
   覆盖率恒为 100%,整片结果丢失也测不出来;改为传解析出的全部行。
2. 判定被放在 filterReceivedParsedRows 之后,整个源文件结果全空时会先 continue 掉,
   连判都不判;移到循环开头,zip 少一个文件不能还报成功。
3. 阈值本身写死在 `boolean enforceCompleteLlmCoverage = false` 上,是死代码。
   改为配置 aiimage.appearance-patent.llm-coverage-min-ratio,默认 0.5 只拦塌陷级
   (现网正常任务实测约 0.91)。

完整性判定另拆出 hasDeliverableLlmResult:现网正常返回里 patent 恒为空串,
拿它当必要条件会把每个任务都判成不完整。
isTechnicalLlmFailure 去掉按 "coze" 子串匹配——品牌名 "Cozee Bay" 会被判成调用失败、
真结论被清空;Coze 工作流特征串随直连改造一并移除。
This commit is contained in:
2026-09-27 11:26:54 +08:00
parent d706c09b0f
commit fd54655f17
6 changed files with 63 additions and 21 deletions
@@ -56,4 +56,13 @@ public class AppearancePatentProperties {
/** 单个外观专利源文件最多解析的有效数据行数,防止 POI 用户模型撑爆堆。 */
private int maxParseRows = 50000;
/**
* 组装结果文件时要求的 LLM 覆盖率下限(0~1,<=0 关闭)。
* 低于该比例说明大批行根本没拿到结论(如 2026-09-20 任务 28805:904 行只检了 1 行却报成功),
* 此时判任务失败并由失败通知告警,而不是交付一份看着完整、实际是复制结论的表。
* 默认 0.5 只拦塌陷级异常;生产正常任务实测约 0.91(28798:723 行 658 行有结论),
* 需要更严时调高,调到 1.0 即要求全行有结论。
*/
private double llmCoverageMinRatio = 0.5D;
}
@@ -6,7 +6,7 @@ import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
/**
* APPEARANCE_PATENT 结果文件 Job Handler(04 注册表)。
* process 返回 Service 的 boolean(false=等待 coze 异步结果,Worker 保持运行心跳);
* process 返回 Service 的 boolean(false=等待 LLM 异步结果,Worker 保持运行心跳);
* cleanup 委托 cleanupResultFileJob;支持异步 offload;owner scoped。
*/
public class AppearancePatentResultFileJobHandler implements ResultFileJobHandler {
@@ -2049,6 +2049,9 @@ public class AppearancePatentTaskService {
for (SourceRows item : sourceRows) {
Map<String, AppearancePatentResultRowDto> resultMap =
loadPersistedResultRowsForRowsWithRetry(task.getId(), item.rows());
// 覆盖率先于「本文件无结果就跳过」判定:整源文件的 LLM 结果全丢(分片被跳过、
// 结果清空)时覆盖率是 0%,必须在这里判掉,不能让 zip 少一个文件还报任务成功。
validateCompleteLlmCoverage(task.getId(), item.rows(), resultMap);
List<AppearancePatentParsedRowVo> receivedRows = filterReceivedParsedRows(item.rows(), resultMap);
if (receivedRows.isEmpty()) {
resultMap.clear();
@@ -2061,7 +2064,6 @@ public class AppearancePatentTaskService {
reasonRows += resultMap.values().stream()
.filter(this::hasReasonFields)
.count();
validateCompleteLlmCoverage(task.getId(), receivedRows, resultMap);
conclusionPropagated += GroupResultPropagator.propagateByGroup(
receivedRows,
AppearancePatentParsedRowVo::getDisplayId,
@@ -2242,10 +2244,15 @@ public class AppearancePatentTaskService {
return receivedRows;
}
/**
* 覆盖率判定:分母必须是**解析出的全部行**(只滤掉不需要送检的行),不能是已经拿到结果的行。
* 传已过滤的集合会让分母恒等于分子 —— 整片结果丢失(chunk payload 缺失被跳过、
* 客户端漏回传)时覆盖率仍是 100%,阈值形同虚设。
*/
private void validateCompleteLlmCoverage(Long taskId,
List<AppearancePatentParsedRowVo> receivedRows,
List<AppearancePatentParsedRowVo> parsedRows,
Map<String, AppearancePatentResultRowDto> resultMap) {
if (receivedRows == null || receivedRows.isEmpty()) {
if (parsedRows == null || parsedRows.isEmpty()) {
return;
}
FileTaskEntity task = fileTaskMapper.selectById(taskId);
@@ -2255,25 +2262,44 @@ public class AppearancePatentTaskService {
int expectedRows = 0;
int missingRows = 0;
List<String> sampleAsins = new ArrayList<>();
for (AppearancePatentParsedRowVo parsedRow : receivedRows) {
for (AppearancePatentParsedRowVo parsedRow : parsedRows) {
if (!hasPromptFields(parsedRow)) {
continue;
}
expectedRows++;
AppearancePatentResultRowDto resultRow = findResultRow(parsedRow, resultMap);
if (resultRow == null || !hasCompleteLlmResult(resultRow)) {
if (resultRow == null || !hasDeliverableLlmResult(resultRow)) {
missingRows++;
if (sampleAsins.size() < 5) {
sampleAsins.add(firstNonBlank(parsedRow.getAsin(), firstNonBlank(parsedRow.getDisplayId(), "")));
}
}
}
boolean enforceCompleteLlmCoverage = false;
if (enforceCompleteLlmCoverage && expectedRows > 0 && missingRows > 0) {
log.warn("[appearance-patent] incomplete llm coverage taskId={} expectedRows={} missingRows={} samples={}",
taskId, expectedRows, missingRows, sampleAsins);
throw new BusinessException("LLM 结果不完整:缺少 " + missingRows + "/" + expectedRows + " 条检测结果,请等待重试或重新运行任务");
if (expectedRows <= 0) {
return;
}
int resolvedRows = expectedRows - missingRows;
double coverage = (double) resolvedRows / expectedRows;
double minCoverage = properties.getLlmCoverageMinRatio();
if (missingRows > 0) {
log.warn("[appearance-patent] incomplete llm coverage taskId={} expectedRows={} missingRows={} coverage={} samples={}",
taskId, expectedRows, missingRows, String.format("%.2f%%", coverage * 100), sampleAsins);
}
if (minCoverage > 0 && coverage + 1e-9 < minCoverage) {
throw new BusinessException("LLM 结果不完整:仅 " + resolvedRows + "/" + expectedRows
+ " 行拿到检测结论(低于 " + Math.round(minCoverage * 100) + "% 覆盖率下限),请重新运行任务");
}
}
/**
* 交付口径的完整性判定:结论依赖标题维度、外观维度和最终结论三列。
* 与 {@link #hasCompleteLlmResult} 的区别是不看 patentRisk —— 现网正常返回里 patent
* 恒为空串(见 AppearancePatentLlmClient 的 LlmResult 构造),拿它当必要条件会把每个任务都判成不完整。
*/
private boolean hasDeliverableLlmResult(AppearancePatentResultRowDto row) {
return hasUsableLlmField(row.getTitleRisk())
&& hasUsableLlmField(row.getAppearanceRisk())
&& hasUsableLlmField(row.getConclusion());
}
private boolean hasCompleteLlmResult(AppearancePatentResultRowDto row) {
@@ -256,11 +256,14 @@ public final class AppearancePatentSheetBuilder {
return normalized.contains("侵权") ? "成功" : "失败";
}
/**
* 只按当前直连 LLM 客户端会写入的文案判定技术性失败。早期 Coze 工作流特征串已随直连改造移除:
* 按 "coze" 子串匹配会把品牌词 "Cozee Bay" 误判成调用失败,真结论被清空。
*/
public static boolean isTechnicalLlmFailure(String value) {
String normalized = normalize(value).toLowerCase(Locale.ROOT);
return normalized.contains("coze") || normalized.contains("llm")
return normalized.contains("llm")
|| normalized.contains("结果不完整")
|| normalized.contains("工作流节点执行超限")
|| normalized.contains("调用超时")
|| normalized.contains("timeout");
}