fix(agent): 画布审批 - 大事件改用快照刷新避免执行回滚

This commit is contained in:
tanzui
2026-10-09 10:11:49 +08:00
parent e54a1c46a5
commit 0b7fb7120f
5 changed files with 197 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"sort"
"strings"
"unicode/utf8"
@@ -19,6 +20,8 @@ import (
"yingce/backend/internal/prompts"
)
const cloudAgentEventPayloadLimit = 128 << 10
func cloudAgentDecode(run *model.CloudAgentExecution) (cloudAgentRuntime, error) {
var state cloudAgentRuntime
if run == nil || strings.TrimSpace(run.StateJSON) == "" {
@@ -262,7 +265,7 @@ func validateCloudAgentRuntime(run *model.CloudAgentExecution, state *cloudAgent
return err
}
raw, err := json.Marshal(event.Payload)
if err != nil || len(raw) > 128<<10 {
if err != nil || len(raw) > cloudAgentEventPayloadLimit {
return errors.New("Agent runtime event payload is too large")
}
}
@@ -471,6 +474,9 @@ func cloudAgentSave(run *model.CloudAgentExecution, state *cloudAgentRuntime) er
}
if run.ID != "" {
if err := validateCloudAgentRuntime(run, state); err != nil {
// HTTP 日志只记录错误类型;在首次校验失败处保留原因,避免被后续模型错误掩盖。
// 不记录完整检查点、提示词或工具参数,日志仅用于定位失败步骤。
log.Printf("[Agent] checkpoint validation failed run=%s step=%d call_index=%d: %v", run.ID, state.Step, state.CallIndex, err)
return cloudAgentCheckpointFailure("runtime validation", err)
}
for index, event := range state.Events {