feat: add durable safe retries with uncertainty tracking and SDK examples

This commit is contained in:
2026-09-17 15:43:44 +08:00
parent 9e3d4be5cc
commit d65cf96ea7
44 changed files with 1300 additions and 77 deletions

View File

@@ -120,6 +120,9 @@ func (s *Service) Finish(ctx context.Context, t auth.Token, b Binding, message c
if in.Outcome != "SUCCEEDED" && in.Outcome != "FAILED" && in.Outcome != "UNKNOWN" {
return CommandResult{}, fault.Invalid("invalid result outcome")
}
if in.Retryable && in.Outcome != "FAILED" {
return CommandResult{}, fault.Invalid("retryable is only valid for known failure")
}
if len(in.Result) == 0 || len(in.Result) > 256<<10 || bytes.Equal(bytes.TrimSpace(in.Result), []byte("null")) {
return CommandResult{}, fault.Invalid("result must be non-null JSON up to 256 KiB")
}

View File

@@ -77,6 +77,7 @@ type FinishInput struct {
Outcome string `json:"outcome"` // Outcome 为 SUCCEEDED、FAILED 或 UNKNOWN。
Result json.RawMessage `json:"result"` // Result 非 null JSON 结果或证据引用,最多 256 KiB。
ErrorCode string `json:"error_code,omitempty"` // ErrorCode FAILED/UNKNOWN 必填稳定分类,不包含原始异常正文。
Retryable bool `json:"retryable,omitempty"` // Retryable 仅 FAILED 可为真,声明该明确失败可安全重试;默认假。
}
// Receipt 是不可变的操作回执,不代表当前仍有执行权。