feat(work): add persistent solution search orchestration policy
CI / test (push) Successful in 1m9s
CI / test (pull_request) Successful in 58s

This commit is contained in:
m
2026-08-23 16:45:58 +03:00
parent 45874f2186
commit 23e0525c08
8 changed files with 173 additions and 4 deletions
+10
View File
@@ -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)
}
+51
View File
@@ -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
}
+30
View File
@@ -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)
}
}