fix(agent): 画布写入 - 漏 patch 按参数错误回给模型而不是终止整轮 (#566)
Original-Commit: a7df2b57c72e479200b82d0af88446d43fa9f9dd fix(agent): 画布写入 - 漏 patch 按参数错误回给模型而不是终止整轮 审批模式下模型用 canvas_apply_ops 做 update_node 时漏了 patch,准入预检直接返回普通 BadAuthRequest,运行期按"准入失败"处理 → 整轮 failed,用户只看得到一句"更新节点必须提供 patch", 模型没有改正机会。批量创作表、分镜、画布读取参数都已把同类错误包成 cloudAgentArgumentError (运行期 errors.As 后作为工具结果回给模型重试),这里补齐。 未知画布写操作仍按准入失败终止(既有用例断言不变);新增用例同时钉住这两条。
This commit is contained in:
1 parent
b5da3deee8
commit
4dd3b554a5
2 files changed
+27
-1
No files matched your search
@@ -153,7 +153,10 @@ func applyCloudAgentCanvasPlan(doc map[string]any, ops []agentCanvasOp) ([]cloud
|
|||||||
})
|
})
|
||||||
case "update_node":
|
case "update_node":
|
||||||
if len(op.Patch) == 0 {
|
if len(op.Patch) == 0 {
|
||||||
return nil, BadAuthRequest("更新节点必须提供 patch")
|
// 漏字段是模型照 schema 就能自己修好的参数错误:当成工具结果回给它重试,
|
||||||
|
// 而不是判整轮失败(用户只在失败提示里看到一句"必须提供 patch")。
|
||||||
|
// 未知操作类型仍按准入失败终止(cloud_agent_test.go 有用例断言这一行为)。
|
||||||
|
return nil, &cloudAgentArgumentError{BadAuthRequest("更新节点必须提供 patch")}
|
||||||
}
|
}
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
return nil, BadAuthRequest("只能更新现有且受 Agent 支持的节点")
|
return nil, BadAuthRequest("只能更新现有且受 Agent 支持的节点")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -81,3 +82,25 @@ func TestCloudAgentCanvasApprovalPreviewRejectsUnknownTargetInsteadOfFallingBack
|
|||||||
t.Fatalf("unknown target was not rejected: %v", err)
|
t.Fatalf("unknown target was not rejected: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 漏 patch 必须是**可恢复的参数错误**:运行期会把它当工具结果回给模型重试,
|
||||||
|
// 而不是把整轮判死;未知操作类型(例如删除)仍按准入失败终止。
|
||||||
|
func TestCloudAgentCanvasApprovalPreviewTreatsMissingPatchAsArgumentError(t *testing.T) {
|
||||||
|
doc, err := creationDocument(`{"nodes":[{"id":"image-1","type":"image","title":"参考图"}],"connections":[]}`)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = applyCloudAgentCanvasPlan(doc, []agentCanvasOp{{Type: "update_node", ID: "image-1"}})
|
||||||
|
var argumentErr *cloudAgentArgumentError
|
||||||
|
if !errors.As(err, &argumentErr) {
|
||||||
|
t.Fatalf("漏 patch 应当是可恢复的参数错误,实际:%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = applyCloudAgentCanvasPlan(doc, []agentCanvasOp{{Type: "delete_node", ID: "image-1"}})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("未知画布写操作必须仍然报错")
|
||||||
|
}
|
||||||
|
if errors.As(err, &argumentErr) {
|
||||||
|
t.Fatalf("未知画布写操作不能被当成可恢复的参数错误:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user