Failure Mode Runbook

Maps each error code to cause, detection, recovery steps, and prevention.


Tool errors

ToolNotRegistered

Field Value
Cause Tool call for a name not in undolog_tool_registry for the org
Detection Engine returns ToolNotRegistered gRPC error
Recovery Register the tool via SDK @undolog_tool decorator
Prevention Validate tool names match registry entries before deployment

DuplicateSignature

Field Value
Cause Concurrent proxy instances insert the same call signature
Detection Engine returns DuplicateSignature gRPC error
Recovery Retry the call; the advisory lock + ON CONFLICT handles most cases
Prevention Ensure single-proxy deployment or use advisory lock tuning

InvalidStateTransition

Field Value
Cause RPC called on effect in wrong state (e.g. Commit on Pending)
Detection Engine returns InvalidStateTransition gRPC error
Recovery Check effect state via effect log; follow correct RPC sequence
Prevention Enforce Intercept -> Execute -> Commit/Fail sequence in proxy

NotExecuting

Field Value
Cause Commit called on effect not in Executing state
Detection Engine returns NotExecuting gRPC error
Recovery Only call Commit after receiving Execute outcome from Intercept
Prevention Track effect state in proxy; skip Commit for Replay/Approval outcomes

EmptyUndoStack

Field Value
Cause Saga orchestrator pops from empty undo stack
Detection Engine returns EmptyUndoStack gRPC error
Recovery Informational; no compensation needed if stack is empty
Prevention Check undo stack length before attempting rollback

ApprovalAlreadyResolved

Field Value
Cause Approve/Reject called on already-resolved approval
Detection Engine returns ApprovalAlreadyResolved gRPC error
Recovery Refresh approval list; check current state
Prevention Use atomic compare-and-swap for approval decisions

ApprovalTimedOut

Field Value
Cause Approval window expired before human decision
Detection Engine returns ApprovalTimedOut gRPC error; processor logs Approval timeout processor: handled timed-out approvals; proxy metric undolog_proxy_approval_decisions_total{action="timeout"} increments
Recovery If auto_approve_on_timeout is true, tool auto-executes; otherwise re-invoke agent
Prevention Set appropriate timeout windows; monitor pending approvals

ApprovalNotFound

Field Value
Cause Approve or Reject called for an approval ID not present in undolog_approval_requests
Detection Engine returns ApprovalNotFound gRPC error with status code NOT_FOUND
Recovery Check approval request ID against active requests in PostgreSQL or proxy /approvals list. Verify if request was purged by retention
Prevention Refresh the pending approval list before submitting operator decisions

AdvisoryLockTimeout

Field Value
Cause Could not acquire PostgreSQL advisory lock after max attempts
Detection Engine returns AdvisoryLockTimeout gRPC error
Recovery Retry the operation; increase UNDOLOG_LOCK_MAX_ATTEMPTS or UNDOLOG_LOCK_RETRY_MS
Prevention Tune lock settings for expected concurrency; monitor lock contention

Database

Field Value
Cause SQL-level error: connection failure, constraint violation, deadlock
Detection Engine returns Database gRPC error with inner sqlx::Error
Recovery Check database connectivity; inspect inner error for SQL error code
Prevention Monitor connection pool usage; set appropriate pool size; use connection retry

Serialization

Field Value
Cause JSON serialization/deserialization fails for internal data
Detection Engine returns Serialization gRPC error with inner serde_json::Error
Recovery Validate tool inputs/outputs are valid JSON; check version compatibility
Prevention Ensure proxy and engine versions match; validate JSON at SDK boundary

Internal

Field Value
Cause Unexpected runtime error not fitting other categories
Detection Engine returns Internal gRPC error
Recovery Report as bug with session and effect IDs for debugging
Prevention Comprehensive testing; error handling for all edge cases

Admission and backpressure failures

CircuitBreakerOpen

Field Value
Cause Consecutive engine errors reached the configured threshold (UNDOLOG_PROXY_ENGINE_BREAKER_THRESHOLD on the proxy or engine error_threshold)
Detection Engine returns CircuitBreakerOpen error; proxy returns HTTP 503 Service Unavailable with Retry-After; log circuit breaker: Closed -> Open; proxy metric undolog_proxy_engine_breaker_state changes to 2; metric undolog_proxy_engine_rejections_total{reason="breaker"} increments
Recovery Check engine logs for consecutive transport or database failures. The breaker automatically enters Half-Open after cooldown (UNDOLOG_PROXY_ENGINE_BREAKER_RESET_SECS) and probes engine health with a single request
Prevention Address root causes of engine errors; tune breaker threshold and reset interval in proxy configuration

ConcurrencyLimitReached

Field Value
Cause In-flight engine RPCs exceed the concurrency gate (UNDOLOG_PROXY_MAX_ENGINE_RPCS or engine max_concurrency), or the wait queue reaches capacity
Detection Engine returns ConcurrencyLimitReached error; log concurrency limit reached: N permits in use; proxy returns HTTP 503 Service Unavailable with Retry-After; proxy metric undolog_proxy_engine_rejections_total increments with reason="gate" or reason="queue"; undolog_proxy_engine_inflight reaches configured cap
Recovery Reduce caller request rate; inspect slow queries holding connections; scale engine instances horizontally if database capacity permits
Prevention Configure bounded wait queue (UNDOLOG_PROXY_ENGINE_QUEUE_MAX and UNDOLOG_PROXY_ENGINE_QUEUE_WAIT_MS) to smooth micro-bursts; tune PgBouncer and engine concurrency limits

Compensation failures

CompensationRegisteredTooLate

Field Value
Cause Compensation registered after tool execution timestamp
Detection Engine returns CompensationRegisteredTooLate gRPC error
Recovery Fix ordering in orchestrator code; registered_at < executed_at must hold
Prevention Enforce compensation registration before execution in orchestrator

CompensationFailed

Field Value
Cause Compensation function exhausted all retries
Detection Effect enters CompensationFailed terminal state
Recovery Manual intervention required; inspect upstream service; retry compensation manually
Prevention Ensure compensation functions are idempotent; set appropriate retry count

Infrastructure failures

Database unavailable

Field Value
Cause PostgreSQL connection pool exhausted, server down, network partition
Detection Engine returns Database errors; health check fails
Recovery Check PostgreSQL status; verify connection string; restart if needed
Prevention Use connection pooling; monitor database health; set appropriate timeouts

Engine gRPC service down

Field Value
Cause Engine process crashed, OOM, or not responding
Detection Proxy returns 502/504 errors; gRPC status Unavailable
Recovery Restart engine process; check logs for crash reason
Prevention Use health checks; set resource limits; monitor memory usage

Proxy HTTP service down

Field Value
Cause Proxy process crashed, OOM, or not responding
Detection Client receives connection refused or timeout
Recovery Restart proxy process; check logs for crash reason
Prevention Use health checks; set resource limits; monitor memory usage

Network partition

Field Value
Cause Network between proxy and engine is disrupted
Detection gRPC calls timeout; health checks fail
Recovery Wait for network recovery; check firewall rules; verify DNS resolution
Prevention Use multiple availability zones; monitor network latency; set appropriate timeouts

Stale tool registry

Field Value
Cause Background registry refresh loop cannot query undolog_tool_registry due to database connection loss or lock contention
Detection Engine log Registry refresh failed - keeping stale data; Engine HTTP health endpoint (http://<engine-host>:9090/) reports registry_age_secs climbing beyond expected refresh interval; newly registered tools fail with ToolNotRegistered
Recovery Verify PostgreSQL connectivity and permissions on undolog_tool_registry; check engine logs for SQL error; restart engine if connection pool is wedged
Prevention Alert on engine health endpoint when registry_age_secs > 3 * UNDOLOG_REGISTRY_REFRESH_SECS; ensure PgBouncer maintains adequate connection headroom for background queries

Session cache saturation

Field Value
Cause Active sessions exceed max_entries or high session churn causes rapid eviction of cached session states
Detection Engine debug logs Session cache: evicting oldest entry at capacity or high ratio of Session cache miss to Session cache hit; elevated database query volume on undolog_sessions
Recovery Increase max_entries and ttl_secs in CacheConfig; verify client applications reuse session IDs rather than generating fresh sessions per tool call
Prevention Size session cache to cover twice concurrent active sessions; monitor database query latency for session lookups

See also