feat(work): require verified graph result fan-in
CI / test (push) Successful in 50s
CI / test (pull_request) Successful in 44s

This commit is contained in:
m
2026-08-23 18:05:23 +03:00
parent ee16103e03
commit 1f8af98f31
9 changed files with 147 additions and 17 deletions
+46
View File
@@ -15,6 +15,7 @@ import (
var ErrGraphDispatchBinding = errors.New("graph node dispatch binding is missing")
var ErrTaskEvaluationCallbackMismatch = errors.New("task evaluation callback does not match graph node")
var ErrGraphResultCallbackMismatch = errors.New("graph result callback does not match graph node")
type GraphScheduleRequest struct {
Graph work.WorkGraph `json:"graph"`
@@ -82,6 +83,51 @@ func SynthesizeGraph(ctx context.Context, store ports.GraphResultStore, request
return conflict, synthesis, nil
}
// RecordGraphResultCandidate persists attributable agent output. The graph is
// immutable by revision, so candidate recording does not rewrite the node;
// only verified synthesis may create the next successful graph revision.
func RecordGraphResultCandidate(ctx context.Context, candidateStore ports.GraphCandidateStore, graphStore ports.GraphStore, request work.GraphResultCallback) (work.WorkGraph, error) {
candidate := request.Candidate
if candidateStore == nil || request.GraphID == "" || request.Revision < 1 || candidate.ID == "" || candidate.GraphID != request.GraphID || candidate.GraphRevision != request.Revision || candidate.NodeID == "" || candidate.AuthorRunID == "" || candidate.EvidenceSummary == "" || candidate.Summary == "" {
return work.WorkGraph{}, ErrGraphResultCallbackMismatch
}
graph, err := graphStore.LoadWorkGraph(ctx, request.GraphID, request.Revision)
if err != nil {
return work.WorkGraph{}, err
}
found := false
for i := range graph.Nodes {
if graph.Nodes[i].ID != candidate.NodeID {
continue
}
found = true
if graph.Nodes[i].State == work.GraphNodeSuccess || graph.Nodes[i].State == work.GraphNodeCancel {
return work.WorkGraph{}, ErrGraphResultCallbackMismatch
}
}
if !found {
return work.WorkGraph{}, ErrGraphResultCallbackMismatch
}
if err := candidateStore.SaveGraphResultCandidate(ctx, candidate); err != nil {
return work.WorkGraph{}, err
}
return graph, nil
}
// SynthesizeAndCompleteGraph is the only path that turns a verifying node
// into success: synthesis must be independently verified first.
func SynthesizeAndCompleteGraph(ctx context.Context, resultStore ports.GraphResultStore, graphStore ports.GraphStore, request GraphSynthesisRequest) (work.ConflictSet, work.GraphSynthesisCandidate, work.WorkGraph, error) {
conflict, synthesis, err := SynthesizeGraph(ctx, resultStore, request)
if err != nil {
return work.ConflictSet{}, work.GraphSynthesisCandidate{}, work.WorkGraph{}, err
}
graph, err := CompleteGraphNode(ctx, graphStore, conflict.GraphID, conflict.GraphRevision, conflict.NodeID, true)
if err != nil {
return work.ConflictSet{}, work.GraphSynthesisCandidate{}, work.WorkGraph{}, err
}
return conflict, synthesis, graph, nil
}
func AdmitAndSchedule(ctx context.Context, store ports.GraphStore, request GraphScheduleRequest) (work.WorkGraph, []work.GraphNodeID, error) {
if request.Now < 1 {
request.Now = time.Now().UnixMilli()
+4
View File
@@ -18,6 +18,10 @@ type GraphResultStore interface {
SaveGraphSynthesis(context.Context, work.ConflictSet, []work.ResultCandidate, work.GraphSynthesisCandidate) error
}
type GraphCandidateStore interface {
SaveGraphResultCandidate(context.Context, work.ResultCandidate) error
}
// TaskEvaluationSink is a remote-capable boundary to Capability's owner.
// Work never writes the capability schema directly.
type TaskEvaluationSink interface {