Files
archie/internal/domain/workflow/task/step.go
T
sam 0b8014516a feat(workflow): agent-call children, call steps, and the waited-on callee sweep
Plan item 4 of docs/prds/execution-tree-state-machine.md (archie-core-1216),
plus the callee half of CancelExecution that plan item 5 deferred until the
tree could decide it.

Every agent call a stage makes records itself: AgentStage's bridge, the
baseline-fix auto-fix run, the adversarial reviewer and a workflow.call each
start a child StepExecution of kind agent or call under the stage's own step
-- TaskContext.StepID, which the engine sets before the stage body starts and
clears when it returns -- and finish it with the call's own outcome and the
tokens it accounted. A child's recording write failure parks the execution
the same way a stage's does: an agent call that ran unrecorded is the
invisibility the step table exists to end. A stage invoked outside the
engine's recorded run -- the stage unit tests -- records no child and runs
unchanged.

The call step is what makes the callee half of the PRD's Cancellation section
decidable, and this lands it: a call step closes when its callee ends, so an
open call step is a callee the caller waits on (wait:true) and a closed one
is a wait:false callee that runs on. CancelExecution reads the open call
steps before its sweep closes them and cancels each named callee through its
own CancelExecution in the caller's write's aftermath -- the callee's own
steps, its own events, its own move to the same destination, and the callee's
own wait:true callees beyond it, the depth the enqueue enforces bounding the
recursion. A callee that cannot be cancelled is reported and the caller's own
record stands.

StartStep refuses a call step whose callee is not this run's own (the
callee's call_parent_task_id must name the recording execution): a
compromised container could otherwise record a step naming a foreign
execution and cancel it. StartStepRequest gains called_execution_id (field 6;
non-breaking, the column and its named consumer already exist) and
StepStart carries it.

PRD decisions recorded here:
- The reviewer records as one agent child named "review": the Reviewer
  contract runs one subagent per review, the PRD model's review:1/review:2
  are illustrative of depth-1 children. A completed report closes it
  succeeded, a not-run review failed with the skip reason; the contract
  carries no usage, so tokens are 0.
- A failed-callee call step closes as failed with the callee's detail when
  the wait ends otherwise; the single open case is the caller itself being
  cancelled, whose CancelExecution already swept this step -- a late write
  must not pretend the wait is still the caller's business.
- A call step's callee is cancelled to the same destination the caller's
  action named (parked stays parked, closed_wont_do ends the whole chain),
  and a callee that cannot be cancelled is reported while the caller's own
  record stands either way.
- The agent child's detail is the result summary on success and the error's
  text on failure, with the call's own TokensUsed -- the PRD's only usage
  field, untracked per call for the reviewer contract.
2026-09-27 07:14:15 +10:00

66 lines
2.4 KiB
Go

package task
import "github.com/samcharles93/archie-core/internal/taskstate"
// The step-execution vocabulary of docs/prds/execution-tree-state-machine.md:
// one stage run, or one agent or workflow.call step an execution's tree
// records, started and finished through the State Store under the run's own
// credential.
// Step kinds. `stage` is what workflow.Run records for every stage it runs;
// `agent` is what the agent runtime records for one agent call; `call` is the
// workflow.call step in a caller's tree, which names its callee's execution.
// A new kind needs a named consumer before it is added.
const (
StepKindStage = "stage"
StepKindAgent = "agent"
StepKindCall = "call"
)
// ValidStepKind reports whether kind is one the store records.
func ValidStepKind(kind string) bool {
switch kind {
case StepKindStage, StepKindAgent, StepKindCall:
return true
default:
return false
}
}
// StepStart names the step a caller is starting. ExecutionID is the
// WorkflowExecution (the tasks row); Attempt is the run of it the step
// belongs to; ParentID is 0 for a stage and names the enclosing StepExecution
// otherwise, from which the store derives depth.
type StepStart struct {
ExecutionID int64
Attempt int
// ParentID is 0 when the step is a stage at the tree's root.
ParentID int64
Kind string
Name string
// CalledExecutionID names the WorkflowExecution a `call` step started.
// The store refuses a value that is not the caller's own callee (the
// callee's call_parent_task_id must name this execution), so a step's
// tree cannot cross runs: a cancel of that execution would otherwise
// cancel work the caller never started. Non-call kinds leave it 0.
CalledExecutionID int64
}
// StepFinish moves one step from From to its outcome. ExecutionID names the
// run the step belongs to: the task-scoped grant check verifies it, and the
// store verifies the step really is that execution's, so a caller cannot move
// another run's step by naming it.
type StepFinish struct {
StepID int64
ExecutionID int64
// From and To are the step transition table's statuses (taskstate).
From taskstate.StepStatus
To taskstate.StepStatus
// Detail is the step's outcome line: an error's text for a failed step, a
// summary otherwise. Clipped store-side like every detail.
Detail string
// TokensUsed is the usage the step itself accounted. Stages record none;
// the agent runtime records its own calls' usage.
TokensUsed int64
}