Skip to content

Failure events 1/4: protocol, and one path for every invocation failure - #198

Open
shawnburke wants to merge 2 commits into
mainfrom
shawn/failure-events-1-protocol
Open

shawnburke wants to merge 2 commits into
mainfrom
shawn/failure-events-1-protocol

Conversation

@shawnburke

@shawnburke shawnburke commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Customer ask to be able to be notified if Axon handlers fail, with the handler invoke info and the failure reason, and the ability to retry or drop them in that case.

This is the basic protocol and plumbing for tracking and publishing failures (~400 lines impl)

Summary

Part 1 of 4, split from #190 (failure hooks, COR2-1098). This PR adds the failure event protocol and the agent plumbing that classifies every invocation failure. Nothing consumes the failures yet. The FailureManager and the DispatchEvents stream come in part 2.

Stack:

  1. Failure events 1/4: protocol, and one path for every invocation failure #198 Protocol and one failure path (this PR)
  2. Failure events 2/4: FailureManager and the DispatchEvents stream #199 FailureManager and DispatchEvents
  3. Failure events 3/4: Python SDK failure hook #200 Python SDK failure hook
  4. Failure events 4/4: Go SDK failure hook #201 Go SDK failure hook

Protocol (additive only)

  • rpc DispatchEvents(stream DispatchEventsRequest) returns (stream DispatchEvent): a bidi stream. The agent sends each failure, and the client answers DROP or RETRY on the same stream. It is a separate stream from Dispatch, because the Python SDK stops reading Dispatch while all its handler slots are busy. That is exactly when failures happen.
  • DispatchRequest.failure_events: the agent keeps events only for clients that ask for them.
  • DispatchHandlerInvoke.attempt (0 means "not said", treat it as 1) and .deadline.
  • ReportInvocationRequest.failure, InvocationFailure, FailureReason, FailureSource, FailureAction, FailureResolution, DispatchEventsRequest, DispatchEvent.
  • The regenerated Go SDK stubs and mocks are in this PR, so the protocol lands in one place.

Agent

  • Invocation state. A single SetState with an explicit transition table. A queued invocation moves once, to dispatched, expired or rejected. Once dispatched, it ends only by a report or by the agent's timeout, not by its queue timeout.

  • One failure path. Every failure the agent can see completes its invocation with a FailureError, and one watcher in Manager (watch) hands it to a FailureNotifier. The four sources are:

    • a full queue (NO_RESOURCES, caller_rejected);
    • expiry while queued (NO_RESOURCES);
    • the agent's own timeout (TIMEOUT/RUNTIME);
    • the client's report, through ReportInvocationRequest.failure.

    An error reported without failure, as older SDKs send them, is only recorded.

  • Deadline. Each dispatched invocation carries an absolute deadline: timeout + 5s grace. After it, the agent stops waiting and reports the timeout itself. The SDKs (parts 3 and 4) use it so they do not start stale work.

  • Generic send loop. InvocationSource[T] has one method, Dequeue(ctx, dispatchId), and drain() sends whatever a source hands out. Dispatch now drains Manager. Part 2 uses the same loop for DispatchEvents.

  • DispatchEvents answers Unimplemented until part 2. Without this stub, the embedded nil AxonAgentServer would panic.

  • Fixes:

    • HandlerInvoke methods use pointer receivers, because the value copy raced with Complete.
    • The dispatch queue map is locked, because webhooks and client streams both use it.
  • Test support: the webhook port can be set with WEBHOOK_PORT.

Compatibility

All proto changes are additive. Old SDKs do not set failure_events and ignore the new fields. With no FailureNotifier set, a failure is only logged.

Test plan

  • CI: make -C agent test, test-race
  • Handler unit tests (invoke_state_test.go), with a recording notifier:
    • state transitions;
    • queue full, expired in the queue, and a reported failure each reach the notifier;
    • a plain error does not;
    • a dispatched invocation does not expire on its queue timeout.
  • Over real gRPC (invocation_failure_test.go):
    • an unreported invocation becomes an agent TIMEOUT/RUNTIME, with the right deadline;
    • a client-reported failure is handed on once;
    • an unclassified client error is only recorded;
    • DispatchEvents answers Unimplemented.

🤖 Generated with Claude Code

The first of four PRs split from #190. It adds the failure event protocol
and the agent plumbing that classifies failures. Nothing consumes the
failures yet: the FailureManager and the DispatchEvents stream come next.

Protocol (additive):
- DispatchEvents, a bidi stream for failure events and their answers.
- DispatchRequest.failure_events, so the agent only keeps events for
  clients that ask.
- DispatchHandlerInvoke.attempt and .deadline.
- ReportInvocationRequest.failure, InvocationFailure, FailureReason,
  FailureSource, FailureAction, FailureResolution.

Agent:
- Invocations have one SetState with an explicit transition table. A
  queued invocation leaves the queue once: dispatched, expired or rejected.
  A dispatched one no longer expires on its queue timeout.
- Every failure completes its invocation with a FailureError: a full
  queue, expiry in the queue, the agent's own timeout, and a failure the
  client reports. One watcher in Manager hands those to a FailureNotifier.
  An error reported without a failure, as older SDKs send, is only
  recorded.
- Each dispatched invocation carries an absolute deadline (timeout + 5s
  grace), after which the agent reports the timeout itself.
- InvocationSource[T] and a generic drain() replace the Dispatch send
  loop. Dequeue takes only ctx.
- DispatchEvents answers Unimplemented until the FailureManager lands.
- HandlerInvoke methods use pointer receivers, and the dispatch queue map
  is locked.
- The webhook port can be set with WEBHOOK_PORT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shawnburke
shawnburke requested a review from ashiramin November 20, 2026 02:13
@shawnburke
shawnburke marked this pull request as ready for review November 20, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant