fix(文案出口): 用户可见提示语一律走 UserMessages 把关,并补结果作业租约围栏

两件事同源:2026-10-09 任务 30456 的卡片上同时出现中文进度和一句英文异常原文。

围栏:派发链在执行前重读 job 行,让 activateRunningClaim 的 CAS 恒真,撞锁方
deferRunning 把在跑的行翻回 PENDING,markSuccess 静默写 0 行——成功被判成失败。
claim 快照现在贯穿到 runClaimed 不再回读,markSuccess 返回布尔并补 stage=SUCCESS_LOST
日志,让这次丢失可观测。

文案:普查数出 61 处把 ex.getMessage() 拼进用户可见字段(异常响应、任务 error_message、
结果作业 error_msg、看板 message),逐条翻译追不上新增速度,改为出口把关——
UserMessages.with(中文主干, 异常) 只拼接中文详情、orFallback(原文, 兜底句) 只放行含中文的串,
被换掉的原文进日志;GlobalExceptionHandler 按码分档兜底(401/4011/40902 各说各的话)。
另把 chunk-read-failed[N] 摘要写成"第 N 分片读取失败"、TASK_LOCK_BUSY 换成中文(40902 码不动,
客户端按码分支)。数字人两处与结果作业 worker 故意仍存原文:孤儿判定与三条 preserves raw
用例按 error_message 读它,界面侧由前端 userNotice 兜住,已在新尺子里点名豁免并反查豁免是否还被用到。

尺子:RawExceptionMessageSinkGuardTest(出口行数下限硬钉 1500+内存造违例自证)、UserMessagesTest、
UserFacingMessageChineseGuardTest 豁免表收到只剩 JSON 键 msg 一条。mvn -o test 4205 例 0 失败。
This commit is contained in:
2026-10-09 19:34:25 +08:00
parent 6325a63b52
commit 2a4d15b801
76 changed files with 1160 additions and 279 deletions
@@ -1519,12 +1519,12 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
int totalProgressUnits,
int llmWorkUnits) {
if (pipelineSupport().countPendingLlmStates(task.getId()) > 0) {
throw new BusinessException("LLM result is still processing, cannot generate result file yet");
throw new BusinessException("LLM 检测还没全部回流,暂时不能生成结果文件");
}
int assembleProgress = Math.max(1, Math.min(totalProgressUnits - 2, llmWorkUnits));
progressSupport().saveFileBuildProgress(task, job, totalProgressUnits, assembleProgress, "Assembling xlsx");
progressSupport().saveFileBuildProgress(task, job, totalProgressUnits, assembleProgress, "正在生成结果文件");
resultAssembler().assembleResultWorkbook(task, result);
progressSupport().saveFileBuildProgress(task, job, totalProgressUnits, totalProgressUnits - 1, "Uploading result file");
progressSupport().saveFileBuildProgress(task, job, totalProgressUnits, totalProgressUnits - 1, "正在上传结果文件");
fileResultMapper.updateById(result);
boolean taskAlreadyFailed = STATUS_FAILED.equals(task.getStatus())
|| (task.getErrorMessage() != null && !task.getErrorMessage().isBlank());
@@ -1537,7 +1537,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
task.setFinishedAt(LocalDateTime.now());
fileTaskMapper.updateById(task);
taskCacheService.deleteTaskCache(task.getId());
progressSupport().saveFileBuildProgress(task, job, totalProgressUnits, totalProgressUnits, "Result file generated");
progressSupport().saveFileBuildProgress(task, job, totalProgressUnits, totalProgressUnits, "结果文件已生成");
// P1-1:异步 assemble 完成 → task 进入 SUCCESS/FAILED 终态,清理滑窗记录避免内存泄漏。
poisonTracker.clear(task.getId());
}
@@ -1638,7 +1638,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
throw new BusinessException(FailedStatusRowFilter.noMatchedRowsMessage());
}
if (allRows.isEmpty()) {
throw new BusinessException("no valid similar ASIN rows");
throw new BusinessException("没有解析到可检测的货源行,请检查表格的 id / ASIN / 国家 列");
}
return new ParsedWorkbook(total, dropped, headers, allRows, categoryRetryRequired);
} catch (BusinessException ex) {
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.similarasin.service.support;
import com.nanri.aiimage.common.util.UserMessages;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nanri.aiimage.common.exception.BusinessException;
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinResultRowDto;
@@ -126,7 +127,7 @@ public final class SimilarAsinChunkMergeSupport {
.orderByAsc("id")
.last("limit " + batch));
} catch (Exception ex) {
throw new BusinessException("chunk keyset 分页查询失败: " + ex.getMessage(), ex);
throw new BusinessException(UserMessages.with("分片键集 分页查询失败", ex), ex);
}
if (page == null || page.isEmpty()) {
break;
@@ -1,5 +1,7 @@
package com.nanri.aiimage.modules.similarasin.service.support;
import java.util.ArrayList;
import com.nanri.aiimage.common.util.UserMessages;
import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -99,8 +101,8 @@ public class SimilarAsinChunkPayloadSupport {
log.warn("[similar-asin] read chunk payload failed taskId={} chunk={} crossInstance={} err={}",
chunk.getTaskId(), chunk.getChunkIndex(), crossInstance, msg);
recordChunkReadFailure(chunk, crossInstance, msg);
throw new BusinessException("similar ASIN chunk payload read failed chunk="
+ chunk.getChunkIndex() + ": " + msg, ex);
throw new BusinessException(UserMessages.with("读取货源查询结果分片失败,分片="
+ chunk.getChunkIndex(), msg), ex);
}
return rows;
}
@@ -141,7 +143,21 @@ public class SimilarAsinChunkPayloadSupport {
from = end + 1;
}
}
return String.join(", ", tags);
if (tags.isEmpty()) {
return "";
}
List<String> readable = new ArrayList<>();
for (String tag : tags) {
int open = tag.indexOf('[');
String body = open < 0 ? tag : tag.substring(open + 1, tag.length() - 1);
boolean cross = body.endsWith("@cross-instance");
if (cross) {
body = body.substring(0, body.length() - "@cross-instance".length());
}
readable.add(cross ? "第 " + body + " 分片跨实例读取失败"
: "第 " + body + " 分片读取失败");
}
return String.join(";", readable);
} catch (Exception ex) {
log.warn("[similar-asin] collect chunk-read-failure summary failed taskId={} err={}", taskId, ex.getMessage());
return "";
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.similarasin.service.support;
import com.nanri.aiimage.common.util.UserMessages;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fasterxml.jackson.databind.JsonNode;
@@ -197,7 +198,7 @@ public class SimilarAsinHistoryAssembler {
vo.setFileProgressCurrent(current);
vo.setFileProgressTotal(total);
vo.setFileProgressPercent(percent);
vo.setFileProgressMessage(snapshot.getMessage());
vo.setFileProgressMessage(UserMessages.orFallback(snapshot.getMessage(), ""));
}
private void attachLlmProgress(SimilarAsinHistoryItemVo vo,
@@ -412,8 +413,8 @@ public class SimilarAsinHistoryAssembler {
log.warn("[similar-asin] read chunk payload failed taskId={} chunk={} crossInstance={} err={}",
chunk.getTaskId(), chunk.getChunkIndex(), crossInstance, msg);
recordChunkReadFailure(chunk, crossInstance, msg);
throw new BusinessException("similar ASIN chunk payload read failed chunk="
+ chunk.getChunkIndex() + ": " + msg, ex);
throw new BusinessException(UserMessages.with("读取货源查询结果分片失败,分片="
+ chunk.getChunkIndex(), msg), ex);
}
return rows;
}
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.similarasin.service.support;
import com.nanri.aiimage.common.util.UserMessages;
import cn.hutool.crypto.digest.DigestUtil;
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinParsedPayloadDto;
import com.nanri.aiimage.modules.similarasin.model.dto.SimilarAsinResultGroupDto;
@@ -1490,9 +1491,9 @@ public class SimilarAsinPipelineSupport {
} catch (Exception ex) {
TaskFileJobEntity job = taskFileJobService.findAssembleJob(taskId, MODULE_TYPE, context.resultId());
if (job != null) {
taskFileJobService.markFailed(job, firstNonBlank(ex.getMessage(), "相似ASIN结果文件生成失败"));
taskFileJobService.markFailed(job, UserMessages.orFallback(ex.getMessage(), "相似ASIN结果文件生成失败"));
if (taskFileJobService.isRetryExhausted(job.getId())) {
host.finalizeExhaustedResultFileJob(job, ex.getMessage());
host.finalizeExhaustedResultFileJob(job, UserMessages.orFallback(ex.getMessage(), "相似ASIN结果文件生成失败"));
}
}
log.warn("[相似ASIN] LLM 异步收尾失败 任务ID={} 结果ID={} 错误={}",
@@ -141,12 +141,12 @@ public class SimilarAsinResultWorkbookAssembler {
List<SourceRows> sourceRows = splitRowsBySourceFile(
parsed, parsedRows, result.getSourceFilename());
if (sourceRows.isEmpty()) {
throw new BusinessException("Similar ASIN result rows are empty");
throw new BusinessException("这份文件没有解析到可导出的行,请稍后重试生成结果文件");
}
File outputDir = new File(storageProperties.getLocalTempDir(), "similar-asin-result");
if (!outputDir.exists() && !outputDir.mkdirs()) {
throw new BusinessException("failed to create result directory");
throw new BusinessException("创建结果目录失败");
}
List<SourceResultWorkbook> workbooks = new ArrayList<>();
List<File> workbookFiles = new ArrayList<>(sourceRows.size());
@@ -207,20 +207,20 @@ public class SimilarAsinResultWorkbookAssembler {
} catch (InterruptedException ex) {
cancelResultAssemblyFutures(futures);
Thread.currentThread().interrupt();
throw new BusinessException("result workbook assembly interrupted", ex);
throw new BusinessException("生成相似ASIN检测结果中断", ex);
} catch (TimeoutException ex) {
cancelResultAssemblyFutures(futures);
throw new BusinessException("result workbook assembly timed out", ex);
throw new BusinessException("生成相似ASIN检测结果超时(" + timeoutMinutes + " 分钟)", ex);
} catch (CancellationException ex) {
cancelResultAssemblyFutures(futures);
throw new BusinessException("result workbook assembly cancelled", ex);
throw new BusinessException("生成相似ASIN检测结果已取消", ex);
} catch (ExecutionException ex) {
cancelResultAssemblyFutures(futures);
Throwable cause = ex.getCause();
if (cause instanceof BusinessException businessException) {
throw businessException;
}
throw new BusinessException("result workbook assembly failed", cause == null ? ex : cause);
throw new BusinessException("生成相似ASIN检测结果失败", cause == null ? ex : cause);
}
int persistedResultRows = workbooks.stream()
@@ -242,8 +242,8 @@ public class SimilarAsinResultWorkbookAssembler {
if (resultRows == 0) {
String failureSummary = chunkPayloadSupport.collectChunkReadFailureSummary(task.getId());
throw new BusinessException(failureSummary.isBlank()
? "Similar ASIN result rows are empty; please retry result generation"
: "Similar ASIN result rows are empty (" + failureSummary + ")");
? "相似ASIN检测结果为空,请稍后重试生成结果文件"
: "相似ASIN检测结果为空(" + failureSummary + "),请稍后重试生成结果文件");
}
taskImageCache.clear();
@@ -941,7 +941,7 @@ public class SimilarAsinResultWorkbookAssembler {
return new SimilarAsinImageEmbedder.ImageSpool(
Files.createTempDirectory(outputDir.toPath(), "similar-asin-images-"));
} catch (IOException ex) {
throw new BusinessException("create Similar ASIN image spool failed", ex);
throw new BusinessException("创建相似ASIN图片临时目录失败", ex);
}
}
@@ -74,7 +74,7 @@ public class SimilarAsinTaskOwnershipSupport {
public TaskDistributedLockService.LockHandle requireTaskLock(Long taskId, long waitMillis) {
TaskDistributedLockService.LockHandle lockHandle = acquireTaskLock(taskId, waitMillis);
if (lockHandle == null) {
throw new BusinessException(40902, "Task is busy, please retry later");
throw new BusinessException(40902, "任务正被占用,请稍后重试");
}
return lockHandle;
}