fix(workflow): derive a declared output's captures need for profile selection

A declared output is written through a capture tool, but the dispatch-time
harness check read only the workflow's needs.captures. A workflow that
declared outputs without also writing needs: {captures: true} could name a
Kit profile whose adapter serves no capture tools; a required output then
parked with "output %q is required" instead of the profile being refused.

WorkflowInterface.Needs now reports captures for a non-empty Outputs beside
the declared needs, and the profile check and Kit launcher read it. The
needs: block keeps its meaning for a workflow that captures without
declaring outputs.

- internal/domain/workflow/task: Needs() derives captures; DeclaredNeeds
  carries only the declared block.
- internal/daemon: pinTaskProfile and runKitTask read Needs().
- tests: parse-time derivation, and pinTaskProfile refusing an
  outputs-declaring workflow against a Kit adapter with no capture MCP.
This commit is contained in:
sam committed 2026-10-02 03:19:07 +10:00
1 parent 446d94681b
commit 721968eeff
8 files changed
+59 -21

No files matched your search

+1 -1
View File
@@ -1921,7 +1921,7 @@ func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (confi
if err == nil {
var profile config.AgentProfile
if profile, err = d.configFor(task).Containers.Profile(iface.Profile); err == nil {
if err = validateProfileMeetsNeeds(profile, iface.Needs); err == nil {
if err = validateProfileMeetsNeeds(profile, iface.Needs()); err == nil {
return profile, true
}
}
+13 -5
View File
@@ -2373,6 +2373,11 @@ func TestPinTaskProfileRefusesCapturesTheHarnessCannotServe(t *testing.T) {
{ID: "needs-captures-served", YAML: "id: needs-captures-served\nrepository: none\nprofile: serves-captures\nneeds: {captures: true}\nsteps:\n - type: agent.run\n settings: {mission: go}\n"},
{ID: "needs-captures-codex", YAML: "id: needs-captures-codex\nrepository: none\nprofile: no-captures\nneeds: {captures: true}\nsteps:\n - type: agent.run\n settings: {mission: go}\n"},
{ID: "needs-captures-bare", YAML: "id: needs-captures-bare\nrepository: none\nprofile: no-adapter\nneeds: {captures: true}\nsteps:\n - type: agent.run\n settings: {mission: go}\n"},
// A declared output is written through a capture tool, so it forces
// the captures need whether or not the author also wrote
// needs.captures (docs/prds/workflow-call-outputs.md).
{ID: "outputs-served", YAML: "id: outputs-served\nrepository: none\nprofile: serves-captures\noutputs: { summary: {type: string} }\nsteps:\n - type: agent.run\n settings: {mission: go}\n"},
{ID: "outputs-codex", YAML: "id: outputs-codex\nrepository: none\nprofile: no-captures\noutputs: { summary: {type: string, required: true} }\nsteps:\n - type: agent.run\n settings: {mission: go}\n"},
}}, version: 1}
ctx := context.Background()
@@ -2389,17 +2394,20 @@ func TestPinTaskProfileRefusesCapturesTheHarnessCannotServe(t *testing.T) {
return task
}
served := claim(51, "needs-captures-served")
if _, ok := d.pinTaskProfile(ctx, served); !ok {
t.Fatal("a Kit profile whose adapter serves captures was refused")
for i, servedWorkflow := range []string{"needs-captures-served", "outputs-served"} {
served := claim(51+i, servedWorkflow)
if _, ok := d.pinTaskProfile(ctx, served); !ok {
t.Fatalf("a Kit profile whose adapter serves captures was refused for %s", servedWorkflow)
}
}
for _, tt := range []struct {
number int
workflow string
}{
{52, "needs-captures-codex"},
{53, "needs-captures-bare"},
{53, "needs-captures-codex"},
{54, "needs-captures-bare"},
{55, "outputs-codex"},
} {
task := claim(tt.number, tt.workflow)
if _, ok := d.pinTaskProfile(ctx, task); ok {
+1 -1
View File
@@ -72,7 +72,7 @@ func (d *Daemon) runKitTask(ctx context.Context, task *workflow.Task, repo confi
Adapter: profile.Adapter,
WorkDir: workDir,
WorkerEnv: env,
GateRetries: iface.Needs.GateRetries,
GateRetries: iface.Needs().GateRetries,
Org: taskCfg.Org,
GrantedServices: taskCfg.GrantedCredentials,
})
+19 -10
View File
@@ -56,15 +56,24 @@ type WorkflowInterface struct {
// Profile names a [containers.profiles] entry. It is resolved when a task
// is dispatched, not when the workflow is saved.
Profile string `yaml:"profile,omitempty" json:"profile,omitempty"`
// Needs declares what this workflow's agent stages require of the
// profile they run under -- checked against the profile's actual
// capabilities before dispatch (docs/prds/external-agent-harness.md,
// "Contract"): a stage that returns structured output needs a harness
// with a capture-tools-capable output adapter, and a gated stage that
// may retry needs the Kit's agent-sessions resume verb. Only a Kit
// profile is checked against it -- an image profile's built-in agent
// loop always supports both.
Needs WorkflowNeeds `yaml:"needs" json:"needs"`
// 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 reports the harness requirements the interface carries: the declared
// needs, plus the captures a declared output forces, because an output is
// written through a capture tool (docs/prds/workflow-call-outputs.md, "How a
// run writes one"). Profile selection reads this rather than DeclaredNeeds,
// so a workflow that declares outputs cannot name a Kit profile whose harness
// serves no capture tools (docs/prds/external-agent-harness.md, "Contract").
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.
@@ -116,7 +125,7 @@ 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.Needs.GateRetries < 0 {
if w.DeclaredNeeds.GateRetries < 0 {
return fmt.Errorf("workflow needs.gate_retries must not be negative")
}
return nil
@@ -47,8 +47,22 @@ func TestParseWorkflowInterfaceNeeds(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !w.Needs.Captures || w.Needs.GateRetries != 3 {
t.Fatalf("Needs = %+v, want {Captures:true GateRetries:3}", w.Needs)
if needs := w.Needs(); !needs.Captures || needs.GateRetries != 3 {
t.Fatalf("Needs() = %+v, want {Captures:true GateRetries:3}", needs)
}
}
// TestParseWorkflowInterfaceOutputsForceCaptures: an output is written
// through a capture tool, so declaring one forces the captures need whether
// or not the author also wrote needs.captures
// (docs/prds/workflow-call-outputs.md, "How a run writes one").
func TestParseWorkflowInterfaceOutputsForceCaptures(t *testing.T) {
w, err := ParseWorkflowInterface("id: a\noutputs:\n summary: {type: string}\n")
if err != nil {
t.Fatal(err)
}
if needs := w.Needs(); !needs.Captures {
t.Fatalf("Needs() = %+v, want Captures for a workflow that declares an output", needs)
}
}