Skip to content

Failure events 4/4: Go SDK failure hook - #201

Draft
shawnburke wants to merge 1 commit into
shawn/failure-events-2-managerfrom
shawn/failure-events-4-go
Draft

shawnburke wants to merge 1 commit into
shawn/failure-events-2-managerfrom
shawn/failure-events-4-go

Conversation

@shawnburke

@shawnburke shawnburke commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Part 4 of 4, split from #190 (COR2-1098). This PR adds WithFailureHook to the Go SDK. Based on #199.

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
  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 (this PR)

Behavior

  • WithFailureHook sets a hook that runs for each failure event from the agent. It returns FailureActionDrop or FailureActionRetry, which is sent back as the answer. A panicking hook answers DROP, and the stream continues.
  • The SDK only reports and answers. It classifies its own failures into ReportInvocationRequest.failure:
    • an error or panic is HANDLER_ERROR/APPLICATION;
    • a timeout is TIMEOUT;
    • a timeout during a Cortex API call, or one capped by the deadline, is RUNTIME.
  • It does not start an invocation past its deadline, and caps a handler's timeout at it.
  • With an older agent, DispatchEvents answers Unimplemented. The SDK logs once and does not redial.
  • Fixes found along the way:
    • invokeHandler let a timed-out handler write to the report while it was being sent.
    • Run(ctx) ignored cancellation: it opened its stream with context.Background(), and its exit flag was raced.

Test plan

  • CI: go test -race ./... in sdks/go
  • Unit tests:
    • the reported reason/source for an error, a panic, a timeout, a timeout during an API call, and a deadline-capped timeout;
    • the hook is not run locally;
    • event → hook → answer, for RETRY and DROP;
    • a panicking hook answers DROP;
    • an Unimplemented agent is not redialed;
    • the failure_events flag.
  • e2e (e2e_failure_test.go, skipped with -short): against a real agent, a handler error and a timeout each reach the hook, the retry succeeds with the original body, and the failure is not delivered twice.

🤖 Generated with Claude Code

The fourth of four PRs split from #190.

WithFailureHook sets a hook that runs for each failure event the agent
sends on DispatchEvents, and returns FailureActionDrop or
FailureActionRetry, which is sent back as the answer. A panicking hook
answers DROP and the stream continues.

The SDK does not run the hook for its own failures. It classifies them
into ReportInvocationRequest.failure: HANDLER_ERROR for an error or panic,
TIMEOUT for a timeout, APPLICATION or RUNTIME by where it happened (a
timeout during a Cortex API call, or one capped by the deadline, is
RUNTIME). It does not start an invocation past its deadline.

An agent without DispatchEvents answers Unimplemented; the SDK logs once
and does not redial.

Fixes found along the way:
- invokeHandler let a timed-out handler write to the report while it was
  being sent.
- Run(ctx) ignored cancellation: it opened its stream with
  context.Background(), and its exit flag was raced.

The end-to-end test builds and runs the real agent; it is skipped with
-short.

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
@engrams-agent
engrams-agent Bot force-pushed the shawn/failure-events-4-go branch from 2989379 to 16e636e Compare November 20, 2026 02:12
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