Skip to content

Failure events 2/4: FailureManager and the DispatchEvents stream - #199

Open
shawnburke wants to merge 1 commit into
shawn/failure-events-1-protocolfrom
shawn/failure-events-2-manager
Open

shawnburke wants to merge 1 commit into
shawn/failure-events-1-protocolfrom
shawn/failure-events-2-manager

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 management of those failures which sends an invoke to the SDK hook to execute the failure handler code.

Summary

Part 2 of 4, split from #190 (COR2-1098). This PR delivers failures to clients that ask for them, and applies each client's answer. Based on #198.

Stack:

  1. Failure events 1/4: protocol, and one path for every invocation failure #198 Protocol and one failure path
  2. Failure events 2/4: FailureManager and the DispatchEvents stream #199 FailureManager and DispatchEvents (this PR)
  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

Design

handler error / timeout in SDK ─┐ ReportInvocation{error, failure}
agent timeout (no report)      ─┤ completeInvocation(report with failure)
queue full / expired in queue  ─┘ invocation.Complete(FailureError)
                                     │
                       Manager: one completion watcher        (part 1)
                                     │ FailureError
                                     ▼
                              FailureManager  (queues, metric, retries)
                                     │ DispatchEvents (bidi)
                                     ▼
                         SDK runs its hook → answers DROP | RETRY
                                     │
                     FailureEvent.Resolve → Manager.Trigger(attempt+1)
  • FailureManager (handler/failure_manager.go) owns everything failure-related:

    • the per-dispatch queues. They are unbounded, so no failure is dropped;
    • the axon_handler_failure_events_pending metric;
    • retries, which go back through Manager.Trigger, and the 5-attempt cap.

    It queues only for dispatch ids that subscribed, through DispatchRequest.failure_events or by opening DispatchEvents.

  • Handles. Dequeue hands out a *FailureEvent. The stream calls Resolve(action) when the answer arrives, or Requeue() if the stream ends first. An unanswered failure is then sent again, ahead of the rest. Exactly one of the two takes effect.

  • DispatchEvents drains the FailureManager with the same drain() that Dispatch uses, and applies each answer.

  • Retry finds the handler again after the client re-registered (new id, same dispatch id and name).

  • The FailureManager is provided in the serve and relay stacks.

Compatibility

Agent SDK Behavior
new old Unchanged. The old SDK does not set failure_events, so nothing is queued.
old new DispatchEvents answers Unimplemented; the SDK logs once and stops asking.

Known limits

  • Failures live in agent memory, so an agent restart loses any that are not yet answered.
  • Delivery is at-least-once. A failure whose answer was lost with its connection is sent again.

Test plan

  • CI: make -C agent test, test-race
  • FailureManager unit tests:
    • 10k failures, none dropped, kept in order;
    • nothing is queued without a subscriber;
    • unanswered failures are requeued first;
    • resolve: RETRY gives attempt 2, DROP queues nothing, a second answer is refused, the retry cap, a missing attempt counts as the first;
    • a retry finds a re-registered handler;
    • concurrent waiters get distinct events.
  • Webhook 503 produces a caller_rejected failure.
  • e2e over real gRPC:
    • an unreported invocation becomes TIMEOUT, is answered RETRY, and runs as attempt 2;
    • a client-reported failure is delivered once, and DROP does not rerun it;
    • an unanswered failure is sent again after a disconnect.

🤖 Generated with Claude Code

The second of four PRs split from #190. It builds on the protocol and the
single failure path, and delivers failures to clients that ask for them.

- FailureManager owns everything failure-related: the per-dispatch queues
  (unbounded, so no failure is dropped), the
  axon_handler_failure_events_pending metric, retries through
  Manager.Trigger, and the 5-attempt cap. It queues only for clients that
  set DispatchRequest.failure_events.
- Dequeue hands out a *FailureEvent. The stream calls Resolve(action) when
  the client answers, or Requeue() if the stream ends first, so an
  unanswered failure is sent again, ahead of the rest.
- DispatchEvents drains the FailureManager with the same drain() that
  Dispatch uses for the Manager, and applies each DROP or RETRY answer.
- The FailureManager is provided in the serve and relay stacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@engrams-agent
engrams-agent Bot force-pushed the shawn/failure-events-2-manager branch from e1a7aa0 to 5019c4b Compare November 20, 2026 02:12
@shawnburke
shawnburke requested a review from ashiramin November 20, 2026 02:17
@shawnburke
shawnburke marked this pull request as ready for review November 20, 2026 02:17
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