# Unified agent action lifecycle

| Dimension | Values | Meaning |
| --- | --- | --- |
| Permission | allow / ask / deny | Whether this exact operation may begin under current authority |
| Outcome | not_started / succeeded / failed / unknown | What is known about execution. A failure can have partial effects. |
| Delivery | pending / recorded / projected | Whether the result is durably stored and reflected in conversation and UI |

```
prepare → authorize → [durable wait → revalidate] → dispatch → record result → checkpoint → project
                  ↘ deny → record not_started → checkpoint → model continues or explains blocker
```

Built on the existing Agent loop, permission service, execution store, durable waits and interface projections; no second workflow engine. Action ID, execution ID, tool-call ID, policy version and canonical argument digest bind every decision, approval, receipt and recovery. A rejection is a completed decision with outcome not_started, not a completed task. Only unknown needs effect reconciliation.

## Permission preparation and automatic review

1. Resolve authenticated authority, policy version, tool capabilities, project binding and exact arguments; existing hard constraints, authority checks, plan restrictions, deny and ask rules and scoped grants stay.
2. Preflight runs asynchronously before a dispatch intent. Auto review gets the complete bounded operation, trusted working directory and scope, the owner request and restrictions. Tool arguments and repository content are untrusted. Oversized or unparseable input is never approved from a truncated prefix.
3. Classifier timeout, cancellation and provider failure differ from a risk rejection: they never execute the action and count as no verdict.
4. A durable approval wait is published only for an eligible interactive owner. Hard constraints and explicit denials cannot become prompts. Noninteractive runs report the restriction and may continue independent work.
5. Before dispatch, revalidate permission version, argument digest, approval identity and file preconditions. A mode change invalidates an obsolete decision; a grant never authorizes a modified command.

**Limits on decisions**

- Auto review cannot rewrite its own policy. Changes to tools, permission state, project binding or restrictions invalidate cached decisions; there is no global allow cache.
- Not every denial is not_started: a denial before the executor proves non-execution, but a rejected escalation after a sandbox attempt may follow partial execution and keeps that evidence.

## Failure handling

| Failure | Response |
| --- | --- |
| Invalid arguments | Structured validation details; the model may correct execution-relevant arguments |
| Permission rejection | Record not_started with reason, policy version and allowed resolution. No retry under unchanged authority by altering descriptive text. |
| Transient transport failure | Bounded retry only with evidence of no execution or supported idempotency; never replay a possibly completed write |
| Deterministic tool failure | Output returned for diagnosis; repeats need changed input or conditions; other work may continue |
| Unknown side effect | Exact evidence preserved; reconciliation required, and a retry does not count as one |
| Infrastructure or checkpoint failure | Reported independently of the tool outcome; a recoverable receipt is kept when available |

**Repeat tracking and refusal counters**

| Item | Rule |
| --- | --- |
| Recent failure map | Bounded to the 16 entries `AgentCheckpointV1` enforces, shared by loop and serializer. Eviction bounds storage, not permission or execution budgets. Full history stays in events; no failure count declares a task complete. |
| Identity | Tool-specific: excludes presentation-only fields such as Bash description, keeps command, working directory and permissions. Fields named description on other tools are kept. Shell programs are never inferred equivalent. Legacy checkpoints stay readable; old keys are normalized only where the tool contract is known. |
| Fallback thresholds | Three consecutive or twenty total classifier refusals trigger manual prompting, through the existing owner approval wait; never overrides explicit denial |
| Scope | Session and owner policy version; a permission version change starts a new epoch |
| Resets | Allowed and approved fallback operations reset only the consecutive count; the total resets when its threshold approval completes or the epoch changes |
| No double counting | Canonical execution events keep each operation identity and verdict in the existing SQLite transaction |
| No verdict | Changes neither counter and never authorizes execution; risk refusals do not consume the execution-failure repeat budget |

## Receipts and recovery

A durable receipt holds exact tool-call identity, outcome, execution-start evidence, error code, result reference and digest, stored independently of display state. Checkpoint construction cannot erase a known result. External operations and local SQLite cannot share a transaction, so exactly-once external effects are not promised.

| Found on recovery | Action |
| --- | --- |
| Receipt recorded, checkpoint missing | Rebuild the continuation from the recorded result |
| Checkpoint recorded, projection missing | Replay projection only |
| Dispatch without a trustworthy receipt | Existing effect reconciliation |
| Older records | Non-execution is never inferred from tool text; reconcile the trusted permission event, call identity and stored command. A task is never marked completed as a repair. |

## Host integration

| Item | Rule |
| --- | --- |
| Execution start | Recorded immediately before the authorized implementation |
| Results | Completed and not-started results are sealed before checkpoint serialization; application result details are not execution evidence |
| Tool visibility | Model-facing tools are filtered against live rules per provider request, without changing the saved execution contract; dynamic revocation is enforced at execution |
| Projection | Host outcomes reach live events and history |
| Human UI actions | Keep their authenticated human origin; routing an agent action through HTTP grants no human privileges |

## Provider response events

Each dispatched model request has a unique `request_id` and exactly one started and one completed event. Completion records completed, failed, cancelled or incomplete, including transport exceptions and EOF without a terminal event. Exceptions and cancellation propagate unchanged; accounting does not replay tools or authorize retries. Legacy partial text stays incomplete, and observers do not treat unsuccessful requests as answers.

## Ownership

| Area | Responsibility |
| --- | --- |
| permissions | Policy, asynchronous preflight, trusted review input, refusal counters, durable approval waits |
| agent tool execution | Repeat tracking and identity in a small failure-policy module; consumes decisions, emits outcomes |
| `conversation/production_driver` and execution | Receipts, checkpoint cursor, recovery, effect reconciliation |
| Web execution projection | Waiting, denied, failed, unknown and remaining work, on existing approval UI and actions |
| Native tools, Terminal, Web resources, application providers | Use this lifecycle through the common tool entry; no provider-specific engines |

**Acceptance**

| Area | Must hold |
| --- | --- |
| Failure tracking | More than sixteen distinct failures cause no schema error; descriptive changes do not bypass suppression; changed executable arguments stay distinct; old checkpoints load |
| Preflight | A denied operation never calls its executor; dangerous suffixes are caught; cancellation and policy changes do not dispatch; exact approvals survive restart once |
| Refusal fallback | Interactive and noninteractive differ explicitly; hard denials stay; counters survive resume and parallel calls |
| Receipts | A failure between result and checkpoint, then restart, does not call a mutating executor again; unknown effects stay blocked |
| Visibility | Revocation is immediate; a hidden tool cannot be invoked by an old decision; UI and backend show the same reason and recovery actions |

**References**

| Reference | Behaviour | Adopted as |
| --- | --- | --- |
| [Codex ToolOrchestrator](https://github.com/openai/codex/blob/8b78600dc85cc265d7e7e827f6aa903875405287/codex-rs/core/src/tools/orchestrator.rs) | Approval precedes sandbox selection and execution; rejection differs from sandbox denial; escalated retries depend on policy | One pre-execution decision and typed outcomes; a retry never changes authority implicitly |
| [Claude Code auto mode](https://code.claude.com/docs/en/permission-modes#when-auto-mode-falls-back) | Classifier denials are visible; 3 consecutive or 20 total trigger prompting where supported; noninteractive runs keep the denial | Separate counters on durable approval waits; fallback thresholds, not task or storage limits |
| [Claude Code permission rules](https://code.claude.com/docs/en/permissions) | Harness-enforced; whole-tool denial removes the tool, scoped denial applies to matching operations | Tool visibility reflects capability |
| [Claude Code checkpoints](https://code.claude.com/docs/en/checkpointing) | File-edit rewind does not undo Bash or external effects | Conversation recovery, file undo and effect reconciliation stay distinct |

The receipt protocol is an OpenProgram design, not a claim about other systems' internals.
