aegis-runtime-mv
Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha.
Brought by drakestapleton
aegis-runtime-mv / docs / FAILURE-PROVENANCE.md
| 1 | # Failure provenance and retry classification (issue #38) |
| 2 | |
| 3 | Code: `src/failure.rs` (all public types), wired in `src/agent.rs`, `src/skills.rs` |
| 4 | (`dispatch_classified`) and `src/events/event.rs` (`AegisEvent::StepFailed`). |
| 5 | |
| 6 | AEGIS is out of release v1. Nothing here is wired into a release path. |
| 7 | |
| 8 | ## Vocabulary |
| 9 | |
| 10 | `FailureClass`: Rejected, Unavailable, Timeout, Cancelled, Uncertain, Failed, Malformed, ApprovalPending. |
| 11 | `EffectCertainty`: NoEffect, Uncertain, EffectOccurred. |
| 12 | `RetryEligibility`: Retryable { max_attempts } or NotRetryable. Derived by the pure function |
| 13 | `retry_eligibility(class, certainty, idempotent, policy)`. It is never stored and never grants anything. |
| 14 | |
| 15 | Upstream mapping: aien-mcp `Rejected` is `Rejected` + `NoEffect`; `Uncertain` is `Uncertain`; `Finished` has no failure record. |
| 16 | |
| 17 | ## Retry rule |
| 18 | |
| 19 | An automatic retry happens only when all hold: class is Unavailable (never Rejected: a policy or gate denial is not retried), certainty is NoEffect, |
| 20 | the skill is on the idempotent list (`skill_effect_profile`), and `RetryPolicy.max_attempts` is above 1 |
| 21 | (default 1, ceiling 5). Every attempt is a new dispatch through the gated path (probe gate, allowlist, |
| 22 | handler). Timeout, Cancelled, Uncertain, Failed, Malformed and ApprovalPending are never retried. |
| 23 | ApprovalPending also stops the run: the later calls of that turn are not run and the model is not asked again. |
| 24 | |
| 25 | ## State and error mapping |
| 26 | |
| 27 | | Existing site | Signal today | FailureClass | EffectCertainty | |
| 28 | |---|---|---|---| |
| 29 | | `enforcement::probe_gate` refusal (`skills.rs` gated path) | Err string | Rejected | NoEffect | |
| 30 | | `enforcement::pre_dispatch_check`: not on allowlist, empty name, non-object args, bad shell command | Err string | Rejected | NoEffect | |
| 31 | | Skill name not in registry | "not found in registry" | Rejected | NoEffect | |
| 32 | | Handler error starting with "Unavailable" (cortex, telemetry stubs) | Err string | Unavailable | NoEffect | |
| 33 | | Handler error, idempotent skill (read_file, list_dir, git_status) | Err string | Failed | NoEffect | |
| 34 | | Handler error, mutating skill (write_file, bash_eval) | Err string | Failed | EffectOccurred (conservative) | |
| 35 | | Per-call deadline (`FailurePolicy.tool_timeout`), idempotent skill | new | Timeout | NoEffect | |
| 36 | | Per-call deadline, mutating skill | new | Timeout | Uncertain | |
| 37 | | `CancelToken` set before dispatch | new | Cancelled | NoEffect | |
| 38 | | `CancelToken` set while running, idempotent / mutating | new | Cancelled | NoEffect / Uncertain | |
| 39 | | Custom `ToolDispatcher` reports lost response | `ToolFault` | Uncertain | Uncertain | |
| 40 | | Custom `ToolDispatcher` reports unparsable result | `ToolFault` | Malformed | as reported | |
| 41 | | Custom `ToolDispatcher` reports human approval needed | `ToolFault` | ApprovalPending | as reported | |
| 42 | | `ExecutionAuthority::authorize` Err (broker seam, not used by `execute_task` today) | Err string | Unavailable | NoEffect | |
| 43 | | `DoctrineDecision` deny at the broker | decision | Rejected | NoEffect | |
| 44 | | `ActionStatus::Denied` / `Failed` | status | Rejected / Failed | NoEffect / as recorded | |
| 45 | | `RunState::Failed` / `Cancelled` / `WaitingForApproval` | state | derived from last record / Cancelled / ApprovalPending | from last record | |
| 46 | | Inference endpoint unreachable (`execute_task` returns Err) | Err | not classified (out of scope, engine error semantics unchanged) | n/a | |
| 47 | | Model tool arguments that are not valid JSON | wrapped as `{"raw": ...}` | unchanged | n/a | |
| 48 | |
| 49 | Rows marked broker, ActionStatus and RunState document how those states would map; this change does not alter |
| 50 | those code paths. Only the agent tool-call rows are exercised by tests. |
| 51 | |
| 52 | ## Record shape |
| 53 | |
| 54 | `FailureRecord`: sequence (stable order, starts at 1 per run), run_id, step_index, tool_call_id, |
| 55 | parent_call_id (the directly preceding failed call, a causal hint), tool_name, attempt, class, |
| 56 | effect_certainty, created_at (call scheduled, ms), failed_at (ms), cause (max 8 entries, each message at most |
| 57 | 512 bytes, payload stored only as a sha256 digest, argument strings echoed in messages replaced by `[redacted]`), |
| 58 | cause_truncated. |
| 59 | |
| 60 | Tool error text sent back to the model and stored in `ToolExecutionRecord.output` passes through the same |
| 61 | redaction as the failure record. `ToolExecutionRecord.arguments` is unchanged and still holds the raw arguments |
| 62 | (pre-existing behaviour, not part of this change). |
| 63 | |
| 64 | `ToolExecutionRecord.failure` holds the terminal record; `retry_failures` holds earlier failed attempts. |
| 65 | Both default to empty so older persisted JSON still loads. Every failed attempt is also published as |
| 66 | `AegisEvent::StepFailed` on the `EventBus` when one is attached (`AgentEngine::with_event_bus`). |
| 67 | `root_cause(records, start)` follows parent links to the original failure. |