feat(work): add persistent solution search orchestration policy
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
"git.cin.su/m/Assistant/modules/work/domain"
|
||||
)
|
||||
|
||||
func DecideSolutionSearch(input work.SolutionSearchInput) (work.SolutionSearchDecision, error) {
|
||||
return domain.DecideSolutionSearch(input)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
)
|
||||
|
||||
var ErrInvalidSolutionSearch = errors.New("invalid solution search input")
|
||||
|
||||
// DecideSolutionSearch keeps an unresolved goal alive across bounded waves.
|
||||
// A wave has limits, but an unresolved goal is never converted into FAILED
|
||||
// merely because one wave is exhausted. The caller persists the decision and
|
||||
// schedules the next wave through the durable Work Graph.
|
||||
func DecideSolutionSearch(input work.SolutionSearchInput) (work.SolutionSearchDecision, error) {
|
||||
if input.GoalID == "" || input.SearchRound < 0 || input.MaxRound < 1 || input.ActiveOptionCount < 0 {
|
||||
return work.SolutionSearchDecision{}, ErrInvalidSolutionSearch
|
||||
}
|
||||
decision := work.SolutionSearchDecision{GoalID: input.GoalID, NextSearchRound: input.SearchRound}
|
||||
if input.CancelRequested || input.GoalState == work.GoalCancelled {
|
||||
decision.State = work.OrchestrationCancelled
|
||||
decision.Reason = "goal cancellation is durable and stops further search waves"
|
||||
return decision, nil
|
||||
}
|
||||
if input.GoalState == work.GoalCompleted && input.VerificationReady {
|
||||
decision.State = work.OrchestrationCompleted
|
||||
decision.Reason = "goal has an independently verified accepted result"
|
||||
return decision, nil
|
||||
}
|
||||
if input.ActiveOptionCount > 0 {
|
||||
decision.State = work.OrchestrationExecuting
|
||||
decision.ContinueSearching = true
|
||||
decision.Options = []work.SearchOptionKind{work.SearchOptionAgents}
|
||||
decision.Reason = "current solution wave is still running"
|
||||
return decision, nil
|
||||
}
|
||||
decision.State = work.OrchestrationSearching
|
||||
decision.ContinueSearching = true
|
||||
decision.NextSearchRound++
|
||||
decision.Options = []work.SearchOptionKind{work.SearchOptionAgents, work.SearchOptionCapability, work.SearchOptionResearch, work.SearchOptionReflection}
|
||||
if input.Unresolved {
|
||||
decision.Reason = "previous wave did not establish a verified solution; start all independent search avenues"
|
||||
} else {
|
||||
decision.Reason = "no verified result exists; start the first parallel solution wave"
|
||||
}
|
||||
if input.SearchRound >= input.MaxRound {
|
||||
decision.State = work.OrchestrationWaiting
|
||||
decision.Options = append(decision.Options, work.SearchOptionHuman)
|
||||
decision.Reason = "bounded wave budget exhausted; continue with a new durable wave and human attention, never claim failure"
|
||||
}
|
||||
return decision, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSolutionSearchDoesNotDeadEndAfterBudgetedWave(t *testing.T) {
|
||||
decision, err := DecideSolutionSearch(work.SolutionSearchInput{GoalID: "goal-1", GoalState: work.GoalInProgress, SearchRound: 3, MaxRound: 3, Unresolved: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !decision.ContinueSearching || decision.State != work.OrchestrationWaiting || decision.NextSearchRound != 4 {
|
||||
t.Fatalf("unexpected exhausted-wave decision: %#v", decision)
|
||||
}
|
||||
if len(decision.Options) != 5 || decision.Options[4] != work.SearchOptionHuman {
|
||||
t.Fatalf("all search avenues were not retained: %#v", decision.Options)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSolutionSearchStopsOnlyForCancelOrVerifiedCompletion(t *testing.T) {
|
||||
completed, err := DecideSolutionSearch(work.SolutionSearchInput{GoalID: "goal-1", GoalState: work.GoalCompleted, VerificationReady: true, MaxRound: 1})
|
||||
if err != nil || completed.ContinueSearching || completed.State != work.OrchestrationCompleted {
|
||||
t.Fatalf("verified completion was not terminal: %#v %v", completed, err)
|
||||
}
|
||||
cancelled, err := DecideSolutionSearch(work.SolutionSearchInput{GoalID: "goal-1", GoalState: work.GoalInProgress, CancelRequested: true, MaxRound: 1})
|
||||
if err != nil || cancelled.ContinueSearching || cancelled.State != work.OrchestrationCancelled {
|
||||
t.Fatalf("cancel was not terminal: %#v %v", cancelled, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user