mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-27 10:20:54 +08:00
fix(goals): fall back to raw goal only when no LLM provider is configured (#585)
This commit is contained in:
+6
-1
@@ -83,6 +83,11 @@ var ErrGoalDecompositionContract = errors.New("goal decomposition did not produc
|
||||
// with an empty task goal.
|
||||
var ErrGoalDecompositionEmptyInput = errors.New("goal decomposition requires a non-empty task goal")
|
||||
|
||||
// ErrGoalDecompositionNoProvider reports that goal decomposition cannot run
|
||||
// because no LLM provider is configured. Callers distinguish this from a
|
||||
// structured tool-call contract failure (ErrGoalDecompositionContract).
|
||||
var ErrGoalDecompositionNoProvider = errors.New("goal decomposition failed: no LLM provider configured")
|
||||
|
||||
// goalsStrictRetryPrompt is sent once when the initial goal decomposition run
|
||||
// finishes without persisting any non-empty goal via a structured set_goals
|
||||
// tool call (e.g. the model emitted set_goals in plain text instead).
|
||||
@@ -122,7 +127,7 @@ func DecomposeGoals(ctx context.Context, prov llm.Provider, dataDir, goalText, d
|
||||
// per-reply output cap (0 = send none).
|
||||
func DecomposeGoalsWithProvider(ctx context.Context, prov llm.Provider, dataDir, goalText, desc string, as *db.AssetStore, ts *db.ExplorationStore, taskID int64, nonStreaming bool, maxTokens int, emit func(db.Activity)) ([]GoalSpec, error) {
|
||||
if prov == nil {
|
||||
return nil, errors.New("goal decomposition failed: no LLM provider configured")
|
||||
return nil, ErrGoalDecompositionNoProvider
|
||||
}
|
||||
if ts == nil {
|
||||
return nil, errors.New("goal decomposition failed: exploration store is not initialized")
|
||||
|
||||
@@ -264,3 +264,16 @@ func TestPlannerRefusesEmptyContextAndOverviewOmitsEmptyFields(t *testing.T) {
|
||||
t.Fatalf("expected 1 LLM call when context is valid, got %d", prov.calls())
|
||||
}
|
||||
}
|
||||
func TestDecomposeGoalsNoProviderReturnsSentinel(t *testing.T) {
|
||||
ts := guardTaskStore(t)
|
||||
got, err := DecomposeGoals(t.Context(), nil, t.TempDir(), "Audit target", "desc", nil, ts, 0, nil)
|
||||
if !errors.Is(err, ErrGoalDecompositionNoProvider) {
|
||||
t.Fatalf("expected ErrGoalDecompositionNoProvider, got goals=%+v err=%v", got, err)
|
||||
}
|
||||
if errors.Is(err, ErrGoalDecompositionContract) {
|
||||
t.Fatalf("no-provider error must not match ErrGoalDecompositionContract: %v", err)
|
||||
}
|
||||
if len(got) != 0 {
|
||||
t.Fatalf("expected no goals returned, got %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
@@ -406,6 +407,23 @@ func (s *Server) createGoals(ctx context.Context, t *Task, emit func(db.Activity
|
||||
decomposed, err := agent.DecomposeGoalsWithProvider(ctx, goalRuntime, s.m.dir, t.Goal, t.Description, as, t.Store, taskID, goalRuntime.nonStreaming(), goalRuntime.maxTokens(), emit)
|
||||
s.engine.EndLLMCall(t.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, agent.ErrGoalDecompositionNoProvider) {
|
||||
// No LLM provider is configured yet: preserve the pre-existing fallback
|
||||
// so the task gets a single raw goal node linked to its origin fact and
|
||||
// stays alive until an LLM is configured. Structured contract failures
|
||||
// from an actual model remain strict and fail the task.
|
||||
g := strings.TrimSpace(t.Goal)
|
||||
log.Printf("[goals] task %s: no LLM provider configured, seeding raw goal as a single goal", t.ID)
|
||||
origin, _ := t.Store.OriginFactID()
|
||||
id, addErr := t.Store.AddNode(db.KindGoal, map[string]any{"text": g}, 0, "open", "system", nil)
|
||||
if addErr != nil {
|
||||
return nil, fmt.Errorf("seed raw goal: %w", addErr)
|
||||
}
|
||||
if origin > 0 && id > 0 {
|
||||
_ = t.Store.Link(origin, db.RelSpawns, id) // goal descends from the task root (origin fact)
|
||||
}
|
||||
return []goalSpec{{Text: g}}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var specs []goalSpec
|
||||
|
||||
@@ -130,3 +130,78 @@ func TestStartTaskEngineFailsTaskOnPlainTextDecomposer(t *testing.T) {
|
||||
t.Fatalf("expected error activity describing goal decomposition failure, got %+v", acts)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreateGoalsNoProviderSeedsRawGoalAndKeepsTaskAlive verifies that when no
|
||||
// LLM provider is configured, createGoals falls back to seeding the raw task
|
||||
// goal as a single goal node linked from the origin fact, keeping the task
|
||||
// alive instead of marking it failed.
|
||||
func TestCreateGoalsNoProviderSeedsRawGoalAndKeepsTaskAlive(t *testing.T) {
|
||||
skipWithoutDSN(t)
|
||||
m, err := NewManager(t.TempDir(), "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = m.Close() })
|
||||
if m.pg == nil {
|
||||
db.SkipNoPG(t)
|
||||
}
|
||||
// Ensure no global LLM profile is configured in this test DB.
|
||||
profiles, err := m.pg.ListProfiles()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(profiles) > 0 {
|
||||
t.Skip("test database already has configured LLM profiles")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
s := New(ctx, m, "", m.dir, m.dir)
|
||||
t.Cleanup(func() { stopTestServer(t, s, cancel) })
|
||||
|
||||
const rawGoal = "Probe http://127.0.0.1:9/v1 for unauthenticated exposure"
|
||||
task, err := m.CreateTaskWithOptions("no-provider fallback", rawGoal, db.TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _, _ = m.DeleteTask(task.ID, DeleteTaskOptions{}) })
|
||||
|
||||
// Seed origin fact as launchTask does so the spawns link is exercised.
|
||||
s.seed(task, rawGoal)
|
||||
originID, err := task.Store.OriginFactID()
|
||||
if err != nil || originID <= 0 {
|
||||
t.Fatalf("expected origin fact seeded, got id=%d err=%v", originID, err)
|
||||
}
|
||||
|
||||
goals, err := s.createGoals(ctx, task, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("createGoals without provider must fall back cleanly, got err=%v", err)
|
||||
}
|
||||
if len(goals) != 1 || goals[0].Text != rawGoal {
|
||||
t.Fatalf("unexpected fallback goals: %+v", goals)
|
||||
}
|
||||
|
||||
nodes, err := task.Store.ListByKind(db.KindGoal, 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(nodes) != 1 {
|
||||
t.Fatalf("expected 1 persisted goal node, got %d", len(nodes))
|
||||
}
|
||||
edges, err := task.Store.Edges(100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
linked := false
|
||||
for _, e := range edges {
|
||||
if e.From == originID && e.Rel == db.RelSpawns && e.To == nodes[0].ID {
|
||||
linked = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !linked {
|
||||
t.Fatalf("fallback goal node #%d not linked from origin fact #%d via %q (edges=%+v)", nodes[0].ID, originID, db.RelSpawns, edges)
|
||||
}
|
||||
if st := task.lifecycleSnapshot().Status; st == "failed" {
|
||||
t.Fatalf("task without provider must stay alive, got status=%q", st)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -248,7 +248,7 @@ func (r *taskLLMRuntime) currentFor(ctx context.Context) (taskLLMSelection, erro
|
||||
}
|
||||
prov, cfg, id, ok := r.s.globalProviderWithProfile()
|
||||
if !ok {
|
||||
return sel, fmt.Errorf("task %s has no available fallback LLM provider", r.taskID)
|
||||
return sel, fmt.Errorf("task %s has no available fallback LLM provider: %w", r.taskID, agent.ErrGoalDecompositionNoProvider)
|
||||
}
|
||||
sel.provider, sel.retry = prov, cfg.Retry
|
||||
sel.healthProfileID = healthIDFor(prov, id)
|
||||
|
||||
Reference in New Issue
Block a user