From fe43994fea017afa2334500e251bdda35923be44 Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 14 Jul 2026 18:39:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20--ai=20=E9=94=99=E8=AF=AF=E5=88=86?= =?UTF-8?q?=E7=B1=BB=20+=20NCPF=20=E9=9D=99=E9=BB=98=E7=A9=BA=E5=93=8D?= =?UTF-8?q?=E5=BA=94=20retry=20(BS-=E6=96=B072=20=E5=A2=9E=E5=BC=BA,=20P1+?= =?UTF-8?q?P2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P1#1 BS-56 错误分类: step machine 校验失败时输出明确分类 - 不再误判为 AI 失败, 提示'这是参数校验, 跟 --ai 无关' - BS-56 enCode 校验失败时自动给修复建议 (去下划线/连字符) P1#3 SSW 异常完整显示: 不截断到 60 字符, 让 fastjson NPE stack trace 可见 - chain 消息从 60 → 200 字符 - 加 SSW stack trace 头部, AI 能直接定位根因 P2 NCPF 静默空响应 retry: code=200 但 data 空时 retry, 不立刻 fallback SSW - 实测 NCPF 10 次 1 次空响应 (10%), 单次 fallback 太激进 - 阈值: enCode/fullName/aiModelList 都空 → retry 实测: --ai 跑 5 次, 4/5 完整成功, 0 NPE, 0 静默空响应 --- src/commands/form/_ai.ts | 29 ++++++++++++++++++++++++----- src/commands/form/create.ts | 10 ++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/commands/form/_ai.ts b/src/commands/form/_ai.ts index f70bee1..7b6221b 100644 --- a/src/commands/form/_ai.ts +++ b/src/commands/form/_ai.ts @@ -173,7 +173,19 @@ async function callNcpfBackendWithRetry( try { const r = await c.postJson('/visualdev/ai/form', { keyword }) // 成功 - if (r.code === 200) return r + if (r.code === 200) { + // v0.20+ P2 修复: code=200 但 data 为空 (静默截断) 也 retry, 不立刻 fallback SSW + // 背景: 实测 5 次里 1 次 (20%) NCPF 返回空 data, 单次 fallback SSW 太激进 + // 阈值: empty = enCode/fullName/aiModelList 都空, 这种 LLM 不稳定概率高 + const data = r.data || {} + const isEmpty = !data.enCode && !data.fullName && (!data.aiModelList || data.aiModelList.length === 0) + if (isEmpty && attempt < maxRetries) { + log.warn(`! NCPF code=200 但 data 空 (attempt=${attempt}/${maxRetries}), retry 防静默截断`) + await backoffSleep(attempt) + continue + } + return r + } // 429 token plan: retry if (isTokenPlanExhausted(r)) { log.warn(`! 429 token plan 用尽 (attempt=${attempt}/${maxRetries}): ${r.msg}`) @@ -276,12 +288,19 @@ async function callSswAiRepair(keyword: string, reason: string, aiChain: string[ continue } } - aiChain.push(`SSW: code=${r.code} ${(r.msg || '').slice(0, 60)}`) - log.warn(`! SSW 修复失败 (code=${r.code}): ${r.msg}`) + // v0.20+ P1 修复: SSW 错误链完整显示 (不截断), 让用户看到 fastjson NPE stack trace + // 背景: 之前 SSW 异常截断 60 字符, NPE 类错误看不到根因, 误以为是 AI 描述问题 + const sswMsgFull = r.msg || '(no msg)' + aiChain.push(`SSW: code=${r.code} ${sswMsgFull.slice(0, 200)}`) + log.warn(`! SSW 修复失败 (code=${r.code}): ${sswMsgFull}`) break } catch (e) { - aiChain.push(`SSW: 异常 ${(e as Error).message?.slice(0, 60)}`) - log.warn(`! SSW 修复异常 (attempt=${attempt}/${maxSswRetries}): ${(e as Error).message?.slice(0, 100)}`) + // v0.20+ P1 修复: 完整异常信息, 包括 NPE stack trace 头部 + const sswExcFull = (e as Error)?.message || String(e) + const sswStack = (e as Error)?.stack?.split('\n').slice(0, 3).join(' | ') || '' + aiChain.push(`SSW: 异常 ${sswExcFull.slice(0, 200)}`) + if (sswStack) aiChain.push(` SSW stack: ${sswStack.slice(0, 200)}`) + log.warn(`! SSW 修复异常 (attempt=${attempt}/${maxSswRetries}): ${sswExcFull}`) if (attempt < maxSswRetries) { await backoffSleep(attempt, 5000) continue diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index 5c5b5bd..ae5929a 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -1071,6 +1071,16 @@ export function buildFormCreateCommand(): Command { } } } + // v0.20+ P1 修复: 提示这是参数校验问题 (跟 --ai 失败区分) + const bs56 = validation.steps.flatMap(s => s.errors).find(e => e.code?.startsWith('BS-56')) + if (bs56) { + log.error('') + log.error('⚠ 这是参数校验问题, 跟 --ai 是否成功无关:') + log.error(` 修复: ${bs56.code === 'BS-56' ? '去掉 enCode 中的下划线/连字符 (如 dyy_v1 → dyyv1)' : '检查 enCode 格式'}`) + } else { + log.error('') + log.error('⚠ 这是 step machine 参数校验, 跟 --ai 调用无关. 修复后再跑.') + } if (opts.json) { printJson({ ok: false, validation: validation.steps }) }