diff --git a/apps/detail-agent-pi/src/native-bridge.mjs b/apps/detail-agent-pi/src/native-bridge.mjs index 9381a8a9..300c09f5 100644 --- a/apps/detail-agent-pi/src/native-bridge.mjs +++ b/apps/detail-agent-pi/src/native-bridge.mjs @@ -110,7 +110,7 @@ export class Native98kBroker { if (this.closed) throw Error('模型桥已关闭'); return new Promise((resolve, reject) => { this.active = { resolve, reject, onEvent, method, requestId: args.id }; - if (method === 'request' && args.id) this.potentiallyDispatched.add(args.id); + if (method === 'request' && args.id && args.inference !== true) this.potentiallyDispatched.add(args.id); try { this.child.stdin.write(JSON.stringify({ method, project: this.project, accountScope: this.scope, ...(this.modelRole==='chat'?{}:{modelRole:this.modelRole}), ...(this.detailSlot?{detailSlot:this.detailSlot}:{}), ...args }) + '\n', error => { if (error && this.active) { this.failed = Error('模型桥连接中断;请核查原请求,不会重发'); const active = this.active; this.active = null; active.reject(this.failed); this.child.kill(); } }); } catch { this.failed = Error('模型桥连接中断;请核查原请求,不会重发'); this.active = null; reject(this.failed); this.child.kill(); } @@ -195,6 +195,7 @@ export class Native98kBroker { if (!completed) return { phase: 'not_dispatched' }; const result = await completed; if (result.phase === 'failed' && result.failureCode === 'rate_limit_exceeded') return result; + if (inference && result.phase === 'unknown') return result; if (result.phase !== 'received') throw Error(`请求 ${id} 结果未知;不会重发`); return this.start('finish', { id, bodyHash: metadata.bodyHash, valid, reason }); }, diff --git a/apps/detail-agent-pi/test/native-wire.test.mjs b/apps/detail-agent-pi/test/native-wire.test.mjs index 170c2f9b..4d7b933a 100644 --- a/apps/detail-agent-pi/test/native-wire.test.mjs +++ b/apps/detail-agent-pi/test/native-wire.test.mjs @@ -239,6 +239,54 @@ test('ordinary chat resumes the same turn through Pi after a confirmed rate limi } finally { await x.close(); } }); +test('an HTTP 503 native inference receipt reaches Pi retry in the same one-click goal', async t => { + const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'pi-recovery-')); + let host; + t.after(async()=>{ await host?.dispose(); await cleanup(dir); }); + const scope = 'b'.repeat(64), project=randomUUID(); + const store = await ProjectStore.open(dir, {scope,project}, {brandId:'qa',shopId:'shop',categoryId:'qa',platform:'qa',version:'1',source:'qa',rules:[]}); + const requests=[], finished=[], operations=[]; + const originalId=randomUUID(); + const broker = new Native98kBroker({project,profile:dir,modelRole:'detail'}); + broker.scope=scope; + broker.info=async()=>({accountScope:scope,model:{id:'qa',protocol:'openai-responses',supportsImageInput:true},pending:[]}); + broker.status=async()=>({pending:[]}); + broker.forDetailSlot=()=>broker; + const event=(type,details)=>'event: '+type+'\ndata: '+JSON.stringify({type,...details})+'\n\n'; + const item={id:'fc_ok',type:'function_call',call_id:'call_ok',name:'finish_production',arguments:'{"revision":7}'}; + const response=event('response.output_item.added',{output_index:0,item:{...item,arguments:''}}) + +event('response.function_call_arguments.delta',{output_index:0,delta:item.arguments}) + +event('response.output_item.done',{output_index:0,item}) + +event('response.completed',{response:{model:'qa',status:'completed',output:[item]}}); + broker.start=async(method,input,emit)=>{ + if(method==='finish'){finished.push(input.id);return {phase:'complete'};} + assert.equal(method,'request'); + requests.push(input); + const success=input.inference===true && requests.length>1; + emit({type:'headers',status:success?200:503,requestId:success?randomUUID():originalId, + headers:{'content-type':success?'text/event-stream':'application/json'},bodyHash:'native-wire'}); + const error=JSON.stringify({error:{code:'service_unavailable',type:'server_error',message:'Service temporarily unavailable'}}); + emit({type:'chunk',data:Buffer.from(success?response:error).toString('base64')}); + return success?{phase:'received'}:{phase:'unknown',requestId:originalId}; + }; + const canvas={begin:async()=>({}),read:async()=>({conversationActive:true}),detailImages(){},activity:async()=>{},delta:async()=>{},end:async()=>{}}; + const productionGoal={outputId:'detail',variantId:randomUUID(),deadline:Math.floor(Date.now()/1000)+90}; + host=await DetailPiAgent.open({store,broker,canvas,productionGoal,callBudget:4}); + host.productionOperations=Promise.resolve({close:async()=>{},finish_production:async input=>{ + operations.push(input.revision); + return {text:'已核对导出。',production:{...productionGoal,complete:true,canvasRevision:input.revision}}; + }}); + const resumed=await host.prompt('继续制作当前画布'); + assert.equal(resumed.production.complete,true); + assert.deepEqual(operations,[7]); + assert.deepEqual(finished,[requests[1].id]); + assert.notEqual(requests[0].id,requests[1].id); + assert.equal(requests[0].body,requests[1].body); + const guarded=broker.round(); + await guarded.fetch('https://api.vip98k.com/v1/responses',{method:'POST',body:'{}'}); + await assert.rejects(guarded.finish(false,'error'),/结果未知;不会重发/u); +}); + test('the one-click goal resumes on changed fields at the same count without naming the next tool',async()=>{ const plan=n=>sse({tool_calls:[{index:0,id:'plan-'+n,type:'function',function:{name:'plan_production',arguments:'{}'}}]},'tool_calls'); let plans=0; diff --git a/docs/development/xiaoyi/implementation.md b/docs/development/xiaoyi/implementation.md index ebb8861c..0a68d0b8 100644 --- a/docs/development/xiaoyi/implementation.md +++ b/docs/development/xiaoyi/implementation.md @@ -584,3 +584,12 @@ R8 详情页的 Pi 草稿回执指出首批图位分派失败、未完成图文 电脑桌 R9 中,Pi 在组合工具内读取正式 Skill 后请求画布摘要 `maxDepth=6`,旧参数声明在进入原生端前拒绝,实机证据见 `batch-09/desk-batch-delegation-r9/codemode-exception-evidence.json`。Pi 工具与原生读取均接受非负整数深度。实际图层树决定可读取的内容,回执保留既有分页,项目读作用域继续核对。省略深度时仍返回浅层摘要。 深层七组的 PhotoCraft 夹具读取到深度 6,浅层、分页和非法参数行为有定向覆盖。Pi 参数验证与转发测试通过,Node 262 项通过,原生画布读 9 项通过,Windows 新构建通过。证据为 `batch-09/canvas-summary-depth-targeted.log`、`canvas-summary-depth-npm.log`、`canvas-summary-depth-native.log`、`canvas-summary-depth-native-build.log`。 + + +### 原生 HTTP 503 回执交给 Pi 的推理重试 + +R9 详情页原请求 `6c9f6c53-334e-4164-aa19-7d510d45e734` 返回 HTTP 503 和 `service_unavailable`,原生端存了纯推理记录。JS 桥接在结束时用通用未知结果错误覆盖了 Pi 已解析的真实响应,详情直接留稿。证据在 `batch-09/desk-batch-delegation-r9/inference-503-evidence.json`。 + +纯推理的未知回执交由调用方保留原记录及 Pi 的原始错误类型,使用 Pi SDK 已有设置决定是否重试。进程内待核查集合只追踪须保留的副作用类调用。付费生图、确认原操作及写画布的原编号处理保持现有契约。 + +从小壹的生产入口用 Responses 合成 HTTP 503,验证 Pi 在同一目标上按默认退避重试,拿到完整函数回执后执行一次工具;隔离的未知非推理调用保持不可重发。三项定向、263 项 Node 回归通过,见 `batch-09/native-503-pi-retry-targeted.log`、`native-503-pi-retry-npm.log`。当前 R9 仍使用启动前的构建。