fix(appearance-patent): 补检改吃独立预算,缺口不再以"排不上队"的名义交付半张表

现网读数(2026-10-19 近 24h 日志):交付缺口触发过补检,但从没补齐过大面积缺口——
"补检排不上队,按已有结果交付" 四例 missingRows=112/455/1471/2110,作业全部 retry_count=5。
根因是一条自我锁死:补检重排走 requeue,而 requeue 的 WHERE 带 retry_count<MAX_RETRY_COUNT,
把这条预算抛满的恰恰是"还没检完"本身(覆盖率抛、空结果抛)。越慢 ⇒ 抛得越多 ⇒ 越补不上。

改法是把两条预算拆开,且只用底座现成件(modules/task/** 是共享文件,且
TaskFileJobService 在册 929/实 928,只剩 1 行棘轮余量,加方法必判红):

- recheck-max-rounds(默认 2):补检自己的轮次上限,与行级 llm-row-max-rounds 分家。
- completeLlmFileJob:补检决定挪到 assembleResultWorkbook 之前(新增 measureDeliveryFacts,
  只量行账不出表)——那一跑完就把成品传上 OSS 并挂好 resultFileUrl,那时才发现缺口,
  半张表已经在用户的下载列表里了。
- requestRecheckForMissingRows:requeue 排不上队时改吃抛,不再退化成按已有结果交付;
  让作业走到终态失败,由判死出口按补检预算再判一次。
- fallbackAssembleResultFile:出表前先试 scheduleFallbackRecheck,复用现成的
  resetTerminalFailedForRecovery(终态失败+retry 到顶 ⇒ 清零、重回 PENDING、重派发),
  补传恢复那条路一直在用它,只有交付缺口这条路没接上。轮次只在重排真接上之后才记,
  否则一轮没接成的重排会自己把预算吃光。预算耗尽仍照常出表——
  "起码失败了也可以下载"那条保证不变。

门禁:后端整量 mvn -o test 4549 例/0 红/0 错/16 skipped,BUILD SUCCESS;
定向 43 例(交付闸门 14+兜底出表 5+行标记 15+CatchSilence 9)全绿;
ops 面 ruff check . All checks passed、readability 棘轮 9 passed(AP 3048→3121,基线 3458)。

整量第一次跑抓到的是本笔自己的账:新增两枚 Redis 降级方法各带一处不重抛的 catch,
把 CatchSilenceRatchetTest 的"不重抛"从 562 顶到 564。没放宽那格判据,改成去掉这两处
新 catch——补检轮次直接复用既有的行级轮次计数(同 24h TTL、同降级口径),借哨兵键
__recheck__;行键恒为 id::ASIN::国家、必带 "::",撞不上。
This commit is contained in:
2026-10-20 00:41:29 +08:00
parent 773c41254f
commit 3c662389c0
5 changed files with 212 additions and 15 deletions
@@ -15,6 +15,7 @@ import com.nanri.aiimage.modules.task.mapper.FileResultMapper;
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
import com.nanri.aiimage.modules.task.mapper.TaskChunkMapper;
import com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper;
import com.nanri.aiimage.modules.task.model.entity.FileResultEntity;
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
import com.nanri.aiimage.modules.task.service.TaskDistributedLockService;
@@ -84,6 +85,7 @@ class AppearancePatentDeliveryGateTest {
@BeforeEach
void setUp() {
when(properties.getLlmCoverageMinRatio()).thenReturn(0.95D);
when(properties.getRecheckMaxRounds()).thenReturn(2);
service = new AppearancePatentTaskService(
localFileStorageService, null,
mock(com.nanri.aiimage.common.service.ResultDownloadResolver.class),
@@ -205,7 +207,38 @@ class AppearancePatentDeliveryGateTest {
"requestRecheckForMissingRows", FileTaskEntity.class, TaskFileJobEntity.class,
AppearancePatentRowOutcome.Facts.class);
method.setAccessible(true);
return (boolean) method.invoke(service, task, job, facts);
try {
return (boolean) method.invoke(service, task, job, facts);
} catch (InvocationTargetException ex) {
// 与 validate/validatePartial 同一口径:不剥壳,assertThrows 就只能断到反射壳本身
if (ex.getCause() instanceof RuntimeException runtime) {
throw runtime;
}
throw ex;
}
}
private static FileResultEntity result(long id) {
FileResultEntity result = new FileResultEntity();
result.setId(id);
result.setTaskId(TASK_ID);
result.setModuleType("APPEARANCE_PATENT");
return result;
}
private static TaskFileJobEntity pendingJob(Long id) {
TaskFileJobEntity job = job(id);
job.setStatus("PENDING");
return job;
}
private boolean scheduleFallbackRecheck(FileTaskEntity task, FileResultEntity result,
AppearancePatentRowOutcome.Facts facts) throws Exception {
Method method = AppearancePatentTaskService.class.getDeclaredMethod(
"scheduleFallbackRecheck", FileTaskEntity.class, FileResultEntity.class,
AppearancePatentRowOutcome.Facts.class);
method.setAccessible(true);
return (boolean) method.invoke(service, task, result, facts);
}
private String appendGap(String existingError, AppearancePatentRowOutcome.Facts facts) throws Exception {
@@ -306,12 +339,16 @@ class AppearancePatentDeliveryGateTest {
}
@Test
void recheckRefusalFallsBackToDeliveringWhatWeHave() throws Exception {
void recheckRefusalDoesNotShipTheHalfTable() throws Exception {
// 旧口径是"补检排不上队就按已有结果交付",现网据此发出过 missingRows=112/455/1471/2110
// 四张半表。改成吃抛:作业走到终态失败,由判死出口按补检自己的预算再判一次。
List<AppearancePatentParsedRowVo> rows = sheetRows(2);
AppearancePatentRowOutcome.Facts facts = summarize(rows, submittedRows(rows, 1, true));
when(taskFileJobService.requeue(anyLong(), any())).thenReturn(false);
assertFalse(requestRecheck(task("SUCCESS"), job(500L), facts));
BusinessException ex = assertThrows(BusinessException.class,
() -> requestRecheck(task("SUCCESS"), job(500L), facts));
assertTrue(ex.getMessage().contains("1 行未完成检测"), ex.getMessage());
verify(taskCacheService).releaseRowInspection(eq(TASK_ID), anyList(), eq(true));
}
@@ -324,6 +361,55 @@ class AppearancePatentDeliveryGateTest {
verify(taskFileJobService, never()).requeue(anyLong(), any());
}
// ---------- 判死出口的补检预算 ----------
@Test
void deadJobWithGapIsRequeuedOnItsOwnBudgetInsteadOfShipping() throws Exception {
List<AppearancePatentParsedRowVo> rows = sheetRows(2);
AppearancePatentRowOutcome.Facts facts = summarize(rows, submittedRows(rows, 1, true));
when(taskCacheService.recheckRounds(TASK_ID)).thenReturn(0L);
when(taskFileJobService.resetTerminalFailedForRecovery(TASK_ID, "APPEARANCE_PATENT", 700L))
.thenReturn(pendingJob(500L));
assertTrue(scheduleFallbackRecheck(task("FAILED"), result(700L), facts));
verify(taskCacheService).releaseRowInspection(eq(TASK_ID), anyList(), eq(true));
verify(taskCacheService).countRecheckRound(TASK_ID);
}
@Test
void exhaustedRecheckBudgetShipsWhatWeHave() throws Exception {
List<AppearancePatentParsedRowVo> rows = sheetRows(2);
AppearancePatentRowOutcome.Facts facts = summarize(rows, submittedRows(rows, 1, true));
when(taskCacheService.recheckRounds(TASK_ID)).thenReturn(2L);
assertFalse(scheduleFallbackRecheck(task("FAILED"), result(700L), facts));
verify(taskFileJobService, never()).resetTerminalFailedForRecovery(anyLong(), any(), anyLong());
}
@Test
void deadJobWithoutGapShipsImmediately() throws Exception {
List<AppearancePatentParsedRowVo> rows = sheetRows(2);
when(taskCacheService.recheckRounds(TASK_ID)).thenReturn(0L);
assertFalse(scheduleFallbackRecheck(task("FAILED"), result(700L),
summarize(rows, submittedRows(rows, 2, true))));
verify(taskFileJobService, never()).resetTerminalFailedForRecovery(anyLong(), any(), anyLong());
}
@Test
void failedRequeueDoesNotBurnARecheckRound() throws Exception {
// 重排没接上(作业不在"FAILED 且 retry 到顶"那格)时不能扣轮次:
// 否则一轮没补成的重排会把预算自己吃光,缺口行连一次补齐机会都没有就出表
List<AppearancePatentParsedRowVo> rows = sheetRows(2);
AppearancePatentRowOutcome.Facts facts = summarize(rows, submittedRows(rows, 1, true));
when(taskCacheService.recheckRounds(TASK_ID)).thenReturn(0L);
when(taskFileJobService.resetTerminalFailedForRecovery(TASK_ID, "APPEARANCE_PATENT", 700L))
.thenReturn(job(500L));
assertFalse(scheduleFallbackRecheck(task("FAILED"), result(700L), facts));
verify(taskCacheService, never()).countRecheckRound(anyLong());
}
// ---------- 任务消息 ----------
@Test