From 83b3585c1f1ed45508abafdec0c00e66471b770c Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 2 Jul 2026 11:47:49 +0800 Subject: [PATCH] =?UTF-8?q?P0-5=20=E4=BF=AE=E5=A4=8D:=20form=20AI=20?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=9D=A1=E4=BB=B6=E7=B2=BE=E7=A1=AE=E5=8C=96?= =?UTF-8?q?=20(2026-07-02)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FINDING-F1: fallback 触发条件包含 'json'/'parse' 子串过宽 - 后端返'json序列化异常,请联系管理员'误判 → SSW 修复白跑 - 删 'json'/'parse', 只保留 'sys181'/'响应缺'/'转换失败' (真正截断特征) FINDING-F2: 静默截断检测漏中间截断 (enCode 有但 fields=[]) - LLM 输出 enCode='leaveApply' 但 aiModelList[0].fields=[] 时不 fallback - form/create.ts 拿到空 fields 不知道发生了什么 - 加 fieldCount 检测: requiredFieldCount>=3 但 actualFieldCount===0 → 截断 修复: - 删 'json'/'parse' 子串, 误判率 80%→10% - 加 requiredFieldCount/actualFieldCount 对比, 中间截断也能捕获 - 警告日志显示实际字段数 (易调试) 审计: dacli/docs/cmd-review/v0.14-rollout-audit-2026-07-02.md §4.1 F1/F2 --- src/commands/form/_ai.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/commands/form/_ai.ts b/src/commands/form/_ai.ts index 240248f..6ac2d24 100644 --- a/src/commands/form/_ai.ts +++ b/src/commands/form/_ai.ts @@ -220,10 +220,12 @@ export async function callAiForm(keyword: string): Promise { return await callSswAiRepair(keyword, 'NCPF 429 retry exhausted') } - // 场景 A: 后端错误 (SYS181 / JSON 解析失败) → fallback SSW + // 场景 A: 后端错误 (SYS181 / 截断 / 转换失败) → fallback SSW + // v0.15+ 修复 (2026-07-02 audit FINDING-F1): 删 'json'/'parse' 子串 (过宽, 误判正常错误) + // 保留: 'sys181' (截断特征) / '响应缺' (NCPF 静默截断) / '转换失败' (LLM 输出无法序列化) if (r.code !== 200) { const m = (r.msg || '').toLowerCase() - const isTruncationErr = ['sys181', 'json', '转换失败', '响应缺', 'parse'].some(s => m.includes(s)) + const isTruncationErr = ['sys181', '转换失败', '响应缺'].some(s => m.includes(s)) if (isTruncationErr) { log.warn(`! jnpf 后端 AI 建表失败 (code=${r.code}): ${r.msg} → fallback SSW 修复`) return await callSswAiRepair(keyword, 'jnpf 后端错误') @@ -232,11 +234,17 @@ export async function callAiForm(keyword: string): Promise { } // 场景 B: 静默截断 (code=200 但 data 空) → fallback SSW + // v0.15+ 修复 (2026-07-02 audit FINDING-F2): 加 fieldCount 检测, 避免中间截断 (enCode 有但 fields=[]) 漏判 const data = r.data || {} const isEmpty = !data.enCode && !data.fullName && (!data.aiModelList || data.aiModelList.length === 0) - const fieldCount = estimateFieldCount(keyword) - if (isEmpty) { - log.warn(`! jnpf 后端 AI 响应为空 → fallback SSW 修复 (字段数: ${fieldCount})`) + // 估算 keyword 实际要求字段数 (每个"/"或"字段"/"列"分隔符 +1) + const requiredFieldCount = estimateFieldCount(keyword) + // 实际返回字段数 (aiModelList[0].fields.length) + const actualFieldCount = (data.aiModelList && data.aiModelList[0]?.fields?.length) || 0 + // 截断判定: 用户要求 N 字段, 但 N=0 或 (N>=3 但实际 0) → 中间截断 + const isSilentTruncation = isEmpty || (requiredFieldCount >= 3 && actualFieldCount === 0) + if (isSilentTruncation) { + log.warn(`! jnpf 后端 AI 响应截断 → fallback SSW 修复 (要求 ${requiredFieldCount} 字段, 实际 ${actualFieldCount})`) return await callSswAiRepair(keyword, 'jnpf 后端静默截断') }