mirror of
https://gitcode.com/JianFeeeee/homeagent-sdk.git
synced 2026-10-31 14:27:30 +00:00
fix(commondev): 投递任务改成真异步,不再同步等 pi 跑完
## 缺陷(用户质疑"投递不就是发一条消息"后实测确认)
`deliverToPi` 的注释写着"把给 pi 发消息包装一下",但实际是:
await s.prompt(text) // 同步等 pi 把**整个任务**跑完
而 pi/zcode 开工程线干活(克隆/改代码/跑测试)要几十秒到 20 分钟。
生产日志实测两次:
23:04:03 executing tool: output_send__commondev_br-...
23:05:03 ★ timed out after 60s
通道的语义是"**投递**任务"(见 outputch 描述),不是"等完成"。
把它实现成同步等待,就必然撞上内核的 60s 工具超时。
★ 我一开始的诊断是错的:以为"超时值太小",给 output_send 声明了 3m
—— 那是掩盖症状。投递本该瞬时返回,慢是 bug 不是需求。已撤回。
## 改动
投递 → 立即回 status=accepted(瞬时)
→ pi 在后台跑
→ 跑完推**主动通知**(id=0)
→ Go 侧 onNotify 经 inputch 注入回 agent
`sidecar.go` 的 readLoop 里早就留好了这个扩展位:
if resp.ID == 0 { // 主动通知(暂未使用,保留扩展位)
现在接上了 `makePromptNotifier`。
pi 与 zcode 两份 sidecar.mjs 都改了(rawfile/ 里那两份同步更新)。
## 判据抓到我三次(都是真问题)
1. `TestSidecarScriptShipsWithPackage`:rawfile/ 与工程根不一致
—— 我只改了根那份
2. `TestZcodeMissingCLIErrorIsActionable`:`inflight is not defined`
—— zcode 版用了未声明变量
3. 同一条判据随后**卡死 2 分钟**:CLI 不存在本该立刻报,异步后错误
被吞进后台通知 ⇒ 用户先收到"已受理"、几秒后才知道配置错。
改成**受理阶段就校验 CLI**(配置错是立刻可判定的,不该推迟)。
判据还逼我保住语义:原 `TestZcodeSidecarArgvBehavior` 断言首轮拿到
真实 `sess_` id,异步后要到完成通知里才有 —— 断言保留、改从通知取,
没有削弱。
## 真机 e2e(三条全过,都要求真改工程文件)
TestZcodeFullPipeline 42.1s
TestZcodeOverSSH 72.4s
TestZcodeOverSSHWithPerHostEndpoints 75.1s
受理现在是瞬时的 ⇒ 内核工具不会再 60s 超时。
This commit is contained in:
@ -1347,6 +1347,13 @@ func (p *Plugin) deliverToPi(branchID string, cargs map[string]interface{}) (int
|
||||
return nil, fmt.Errorf("投递给 pi 失败: %w", err)
|
||||
}
|
||||
|
||||
// ★ 现在是**异步投递**(2026-10-17 修):sidecar 立即回 "accepted",
|
||||
// 真正跑完时用主动通知(id=0)回投,见 sidecar.go 的 onNotify。
|
||||
//
|
||||
// 原实现同步等 pi 跑完 ⇒ 内核 60s 工具超时先到,报「执行超时(60秒)」,
|
||||
// 而任务其实还在正常跑(生产实测两次)。
|
||||
// 通道的语义是"投递任务",不是"等任务完成"。
|
||||
|
||||
// ★ 纪律 4:断言 session 未变 —— 变了即响亮失败(不静默改投新会话)
|
||||
got := wantSession
|
||||
if m, ok := res.(map[string]interface{}); ok {
|
||||
@ -1360,8 +1367,17 @@ func (p *Plugin) deliverToPi(branchID string, cargs map[string]interface{}) (int
|
||||
return nil, fmt.Errorf("%s", msg)
|
||||
}
|
||||
|
||||
p.recordDelivery(branchID, got, payload, "sent", "")
|
||||
return map[string]interface{}{"status": "sent"}, nil
|
||||
p.recordDelivery(branchID, got, payload, "accepted", "")
|
||||
// ★ status 用 "accepted" 而不是 "sent":
|
||||
// sent 会让人以为"pi 已经干完了",而实际只是**排队受理**。
|
||||
// 内核的 executeOutputSendTool 会把 "queued"/"unconfirmed" 当成
|
||||
// "结果未知"回报给模型(见 output.go),accepted 走正常成功路径
|
||||
// 但语义诚实:任务已送达、结果稍后回投。
|
||||
return map[string]interface{}{
|
||||
"status": "accepted",
|
||||
"note": "任务已投递给 pi,完成结果稍后经 inputch 回投",
|
||||
"session": got,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Plugin) recordDelivery(branchID, sessionID, text, status, note string) {
|
||||
|
||||
Reference in New Issue
Block a user