Gate4 Orchestrator Controls
Objective
Define a deterministic orchestrator lifecycle, queue/cancellation controls, retry/failure-budget policy, and execution command boundary so runtime behavior can be tested, audited, and safely hardened.
State Contract
States:
receivedqueuedexecutingawaiting_toolawaiting_user_confirmationcompletedfailedcancelled
Transition Boundaries
- Requests start in
receivedand move toqueuedbefore execution work begins. - Execution can pause only in
awaiting_toolorawaiting_user_confirmation. - Terminal states are immutable: once
completed,failed, orcancelled, no further transition is accepted. - Invalid transitions must fail deterministically with explicit errors.
Deterministic Transition Matrix
| Current State | Allowed Targets |
|---|---|
received | received, queued, failed, cancelled |
queued | queued, executing, failed, cancelled |
executing | executing, awaiting_tool, awaiting_user_confirmation, completed, failed, cancelled |
awaiting_tool | awaiting_tool, executing, failed, cancelled |
awaiting_user_confirmation | awaiting_user_confirmation, executing, failed, cancelled |
completed | completed |
failed | failed |
cancelled | cancelled |
Queue and Cancellation Controls (AG-ORCH-02)
Queue/cancellation runtime semantics are active:
- Work items enter queue from
received -> queued. - Queue scheduling is deterministic: lower numeric priority executes first; same priority is FIFO.
dequeuetransitionsqueued -> executing.- Cancelling queued work prevents execution and records cancellation reason.
- Cancelling executing/awaiting work transitions directly to
cancelled. - Terminal states remain immutable under cancellation attempts.
Retry and Failure Budget Policy (AG-ORCH-03)
Retry runtime semantics are deterministic and bounded:
- Retry decisions are constrained by explicit
max_attemptsandmax_failures. - Retry-eligible failures emit bounded exponential backoff delay metadata.
- Retry path remains non-terminal and maps to retry-wait execution state (
awaiting_tool). - Attempt/failure budget exhaustion emits terminal
faileddecision with deterministic reason codes. - Terminal retry states are immutable for further attempt scheduling.
Retry Decision Matrix
| Condition | Decision | Next Runtime State |
|---|---|---|
| Attempts and failures within budget | Retry allowed with bounded backoff | awaiting_tool |
max_attempts exhausted | Retry denied | failed |
max_failures exhausted | Retry denied | failed |
| Retry state already terminal | New attempts denied | failed (immutable) |
Gate4 Scope Boundary
- AG-ORCH-01 transition contract, AG-ORCH-02 queue/cancellation controls, and AG-ORCH-03 retry/failure budget policy are active.
Execution Command Boundary (AG-EXE-01)
Execution side-effect operations are routed through internal command handlers before adapter calls:
- Deployment create/stop commands are emitted via command layer abstractions.
- Order place/cancel commands are emitted via command layer abstractions.
- Command layer delegates side effects to
ExecutionAdapter; provider APIs remain adapter-only. - Read paths (list/get) remain non-command adapter reads.
- Deployment create and order place commands enforce idempotency replay semantics; key/payload conflicts fail deterministically.
Migration Notes
- Runtime components should consume queue/retry outcomes via deterministic service calls, not ad-hoc state mutation.
- New orchestrator features must extend contract tests before runtime behavior changes are merged.
- Side-effecting execution retries remain gated by AG-RISK controls and execution command idempotency semantics.
Traceability
- Architecture interface contract:
/docs/architecture/INTERFACES.md - Runtime implementation:
/backend/src/platform_api/services/orchestrator_state_machine.py - Queue/cancellation runtime:
/backend/src/platform_api/services/orchestrator_queue_service.py - Retry policy runtime:
/backend/src/platform_api/services/orchestrator_retry_policy.py - Execution command runtime:
/backend/src/platform_api/services/execution_command_service.py - Contract tests:
/backend/tests/contracts/test_orchestrator_state_machine.py - Contract tests:
/backend/tests/contracts/test_orchestrator_queue_cancellation.py - Contract tests:
/backend/tests/contracts/test_orchestrator_retry_policy.py - Contract tests:
/backend/tests/contracts/test_execution_command_layer.py - Contract tests:
/backend/tests/contracts/test_execution_command_idempotency.py - Related epics/issues:
#77,#138,#106