feat(work): schedule bounded additional evaluations

This commit is contained in:
m
2026-08-23 23:37:56 +03:00
parent fb6b5e9677
commit 1b4284592b
4 changed files with 90 additions and 2 deletions
+33
View File
@@ -29,6 +29,19 @@ type TaskEvaluationScheduleRequest struct {
Now int64 `json:"now_unix_millis"`
}
// TaskEvaluationExpansionScheduleRequest carries a typed expansion decision
// from Capability to Work. Capability owns the decision and test-case
// construction; Work owns durable graph lineage, persistence and dispatch.
type TaskEvaluationExpansionScheduleRequest struct {
Profile capability.TaskEvaluationProfile
Cases []capability.TaskEvaluationCase
ParentGraphState work.GraphState
TriggerEvidenceRef string
Plan work.TaskEvaluationGraphRequest
Intents []work.AgentDispatchIntent
Now int64
}
type GraphCompleteRequest struct {
GraphID string `json:"graph_id"`
Revision int64 `json:"revision"`
@@ -229,6 +242,26 @@ func AdmitAndScheduleTaskEvaluation(ctx context.Context, store ports.GraphStore,
return AdmitAndSchedule(ctx, store, GraphScheduleRequest{Graph: graph, Intents: intents, Now: request.Now})
}
// ScheduleAdditionalTaskEvaluation is the runtime hand-off for the
// "general-first, additional-when-unresolved" policy. Capability decides
// whether to expand and supplies the bounded cases; this function never
// invents cases or chooses a model, and only persists/enqueues the new graph.
func ScheduleAdditionalTaskEvaluation(ctx context.Context, store ports.GraphStore, request TaskEvaluationExpansionScheduleRequest) (work.WorkGraph, []work.GraphNodeID, error) {
if request.Profile.Stage != capability.TaskEvaluationAdditional || request.Profile.ParentProfileID == "" || request.TriggerEvidenceRef == "" || len(request.Cases) == 0 {
return work.WorkGraph{}, nil, errors.New("additional task evaluation lineage is incomplete")
}
plan := request.Plan
plan.Profile = request.Profile
plan.Cases = append([]capability.TaskEvaluationCase(nil), request.Cases...)
plan.ParentGraphState = request.ParentGraphState
plan.TriggerEvidenceRef = request.TriggerEvidenceRef
graph, ready, err := AdmitAndScheduleTaskEvaluation(ctx, store, TaskEvaluationScheduleRequest{Plan: plan, Intents: request.Intents, Now: request.Now})
if err != nil {
return work.WorkGraph{}, nil, err
}
return graph, ready, nil
}
func CompleteGraphNode(ctx context.Context, store ports.GraphStore, graphID string, revision int64, nodeID work.GraphNodeID, success bool) (work.WorkGraph, error) {
graph, err := store.LoadWorkGraph(ctx, graphID, revision)
if err != nil {
@@ -45,3 +45,35 @@ func TestAdmitAndScheduleTaskEvaluationCarriesSpecialistContext(t *testing.T) {
t.Fatalf("specialist context was not carried into dispatch: %+v", store.intents)
}
}
func TestExpandAndScheduleTaskEvaluationCreatesAdditionalDurableGraph(t *testing.T) {
store := &taskGraphStore{}
additional := capability.TaskEvaluationProfile{ID: "profile-additional", Revision: 1, CapabilityID: "capability-chat", Stage: capability.TaskEvaluationAdditional, ParentProfileID: "profile-general", TriggerEvidenceRef: "artifact-unresolved", BenchmarkVersion: "additional-v1", RequiredCaseIDs: []string{"case-a:reproduce", "case-a:address-failure"}, QualityWeightMillis: 600, ReliabilityWeightMillis: 300, LatencyWeightMillis: 100}
request := TaskEvaluationExpansionScheduleRequest{
Profile: additional, Cases: []capability.TaskEvaluationCase{{CaseID: "case-a:reproduce", Prompt: "проверь доступность", EvidenceArtifactRef: "artifact-unresolved"}, {CaseID: "case-a:address-failure", Prompt: "проверь доступность; обработай неизвестный результат", EvidenceArtifactRef: "artifact-unresolved"}},
ParentGraphState: work.GraphCompleted, TriggerEvidenceRef: "artifact-unresolved",
Plan: work.TaskEvaluationGraphRequest{
GraphID: "graph-additional", BindingIDs: []capability.CapabilityBindingID{"binding-a"}, DispatchIDs: []string{"dispatch-additional"}, IdempotencyPrefix: "additional", Budget: work.GraphBudget{MaxParallel: 1, MaxAttempts: 2}, ParentGraphID: "graph-general", ParentGraphRevision: 2,
},
Intents: []work.AgentDispatchIntent{{DispatchID: "dispatch-additional", IdempotencyKey: "idem-additional", DelegationID: "delegation-a", RunID: "run-a", ImplementationID: "impl", ImplementationRevision: 1, SourceRevision: "source", WorktreeID: "tree", VerificationPlanRef: "verify", CreatedAtUnixMillis: 1}},
Now: 20,
}
graph, ready, err := ScheduleAdditionalTaskEvaluation(context.Background(), store, request)
if err != nil || len(ready) != 1 || graph.State != work.GraphRunning {
t.Fatalf("graph=%+v ready=%v err=%v", graph, ready, err)
}
if len(graph.Nodes) != 1 || graph.Nodes[0].TaskProfileID != "profile-additional" || len(graph.Nodes[0].CaseIDs) != 2 || graph.TriggerEvidenceRef != "artifact-unresolved" {
t.Fatalf("additional graph did not preserve bounded expansion lineage: %+v", graph)
}
if len(store.intents) != 1 || store.intents[0].TaskEvaluationProfileID != "profile-additional" {
t.Fatalf("additional dispatch context missing: %+v", store.intents)
}
}
func TestScheduleAdditionalTaskEvaluationRejectsIncompleteLineage(t *testing.T) {
store := &taskGraphStore{}
_, _, err := ScheduleAdditionalTaskEvaluation(context.Background(), store, TaskEvaluationExpansionScheduleRequest{Profile: capability.TaskEvaluationProfile{Stage: capability.TaskEvaluationGeneral}})
if err == nil || len(store.intents) != 0 {
t.Fatalf("incomplete expansion lineage was accepted: intents=%v err=%v", store.intents, err)
}
}