fix(workflow): make the repository optional for the triage workflow (#1578)

This commit is contained in:
sam committed 2026-10-31 00:36:10 +11:00
1 parent 3b6de96782
commit 3977eaad68
5 files changed
+167 -7

No files matched your search

+7
View File
@@ -2090,6 +2090,13 @@ func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (confi
// dashboard spawns go through the Gateway, which never does).
err = iface.CheckInputs(task.Inputs)
}
if err == nil && iface.RepositoryMode() == workflowtask.RepositoryRequired && !task.HasRepository() {
// An optional workflow may hand off to one that requires a
// repository, because its task may carry one; a task that does not
// is parked here rather than run the target's steps in a scratch
// workspace.
err = fmt.Errorf("requires a repository and this task has none")
}
if err == nil {
var profile config.AgentProfile
if profile, err = d.configFor(task).Containers.Profile(iface.Profile); err == nil {
+7 -3
View File
@@ -252,14 +252,18 @@ func controlTarget(step StepRecord) (string, bool, error) {
}
// checkControlTarget refuses a target workflow the task cannot follow: one
// that is not defined, one that needs a repository the task does not have, or
// one whose declared inputs the task's own inputs cannot satisfy.
// that is not defined, one that needs a repository the source can never
// provide, or one whose declared inputs the task's own inputs cannot satisfy.
// An optional source may hand off to a repository-requiring target because
// its task may carry a repository; a repository-less task that does is parked
// at dispatch (daemon pinTaskProfile) instead of running the target's steps
// in a scratch workspace.
func checkControlTarget(where string, source task.WorkflowInterface, parsed map[string]YAMLDefinition, target string) error {
wf, ok := parsed[target]
if !ok {
return fmt.Errorf("%s targets %q, which is not defined", where, target)
}
if wf.RepositoryMode() == task.RepositoryRequired && source.RepositoryMode() != task.RepositoryRequired {
if wf.RepositoryMode() == task.RepositoryRequired && source.RepositoryMode() == task.RepositoryNone {
return fmt.Errorf("%s targets %q, which needs a repository the task does not have", where, target)
}
for _, name := range slices.Sorted(maps.Keys(source.Inputs)) {
@@ -92,6 +92,21 @@ steps:
},
wantErr: `which needs a repository the task does not have`,
},
{
name: "an optional source may hand off to a target that requires a repository",
defs: map[string]string{
"source": `id: source
repository: optional
steps:
- type: workflow.handoff
settings: {workflow: defined}
`,
"defined": `id: defined
steps:
- type: workflow.finish
`,
},
},
{
name: "a target requiring an input the task may not carry is refused",
defs: map[string]string{
+4 -4
View File
@@ -1,19 +1,19 @@
id: triage
repository: optional
identity: 6f129e29-0e26-5246-99bd-74cb4496203b
steps:
- type: repo.prepare
- id: classify
type: agent.run
settings:
read_only: true
mission: |
Triage this {{ task.kind }} on the repository {{ task.repository }}: decide whether it needs a code change at all, and if so which workflow suits it best.
Triage this {{ task.kind }}: decide whether it needs a code change at all, and if so which workflow suits it best.
{{ task.prompt }}
Read only as much as you need to judge this. A title or body that is purely conversational, administrative, or already resolved needs no code change.
Read only as much as you need to judge this. If the task names no repository, there is no code to read: judge from the request alone. A title or body that is purely conversational, administrative, or already resolved needs no code change.
If it does need a change, the workflow is a real decision, not a formality. Check whether the repository already has a settled design for what is being asked (a design document, an approved plan, an existing implementation to extend). If it does not, and the request is not a defect, choose feasibility: it writes a design document for an operator to approve, which is cheaper than an implementation built on a guess. Choose tdd when there is an observable wrong behaviour a test can reproduce first. Choose implement only when the change is well understood and its shape is already clear.
If it does need a change, the workflow is a real decision, not a formality. If there is a repository, check whether it already has a settled design for what is being asked (a design document, an approved plan, an existing implementation to extend). If it does not, and the request is not a defect, choose feasibility: it writes a design document for an operator to approve, which is cheaper than an implementation built on a guess. Choose tdd when there is an observable wrong behaviour a test can reproduce first. Choose implement only when the change is well understood and its shape is already clear.
Return your result exactly once, then call finish with status "passed".
result:
@@ -0,0 +1,134 @@
package workflow
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"slices"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
)
// shippedTriageYAML returns the shipped triage definition's YAML.
func shippedTriageYAML(t *testing.T) string {
t.Helper()
for _, entry := range ShippedDefinitions().Definitions {
if entry.ID == "triage" {
return entry.YAML
}
}
t.Fatal("the triage definition is not shipped")
return ""
}
// The shipped collection must stay valid with triage declaring its repository
// optional: the control plane seeds and saves workflow definitions through
// ValidateDefinitionCollection, so an invalid shipped set would fail every
// operator save and the seed for orgs without a stored document.
func TestShippedCollectionValidatesWithOptionalTriage(t *testing.T) {
t.Parallel()
if err := ValidateDefinitionCollection(ShippedDefinitions(), triageRegistry()); err != nil {
t.Fatalf("shipped collection: %v", err)
}
definition, err := ParseDefinition(shippedTriageYAML(t), triageRegistry())
if err != nil {
t.Fatalf("parse the triage definition: %v", err)
}
if got := definition.RepositoryMode(); got != task.RepositoryOptional {
t.Fatalf("triage repository mode = %q, want %q", got, task.RepositoryOptional)
}
// An optional workflow may carry only repo-free step types, since it can
// run with no worktree at all.
if err := walkSteps(definition.Steps, `workflow "triage"`, func(where string, step StepRecord) error {
if NeedsRepository(step.Type) {
return fmt.Errorf("%s step %q needs a repository", where, step.StageName())
}
return nil
}); err != nil {
t.Fatalf("triage steps: %v", err)
}
}
// fakePromptRunner answers one agent.run with a fixed captured result and
// records the workspace and mission it was given.
type fakePromptRunner struct {
res agentrun.Result
workspace string
mission string
}
func (f *fakePromptRunner) Run(_ context.Context, workspace string, req agentrun.Request, _ agentrun.ToolCallReporter) (agentrun.Result, error) {
f.workspace = workspace
f.mission = req.Mission
return f.res, nil
}
// A prompt-only Run starts a task directly: an unlabeled repository-less task
// routes to triage, compiles, and runs to completion in a scratch workspace,
// with no repository involved.
func TestRepoLessTaskRunsTriageFromAPrompt(t *testing.T) {
t.Parallel()
available := map[string]struct{}{}
for _, entry := range ShippedDefinitions().Definitions {
available[entry.ID] = struct{}{}
}
promptTask := &task.Task{ID: 7, Attempt: 1, Source: SourceChat, Title: "what does this do?", Body: "Explain the auth flow."}
if promptTask.HasRepository() {
t.Fatal("the prompt-only task must have no repository")
}
id, err := ResolveWorkflowID(promptTask, available)
if err != nil {
t.Fatalf("route: %v", err)
}
if id != "triage" {
t.Fatalf("routed to %q, want triage", id)
}
wf, err := ParseAndCompile(shippedTriageYAML(t), triageRegistry())
if err != nil {
t.Fatalf("compile triage: %v", err)
}
if got := wf.Interface.RepositoryMode(); got != task.RepositoryOptional {
t.Fatalf("compiled triage repository mode = %q, want %q", got, task.RepositoryOptional)
}
runner := &fakePromptRunner{res: agentrun.Result{
Version: agentrun.ProtocolVersion, TaskID: 7, Attempt: 1, Stage: AgentRunStepName,
Status: agentrun.StatusPassed, Summary: "triaged",
Captures: map[string][]json.RawMessage{resultToolName: {json.RawMessage(`{"needs_code_change": false, "reasons": "conversational"}`)}},
}}
store := &fakeStepStore{}
scratch := t.TempDir()
tc := &TaskContext{
Task: promptTask, Store: store, Log: slog.Default(), Agent: runner,
Cfg: config.Config{Models: map[string]string{"default": "test/model"}},
Dir: scratch,
}
Run(context.Background(), wf, tc)
if tc.Outcome.Status != StatusCompleted {
t.Fatalf("outcome status = %q, want %q (detail %q)", tc.Outcome.Status, StatusCompleted, tc.Outcome.Detail)
}
if runner.workspace != scratch {
t.Errorf("agent ran in workspace %q, want the scratch workspace %q", runner.workspace, scratch)
}
if !strings.Contains(runner.mission, "Explain the auth flow.") {
t.Errorf("mission %q lacks the prompt", runner.mission)
}
var names []string
for _, s := range store.started {
names = append(names, s.Name)
}
if !slices.Contains(names, "classify") {
t.Errorf("steps started = %v, want a classify step", names)
}
}