Package com.tnsai.resilience
package com.tnsai.resilience
Resilience patterns for fault-tolerant agent and action execution.
Two layers
This package houses two distinct concerns sharing the "resilience" label:- Agent-level orchestration
(
ResilienceExecutor,RetryPolicy) — wrapsAgent.chat/ tool-call paths withresilience4j-backed circuit breaker, bulkhead, rate limiter, and retry around the orchestration layer. ReadsResilience. - Action-level decorators
(the
TracedResolver/MeteredResolver/FallbackResolverfamily — issue #173 Phase 1) — wraps individual@ActionSpecdispatches with observability + recovery decorators driven byTraced,Metered, andFallback. Wired intoActionExecutorimmediately around each action's executor invocation; runs in canonical order:Traced → Metered → action → Fallback.
The two layers are intentionally separate: agent-level
resilience runs across many actions per chat turn, while action-
level decorators are per-dispatch and need different state
isolation guarantees. A future Phase 2+ may rationalise them once
@Idempotent support lands.
Action-level Phase 1 scope (#173)
Only the three decorators that don't require external storage are wired today — same boundary as the other Phase-1 batches in this sprint (#171 / #172 / #177).-
ClassDescriptionResolves the
@Fallbackannotation on a Role's methods and invokes the matching handler when an action's primary execution fails.Callback for re-invoking the primary action during retry.Functional contract for providing fallback values when an operation ultimately fails.Per-invocation handle for a@Meteredaction — opened byMeteredResolver.start(com.tnsai.metadata.ActionMetadata, com.tnsai.roles.Role)immediately before action dispatch and closed in afinallyblock.Resolves the@Meteredannotation on an action method or its declaring Role class and produces aMeteredHandleto wrap the dispatch.Programmatic resilience policy for a builder-builtRole— the builder-path counterpart of the@Resilienceannotation (TNS-567).Fluent builder.Central executor that combines retry policies, circuit breaker, bulkhead, rate limiting and dead-letter queue tracking.In-memory metrics registry for@Meteredactions (issue #173, Phase 1).Immutable snapshot of one metric's state at the momentResilienceMetrics.snapshot(java.lang.String)was called.Immutable descriptor for executing an operation through the resilience pipeline.Immutable retry policy definition used by the resilience layer.Resolves the@Tracedannotation on an action method or its declaring Role class and produces aTracedSpanthat wraps the dispatch with structured trace logs.Per-invocation handle for a@Tracedaction — opened byTracedResolver.open(com.tnsai.metadata.ActionMetadata, com.tnsai.roles.Role, java.util.Map<java.lang.String, java.lang.Object>)immediately before dispatch and closed in afinallyblock.