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
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.imagevideo.service;
import com.nanri.aiimage.common.util.UserMessages;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nanri.aiimage.common.exception.BusinessException;
@@ -204,7 +205,7 @@ public class ImageVideoAdminTaskService {
deleteQuietly(zipFile);
throw ex instanceof BusinessException business
? business
: new BusinessException("批量打包失败: " + messageOf(ex), ex);
: new BusinessException(UserMessages.with("批量打包失败", ex), ex);
}
}
@@ -124,7 +124,7 @@ public class ImageVideoAsyncTaskService {
.eq(ImageVideoAsyncTaskEntity::getId, taskId)
.eq(ImageVideoAsyncTaskEntity::getUserId, userId));
if (task == null) {
throw new BusinessException("Image video task not found");
throw new BusinessException("图像视频任务不存在");
}
ensureTaskOwnedByCurrentInstance(task, "query async task");
task = recoverFalseFailedTask(task);
@@ -260,7 +260,7 @@ public class ImageVideoAsyncTaskService {
private ImageVideoAsyncTaskVo submit(TaskType type, Long userId, Object payload) {
if (userId == null || userId <= 0) {
throw new BusinessException("userId is required");
throw new BusinessException("缺少用户 id");
}
LocalDateTime now = LocalDateTime.now();
ImageVideoAsyncTaskEntity task = new ImageVideoAsyncTaskEntity();
@@ -330,7 +330,7 @@ public class ImageVideoAsyncTaskService {
task.setResultJson(writeJson(result));
String businessError = resolveCozeBusinessError(result);
failTask(task, new BusinessException(businessError.isBlank()
? "Coze workflow finished with status " + cozeStatus
? "Coze 工作流已结束,状态 " + cozeStatus
: businessError));
} else {
completeTask(task, transformResult(type, result), cozeStatus);
@@ -338,7 +338,7 @@ public class ImageVideoAsyncTaskService {
return;
}
if (pollingDeadlineExceeded(task)) {
failTask(task, new BusinessException("Coze task exceeded the one-hour polling limit"));
failTask(task, new BusinessException("Coze 任务轮询已超过一小时上限"));
return;
}
task.setStatus(TaskStatus.WAITING.name());
@@ -348,7 +348,7 @@ public class ImageVideoAsyncTaskService {
} catch (Exception ex) {
// Coze history calls are retried by the next polling cycle until the task's overall deadline.
if (pollingDeadlineExceeded(task)) {
failTask(task, new BusinessException("Coze task exceeded the one-hour polling limit", ex));
failTask(task, new BusinessException("Coze 任务轮询已超过一小时上限", ex));
return;
}
task.setStatus(TaskStatus.WAITING.name());
@@ -423,7 +423,7 @@ public class ImageVideoAsyncTaskService {
if (requiresVideoResult(task) && !hasFinalVideoUrl(result)) {
task.setCozeStatus(normalizeStatus(cozeStatus));
task.setResultJson(writeJson(result));
failTask(task, new BusinessException("Coze workflow succeeded but video_url is empty"));
failTask(task, new BusinessException("Coze 工作流成功但没有返回视频地址"));
return;
}
task.setStatus(TaskStatus.SUCCESS.name());
@@ -458,7 +458,7 @@ public class ImageVideoAsyncTaskService {
return task;
}
String errorMessage = task.getErrorMessage() == null ? "" : task.getErrorMessage();
if (!errorMessage.startsWith("Coze workflow finished with status ")) {
if (!errorMessage.startsWith("Coze 工作流已结束,状态 ")) {
return task;
}
task.setStatus(TaskStatus.WAITING.name());
@@ -490,7 +490,7 @@ public class ImageVideoAsyncTaskService {
try {
return objectMapper.readValue(json, type);
} catch (Exception ex) {
throw new BusinessException("Image video task payload is invalid", ex);
throw new BusinessException("图像视频任务参数不合法", ex);
}
}
@@ -509,7 +509,7 @@ public class ImageVideoAsyncTaskService {
try {
return objectMapper.writeValueAsString(value);
} catch (Exception ex) {
throw new BusinessException("Image video task serialization failed", ex);
throw new BusinessException("图像视频任务序列化失败", ex);
}
}
@@ -1,5 +1,6 @@
package com.nanri.aiimage.modules.imagevideo.service;
import com.nanri.aiimage.common.util.UserMessages;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -209,7 +210,7 @@ public class ImageVideoCozeService {
public Map<String, Object> getWorkflowResult(Long userId, String workflowId, String executeId) {
String resolvedExecuteId = firstNonBlank(executeId);
if (!hasText(resolvedExecuteId)) {
throw new BusinessException("execute_id cannot be blank");
throw new BusinessException("任务执行 id 不能为空");
}
ImageVideoSecretService.ResolvedSecret secret = secretService.requireValid(userId);
String cozeToken = firstNonBlank(secret.cozeToken());
@@ -255,7 +256,7 @@ public class ImageVideoCozeService {
vo.setMediaType(mediaType);
return vo;
} catch (Exception ex) {
throw new BusinessException("媒体上传失败: " + ex.getMessage(), ex);
throw new BusinessException(UserMessages.with("媒体上传失败", ex), ex);
} finally {
if (tempFile != null && tempFile.exists() && !tempFile.delete()) {
log.warn("[image-video] temp media delete failed path={}", tempFile.getAbsolutePath());
@@ -314,7 +315,7 @@ public class ImageVideoCozeService {
String resolvedT8Key = firstNonBlank(t8Key);
String cozeToken = firstNonBlank(token);
if (!hasText(resolvedT8Key)) {
throw new BusinessException("image-video douyin copy t8_key not configured");
throw new BusinessException("未配置抖音文案密钥 t8_key");
}
if (!hasText(resolvedApiKey)) {
throw new BusinessException("图生视频抖音文案 api_key 未配置");
@@ -408,7 +409,7 @@ public class ImageVideoCozeService {
} catch (BusinessException ex) {
throw ex;
} catch (Exception ex) {
throw new BusinessException("Coze 返回解析失败: " + ex.getMessage());
throw new BusinessException(UserMessages.with("Coze 返回解析失败", ex));
}
}
@@ -453,7 +454,7 @@ public class ImageVideoCozeService {
} catch (Exception ex) {
log.warn("[image-video] parse douyin copy response failed bodyPreview={}",
responsePreview(responseText), ex);
throw new BusinessException("Coze 返回解析失败: " + ex.getMessage());
throw new BusinessException(UserMessages.with("Coze 返回解析失败", ex));
}
}
@@ -463,7 +464,7 @@ public class ImageVideoCozeService {
} catch (BusinessException ex) {
throw ex;
} catch (Exception ex) {
throw new BusinessException("Coze response parse failed: " + ex.getMessage(), ex);
throw new BusinessException(UserMessages.with("解析 Coze 响应失败", ex), ex);
}
}
@@ -609,7 +610,7 @@ public class ImageVideoCozeService {
Thread.currentThread().interrupt();
throw new BusinessException("Coze 调用被中断", ex);
} catch (Exception ex) {
throw new BusinessException("Coze 调用失败: " + ex.getMessage(), ex);
throw new BusinessException(UserMessages.with("Coze 调用失败", ex), ex);
}
}
@@ -639,7 +640,7 @@ public class ImageVideoCozeService {
Thread.currentThread().interrupt();
throw new BusinessException("Coze 调用被中断", ex);
} catch (Exception ex) {
throw new BusinessException("Coze 调用失败: " + ex.getMessage(), ex);
throw new BusinessException(UserMessages.with("Coze 调用失败", ex), ex);
}
}