feat: add bounded workflow decisions and durable result inbox

This commit is contained in:
2026-09-18 01:11:42 +08:00
parent 520e98d9d1
commit 0f7ac5203b
20 changed files with 1909 additions and 9 deletions

54
weave/engine/poll.go Normal file
View File

@@ -0,0 +1,54 @@
package engine
import (
"encoding/json"
"git.yuntuo.hk/k2safe/orbit/weave/definition"
)
// PollOutcome 仅分类一次成功查询的业务结果,不代表查询请求的Pulse执行状态。
type PollOutcome string
const (
PollPending PollOutcome = "PENDING"
PollSucceeded PollOutcome = "SUCCEEDED"
PollFailed PollOutcome = "FAILED"
PollNeedsReview PollOutcome = "NEEDS_REVIEW"
)
// ClassifyPoll 解释固定定义中的结果映射;轮次/时限/信号竞态仍由持久化运行器决定。
func (p *Program) ClassifyPoll(key string, raw json.RawMessage) (PollOutcome, error) {
node, ok := p.nodes[key]
if !ok || node.Poll == nil {
return "", problem(key, "NOT_A_POLL_STEP")
}
result, err := classifyPoll(*node.Poll, raw)
if err != nil {
return "", problem(key, "POLL_RESULT_INVALID")
}
return result, nil
}
func classifyPoll(p definition.Poll, raw json.RawMessage) (PollOutcome, error) {
if err := definition.ValidateData(p.Task.ResultType, raw); err != nil {
return "", err
}
status, err := resolve(definition.Value{Kind: "REFERENCE", Reference: &definition.Reference{Source: "result", Path: p.StatusPath}}, definition.Type{Kind: "STRING"}, values{"result": raw})
if err != nil {
return "", err
}
var value string
if err := json.Unmarshal(status, &value); err != nil {
return "", err
}
for _, group := range []struct {
values []string
outcome PollOutcome
}{{p.Pending, PollPending}, {p.Succeeded, PollSucceeded}, {p.Failed, PollFailed}, {p.Review, PollNeedsReview}} {
for _, candidate := range group.values {
if value == candidate {
return group.outcome, nil
}
}
}
return "", problem("", "UNMAPPED_POLL_RESULT")
}