From 606da1aee5dabdd2b34f6dfbf44681d2c92f0f37 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 13 Nov 2026 02:11:22 +1100 Subject: [PATCH] chore(workflow): remove the needs block (#1888) --- WORKFLOWS.md | 1 - internal/domain/workflow/definition.go | 37 +++++++++- .../domain/workflow/definition_load_test.go | 70 +++++++++++++++++++ internal/domain/workflow/task/interface.go | 26 ------- ui/src/workflows/WorkflowSettings.vue | 25 ------- 5 files changed, 106 insertions(+), 53 deletions(-) create mode 100644 internal/domain/workflow/definition_load_test.go diff --git a/WORKFLOWS.md b/WORKFLOWS.md index 66058557f..4649ef94c 100644 --- a/WORKFLOWS.md +++ b/WORKFLOWS.md @@ -46,7 +46,6 @@ steps: | `outputs` | mapping | Named, typed results the run writes once each (same shape as inputs). A required output the run never writes parks it. A calling workflow reads them. | | `profile` | text | The container profile (`[containers.profiles]`) the run's agents use. Resolved when the task is dispatched. | | `identity` | text | The identity every run acts as, whatever started it. Empty runs as the starter. | -| `needs` | mapping | Harness capabilities the run requires: `captures` (bool), `gate_retries` (number). Declared outputs imply `captures`. | ## A step diff --git a/internal/domain/workflow/definition.go b/internal/domain/workflow/definition.go index 60655b6ca..4fa1787b2 100644 --- a/internal/domain/workflow/definition.go +++ b/internal/domain/workflow/definition.go @@ -86,10 +86,45 @@ type StepFactory func(yaml.Node) (Stage, error) // StepRegistry is the closed set of safe workflow operations available to YAML. type StepRegistry map[string]StepFactory +// dropNeeds removes a needs: block a definition written before the field went +// away may still carry. The key is deleted from the document's root mapping, +// so the caller's strict decode sees no trace of it while every other key, +// including those inside steps, keeps its original wording. +func dropNeeds(src string) ([]byte, error) { + decoder := yaml.NewDecoder(strings.NewReader(src)) + var document yaml.Node + if err := decoder.Decode(&document); err != nil { + return nil, fmt.Errorf("parse workflow YAML: %w", err) + } + if document.Kind == yaml.DocumentNode && len(document.Content) > 0 { + if root := document.Content[0]; root.Kind == yaml.MappingNode { + for i := 0; i+1 < len(root.Content); i += 2 { + if root.Content[i].Value == "needs" { + root.Content = slices.Delete(root.Content, i, i+2) + break + } + } + } + } + var encoded bytes.Buffer + encoder := yaml.NewEncoder(&encoded) + if err := encoder.Encode(&document); err != nil { + return nil, err + } + if err := encoder.Close(); err != nil { + return nil, err + } + return encoded.Bytes(), nil +} + // ParseDefinition strictly parses and validates one YAML workflow. func ParseDefinition(src string, registry StepRegistry) (YAMLDefinition, error) { + document, err := dropNeeds(src) + if err != nil { + return YAMLDefinition{}, err + } var definition YAMLDefinition - decoder := yaml.NewDecoder(strings.NewReader(src)) + decoder := yaml.NewDecoder(bytes.NewReader(document)) decoder.KnownFields(true) if err := decoder.Decode(&definition); err != nil { return YAMLDefinition{}, fmt.Errorf("parse workflow YAML: %w", err) diff --git a/internal/domain/workflow/definition_load_test.go b/internal/domain/workflow/definition_load_test.go new file mode 100644 index 000000000..df36c9ce5 --- /dev/null +++ b/internal/domain/workflow/definition_load_test.go @@ -0,0 +1,70 @@ +package workflow + +import ( + "encoding/json" + "testing" +) + +// Definitions written before the needs block went away still carry a needs +// entry in their YAML. The load path drops it, so a definition that parsed +// when it was saved still loads now, while strictness for everything else is +// unchanged. +func TestParseDefinitionDropsStoredNeeds(t *testing.T) { + t.Parallel() + + var shipped string + for _, entry := range ShippedDefinitions().Definitions { + if entry.ID == "triage" { + shipped = entry.YAML + } + } + if shipped == "" { + t.Fatal("the triage definition is not shipped") + } + + tests := []struct { + name string + yaml string + wantErr bool + }{ + { + name: "a stored definition carrying needs still loads", + yaml: shipped + "needs:\n captures: true\n gate_retries: 3\n", + }, + { + // The strip must drop exactly the needs key, not sed the parser + // into a lenient one: anything else unknown is still refused. + name: "a stored definition with another unknown key is still refused", + yaml: shipped + "bogus: 1\n", + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + // Ship the whole collection: a call target only validates + // against the workflows beside it. + entries := []WorkflowDefinitionEntry{} + for _, entry := range ShippedDefinitions().Definitions { + if entry.ID == "triage" { + entry.YAML = tt.yaml + } + entries = append(entries, entry) + } + value, err := json.Marshal(WorkflowDefinitionCollection{Definitions: entries}) + if err != nil { + t.Fatal(err) + } + collection, err := DecodeDefinitionCollection(value, triageRegistry()) + if (err != nil) != tt.wantErr { + t.Fatalf("DecodeDefinitionCollection() err = %v, wantErr %v", err, tt.wantErr) + } + if tt.wantErr { + return + } + if len(collection.Definitions) != len(entries) { + t.Fatalf("kept %d definitions, want %d", len(collection.Definitions), len(entries)) + } + }) + } +} diff --git a/internal/domain/workflow/task/interface.go b/internal/domain/workflow/task/interface.go index 31720c6ce..8ddd1198b 100644 --- a/internal/domain/workflow/task/interface.go +++ b/internal/domain/workflow/task/interface.go @@ -63,29 +63,6 @@ type WorkflowInterface struct { // Instructions are the workflow's layer of the instructions every agent // stage of a run follows. Instructions string `yaml:"instructions,omitempty" json:"instructions,omitempty"` - // DeclaredNeeds is what the definition's needs: block declares. Read - // Needs, not this, when deciding a harness requirement: a declared output - // forces the captures capability and Needs resolves it. - DeclaredNeeds WorkflowNeeds `yaml:"needs" json:"needs"` -} - -// Needs returns the declared needs plus captures when outputs are declared. -func (w WorkflowInterface) Needs() WorkflowNeeds { - needs := w.DeclaredNeeds - if len(w.Outputs) > 0 { - needs.Captures = true - } - return needs -} - -// WorkflowNeeds is WorkflowInterface's declared harness requirements. -type WorkflowNeeds struct { - // Captures declares that a stage returns structured output through - // capture tools. - Captures bool `yaml:"captures,omitempty" json:"captures,omitempty"` - // GateRetries is the largest gate-retry budget any stage declares. Zero - // means no stage gates its result, so no resume capability is needed. - GateRetries int `yaml:"gate_retries,omitempty" json:"gate_retries,omitempty"` } var ( @@ -127,9 +104,6 @@ func (w WorkflowInterface) Validate() error { return fmt.Errorf("workflow output %q type %q must be one of %s", name, spec.Type, strings.Join(inputTypes, ", ")) } } - if w.DeclaredNeeds.GateRetries < 0 { - return fmt.Errorf("workflow needs.gate_retries must not be negative") - } return nil } diff --git a/ui/src/workflows/WorkflowSettings.vue b/ui/src/workflows/WorkflowSettings.vue index 03b5cd5c1..d790f85f8 100644 --- a/ui/src/workflows/WorkflowSettings.vue +++ b/ui/src/workflows/WorkflowSettings.vue @@ -2,12 +2,10 @@ import { Alert, AlertDescription } from "@/components/ui/alert"; import { Label } from "@/components/ui/label"; import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; -import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { computed, ref, onMounted } from "vue"; import { Button } from "@/components/ui/button"; -import { Switch } from "@/components/ui/switch"; import { api } from "@/lib/api"; import type { Identity } from "@/stores/org"; import { useOrgStore } from "@/stores/org"; @@ -66,14 +64,6 @@ const MODES = [ { value: "none", label: "None", hint: "Scratch workspace, no clone" }, ]; const repository = computed(() => text("repository") || "required"); - -// needs is the workflow's declared harness requirements: captures (a stage -// returns structured output through capture tools) and the largest gate-retry -// budget any stage declares. -const needs = computed<{ captures?: boolean; gate_retries?: number }>(() => { - const value = workflowField(props.yaml, "needs"); - return value && typeof value === "object" ? (value as { captures?: boolean; gate_retries?: number }) : {}; -});