docs/ez-agent-ruby/lib/ez_agent/error-classification.md
Ruby error classification and incident boundaries
The Ruby API separates transient evidence from permission to retry. A transport failure or local timeout can leave admission uncertain. Neither proves that the daemon rejected the operation, and neither authorizes repeating a side effect. Classification does not recover, retry, connect, or change a terminal result.
Exact classification APIs
require "ez_agent/api" loads EzAgent::API::ErrorClassification.
require "ez_agent/workflow/error_classification" loads the independent
EzAgent::WorkflowErrorClassification helper without loading Workflow itself.
Load Workflow separately when using its typed errors.
Both modules provide:
classify(error) -> EzAgent::API::ErrorClassification::Resulttransient?(error) -> booleanretry_authorized?(error) -> booleanadmission_ambiguous?(error) -> boolean
The immutable result exposes category, transient?, retry_authorized?, and
admission_ambiguous?. Categories are fixed symbols, never exception class
names or provider strings. No method reads exception messages, inspection,
backtraces, status text, or terminal prose.
API categories
| Category | Typed evidence | Transient | Ambiguous admission |
|---|---|---|---|
endpoint | EndpointError | false | false |
transport | TransportError | true for no cause or I/O, system-call, or EOF cause | true |
connection_closed | ConnectionClosedError without a typed API cause | false | true |
handshake | HandshakeError | only with a transient TransportError cause | false |
decode | DecodeError, including oversized and incomplete frame subclasses | false | false |
encode | EncodeError | false | false |
timeout | TimeoutError | true | true |
registration | RegistrationError and its subclasses | false | false |
service | ServiceError, regardless of code or message | false | false |
callback | CallbackError | false | false |
unsupported_message | UnsupportedMessageError | false | false |
invalid_argument | ArgumentError or TypeError | false | false |
fatal | an Exception outside StandardError, or a fatal cause in a transport, handshake, closure, or callback wrapper | false | false |
unexpected | everything else | false | false |
Every API result has retry_authorized? == false. An unexpected reactor failure
may be wrapped in TransportError for compatibility. Its non-I/O cause does not
become transient. A local handshake deadline has no distinct typed timeout
cause today, so it remains a non-transient handshake classification.
ConnectionClosedError with a typed API cause uses that cause's classification.
Traversal is bounded to eight wrappers and detects cycles. A malformed chain
returns unexpected with ambiguous admission. Other ambiguity flags describe
only what the error type establishes. A false flag does not prove that no side
effect happened. The generic timeout and closure types lack enough call-stage
evidence to distinguish a pre-admission wait from a post-write wait.
Workflow handoff
The Workflow helper adds three categories:
query_transientforWorkflowQueryTransientErrorwhose existingretryable?method returns exactlytrue, whose outcome is notabort, and whose enclosing occurrence carriers do not veto retry. Bothtransient?andretry_authorized?are true; ambiguous admission is false.query_failurefor the same type without explicit retry authorization, or with an abort outcome or enclosingretry_eligibility: false. All three flags are false. The class name alone does not establish transience.cancelledforWorkflowCancellationError. All flags are false.
It unwraps only the known WorkflowQueryExecutionError,
WorkflowQueryOccurrenceError, and WorkflowSetupError carriers, with bounded
cycle detection. Other errors delegate to the API classifier. It does not call
arbitrary objects' error, retryable?, or cause methods. A transport error or
API timeout remains ambiguous and unauthorized after unwrapping.
Occurrence vetoes are retained through nested execution carriers. An outer
retry_eligibility: true does not override an inner false veto. These are the
existing executor exclusions, not a new replay or continuation policy.
This helper is available for the recovery owner to require and call. It is not wired into the executor or scheduler by this change. Explicit typed retry permission still requires the owner's existing replay/ancestry checks, retry budget, and cancellation policy. The helper alone cannot authorize bypassing those checks.
Concrete provider wire limits
protocol.Error carries code, message, and optional request_id. Ruby maps a
correlated error to ServiceError. The code identifies a service operation
failure; this helper deliberately does not treat any code as a provider retry
contract. Unknown codes remain service, even if they contain words such as
"temporary" or "retryable".
prompt_completed and agent_end carry reason and optional diagnostic
message. They do not carry a structured provider transient category, HTTP
status, retry authorization, or retry delay. The existing Workflow terminal
path constructs WorkflowQueryTransientError without retryable: true.
Therefore exhausted provider runs remain query_failure in this helper.
Go provider-native RetryableError and HTTPError types are not Ruby wire
values. Ruby cannot infer their type from terminal messages. HTTP-looking
numbers, rate-limit prose, DNS text, or provider bodies must not be parsed to
invent retry permission. Durable error turns and assistant exit metadata remain
failures. This change adds no wire fields and changes no durable terminal meaning.
Process recorder and fixed sites
EzAgent::API::Incidents.recorder returns one reusable process-wide
EzAgent::Incident::Recorder, with component ruby_api. Connections, requests,
and leaves do not allocate separate recorders. Workflow recovery owners may
register their own fixed repository sites on this same recorder and call its
existing breadcrumb, incident, flush, and close methods. A Workflow must
not close the shared recorder when it closes an individual connection.
The recorder uses the existing Incident.state_dir environment resolution,
not peer-supplied paths. An exit hook requests a bounded 0.1-second drain if the
process recorder was created. It does not allocate a recorder on healthy exit.
The recorder's existing queue, file, repeat, and byte bounds apply. Delivery is
best effort, not an fsync guarantee. See incident infrastructure.
The internal adapter exposes these reusable methods:
Incidents.record(boundary, error, data: {}, event: nil, outcome: :fail)records an incident and returns the recorder's acceptance boolean.Incidents.breadcrumb(boundary, event:, outcome: :observe, data: {})retains bounded evidence in memory until an incident activates the writer.Incidents.timing(started, budget = nil)converts a monotonic start time and optional seconds budget toduration_msandbudget_msintegers.Incidents::Contextprovides the samerecordandbreadcrumbsignatures on an injected recorder, plus itsrecorderreader.
Boundary symbols are fixed in Incidents::BOUNDARIES: connect, open,
reader, request, connection_join, callback_join, provider_join, write,
cleanup, callback, terminal_callback, diagnostic_callback, provider,
provider_batch, provider_call, provider_callback, provider_route,
provider_control, and heartbeat. Each site is a repository file/function
identity plus a fixed classifier category suffix. Breadcrumb sites use the fixed
observation suffix. Site combinations are registered once on first use without
consulting a runtime stack.
The adapter allows only locally generated rpc_ request IDs with 32 lowercase
hex digits and bounded nonnegative integer duration_ms/budget_ms data. It
omits other fields and invalid values before recorder validation. Peer IDs,
leaf IDs, capability names, request types, provider bodies, frames, exception
text, stacks, and paths never enter these records.
RPCs retain started/observe and completed/success, completed/fail, or
completed/cancel breadcrumbs. Failures also emit incidents. A reply that wins
a timeout race, or otherwise completes past the local budget, remains a success
and emits a request.timeout incident with completed/success and elapsed/budget
evidence. This does not turn success into failure or authorize a retry. Reader,
event callback, and provider joins emit fixed timeout incidents when their
join deadline expires, preserving the raised TimeoutError.
Failure incidents default to outcome: fail. Cleanup uses cleanup_failed,
timeouts use timeout, and other failures use unexpected. Comments are fixed
deadline exceeded or unexpected failure. Breadcrumbs have no comment.
Healthy requests and clean local cancellation do not start a writer, open files,
or create directories. A later incident may flush their bounded breadcrumbs.
The first terminal exception and local/remote provenance never change on a later
close. Pending and new requests that receive the stable clean-local-close
exception retain cancellation breadcrumbs but emit no incident. A previous
remote/fatal terminal failure or a cleanup failure is not suppressed by a later
local close. Cleanup incidents retain their existing containment and are recorded
independently, even if a pending waiter wakes before cleanup finishes.
Boundaries record before preserving the existing typed failure or diagnostic
route. Ordinary callback/provider failures still become error diagnostics or
typed error results, never successful results. Ordinary cleanup/diagnostic
callback failures retain their existing containment. Exceptions outside
StandardError are recorded and re-raised instead of converted to a result,
wrapped as ordinary reactor errors, or silently swallowed during cleanup.
Connection-owned threads disable Ruby's automatic raw exception/backtrace
printing; join still raises their original failures. Fatal reader, provider
worker/control/heartbeat, and event/diagnostic callback failures publish the
original exception as the first connection terminal error before rethrowing.
This closes admission, releases RPC/event waiters, cancels provider work, and
stops the reader even while the peer remains open. join raises fatal failures
even with raise_on_error: false; callers need not call close first. A fatal
terminal callback cannot overwrite an earlier terminal exception, but its thread
still rethrows and join exposes it.
Events.new(fatal_hook: nil) is an internal ownership seam. Connections supply
Connection#worker_failed; standalone Events keep their previous behavior with
no hook. The connection hook terminalizes work without letting a cleanup failure
replace the worker's original fatal exception. Audit adapter failures, including
fatal sink failures, return false rather than replace useful work results or
exceptions. This containment applies to auditing only, not to operation or
callback failures.