Workflow DAG (issue #39)
A small dependency-aware task layer for multi-step agent work. It decides when a caller-supplied task may start. Nothing else.
Existing machinery
Inspected before writing any code.
| Area | What exists |
|---|---|
src/orchestration/run.rs | One Run with RunState {Running, WaitingForApproval, WaitingForTool, Completed, Failed, Cancelled}, step and action counters, a Trigger. A run is a single linear lifecycle. |
src/orchestration/budget.rs | RunBudget counters (steps, inference calls, actions, wall seconds) for one run. |
src/orchestration/termination.rs, trigger.rs | Why a run ended; what started it. |
src/agent.rs | AgentEngine::execute_task: a sequential model/tool loop. Since #38 it classifies tool failures (FailureRecord), retries only idempotent no-effect cases, and stops on ApprovalPending. |
src/failure.rs (#38) | FailureClass, EffectCertainty, FailureRecord, CancelToken. Reused here. |
src/events/{event,envelope,bus}.rs | AegisEvent, EventEnvelope (has a sequence field), broadcast EventBus. |
src/execution/{broker,action,receipt}.rs | ExecutionAuthority and action receipts: the only authority for effects. |
src/sessions, tests/aegis_tests.rs | Ids (RunId, SessionId), stores, and the integration test conventions (tokio tests, scripted fakes). |
Already present: the single-run lifecycle, approval-gate states, a per-run budget, cancellation tokens, failure vocabulary, events.
Absent before this change: prerequisite edges between tasks, readiness tracking, bounded concurrent execution of independent tasks, propagation of a prerequisite's failure to dependents, a workflow-level event order. No equivalent DAG exists, so src/orchestration/workflow.rs is new. It is not an inference scheduler: AIEN's aien-scheduler and the swarm manager are untouched and never called.
Model
TaskIdnewtype.WorkflowSpec::builder().add_task(id, &[deps], runner)...build()rejects empty ids, duplicate tasks, duplicate edges, self dependency, unknown predecessors and cycles with typedWorkflowError.TaskState {Pending, Ready, Running, WaitingForApproval, Completed, Failed(FailureRecord), Cancelled, Skipped{prerequisite}, Uncertain(FailureRecord)}.Uncertain(issue #55) means "not known whether the effect happened"; it is not terminal.TaskRunneris the task body and returnsTaskOutcome {Completed(value), Failed(ToolFault), ApprovalPending, Cancelled}.certainty_on_interrupt()says what is known about effects if the DAG interrupts the body (timeout, cancel); the default isUncertain.WorkflowConfig {run_id, session_id, max_parallel, per_task_timeout, total_budget}.
Rules the executor enforces
- A dependent becomes Ready only when every prerequisite is
Completed. - A prerequisite that is
Failed,CancelledorSkippedmakes the dependentSkippedwith aFailureRecordof classRejected, certaintyNoEffect, causeprerequisite failed: <id>. This is transitive. WaitingForApprovalis not success and not terminal. Dependents stayPending; the report lists them inunfinishedand the status isWaitingForApproval.- The DAG never retries or reschedules anything. An
Uncertainoutcome runs once and is never retried here. - Timeout gives
Failedwith classTimeoutand the runner's certainty, unless that certainty isUncertain: then the task becomesUncertain(#55). Cancellation (token or total budget) cancels running tasks and every Pending/Ready task and starts nothing new; a running task whose certainty isUncertainbecomesUncertaininstead ofCancelled. - Dependents of an
Uncertaintask are neither run nor skipped. They stayPending, are listed inunfinished, andWorkflowReport.blocked_behind_uncertainnames the uncertain task each one waits on (transitively). A task with both anUncertainand aFailedprerequisite is still skipped by the failed one. - Parallelism is bounded by a
tokio::sync::Semaphore. The coordinator only awaits; task bodies run on spawned tasks. Noblock_on. - The DAG authorizes nothing and caches no decision. Real effects go through the agent/skill gate path or
ExecutionAuthorityinside the task body.
Events and replay
Every transition takes a workflow sequence number under one lock, together with the state change, and is published in that same critical section. New AegisEvent variants: WorkflowTaskReady/Started/Completed/Waiting/Failed/Cancelled/Skipped, WorkflowFinished. They carry workflow_seq and go out with EventEnvelope.sequence set to it, so sorting by sequence replays the exact order. With max_parallel = 1 the whole order is fixed for a given spec; with more parallelism the order of simultaneous completions follows real completion order, but the sequence is still gapless and dependency-consistent. Existing variants are unchanged; the canonical mapping returns None for the new ones. The Uncertain task state (#55) has no bus variant yet (#55 item 4): its ledger event uncertain is written in sequence, and the bus stays silent rather than publish a false Failed or Cancelled. WorkflowStatus still reads Failed or Cancelled when a task is uncertain; the "needs reconciliation" status is #55 item 2, not in the first cut.
Results: WorkflowSnapshot.results maps task id to a sha256 digest of the result value. Failure records for Failed, Skipped and Cancelled tasks are in WorkflowReport.failures.
Agent adapter
AgentTaskRunner runs one AgentEngine::execute_task as a task; agent_outcome maps its result (failure class and certainty from the last tool failure, ApprovalPending stays pending, an incomplete run is Failed/Uncertain). It is a thin seam and is not exercised against a live model in tests.
Restart boundary
Workflow state is in memory only. After a process restart nothing is recovered and no task is resumed or re-run. WorkflowSnapshot is serializable (tested) so a later change can persist it, but no schema, table or recovery path exists. A resumed workflow must not re-run a task whose effect is Uncertain; that recovery policy is not designed here. Which record owns each fact of a delegated task, and the rebuild rule after a restart, are in DELEGATED-DAG.md. src/orchestration/recovery.rs (#56) implements that rebuild as a pure host function over an AuthorityLookup trait, tested against in-memory fakes; nothing stores the pointers yet and no real authority client exists.
Not claimed
AEGIS is outside release v1; nothing here is wired into a release path or the frozen E2E contract. Timings printed by the demo test compare max_parallel = 1 against 2 with sleep-based fake tasks on CPU. They are informational, and no GPU or throughput claim is made.
Progress messages for the Pi
src/orchestration/progress.rs (#58) maps recorded task state to the PST1 Draft v0 message types (aien-dev/aien-protocols-mv#28): Pending and Ready are queued; Skipped is failed with reason PREREQUISITE_FAILED; Uncertain, and Failed with Uncertain effect certainty, are uncertain_after_disconnect (not known), never failed. Ids come from the stored records, ordinals count each task's messages from 0, and a completed task carries its result digest, never raw output. A message that would need a guess (no cause id, no result digest, no action digest) is refused. The first cut has no encoding and no network; the resume summary and the bytes are later.
Grant gate for effectful tasks
src/orchestration/grant_gate.rs (#59) wraps an effectful task body. It starts only under a desk grant bound to the request's objective id and cause id, and checks the grant again after preparation, immediately before the effect. No grant leaves the task waiting for approval; an unbound binding, a forged id, a spent, expired or revoked grant, a foreign objective or cause, and an unreachable desk are refused with a named reason and no effect. The gate checks and never spends: the effect ledger spends the grant when it opens the effect intent. The desk is a trait tested with a fake; the real adapter waits on sovereign-core#379, and binding to the INTERPLANE canonical request digest waits on aien-protocols-mv#33.