feat: Add OnPipelineErrorCallback lifecycle hook to Plugin Config
Pull Request: Add OnPipelineErrorCallback lifecycle hook to Plugin Config
Description
Fixes #886
This PR introduces the OnPipelineErrorCallback lifecycle hook to plugin.Config and plugin.Plugin structures.
Currently, plugin.Config supports precise model-level (OnModelErrorCallback) and tool-level (OnToolErrorCallback) failure hooks, but lacks a mechanism to intercept and handle orchestrator/pipeline-level failures. If an error is encountered during the runner lifecycle (e.g., within OnUserMessageCallback or BeforeRunCallback), the runner immediately aborts execution.
With OnPipelineErrorCallback, plugins can now intercept, log, or transform pipeline-level errors before they propagate up the call stack, enabling custom global error tracking, retry policies, or fallback behavior.
Proposed API / Design
- Callback Signature:
type OnPipelineErrorCallback func(agent.InvocationContext, error) error - Extended
plugin.Config&plugin.Plugin: AddedOnPipelineErrorCallbackfields and constructor mappings, along with theOnPipelineErrorCallback()accessor onplugin.Plugin. - Plugin Manager Execution:
Added
RunOnPipelineErrorCallbackinPluginManagerto run the active plugin stack's error hooks sequentially:func (pm *PluginManager) RunOnPipelineErrorCallback(cctx agent.InvocationContext, err error) error { for _, plugin := range pm.plugins { callback := plugin.OnPipelineErrorCallback() if callback != nil { err = callback(cctx, err) } } return err } - Orchestrator Integration:
Intercepted pipeline errors in
RunandRunLiveloops inrunner/runner.goand fed them to the active plugin manager before yielding the final error or exiting.
Telemetry Test Fix
Fixed a flaky assertion in server/adkrest/internal/services/debugtelemetry_test.go where expected spans list was compared without sorting, causing non-deterministic map iteration order failures. Added cmpopts.SortSlices sorting by span Name to ensure stable green builds.
Verification & Testing
Added new subtests under TestRunner_OnPipelineErrorCallback in runner/runner_test.go:
- BeforeRunCallback Error: Validates that errors raised in
BeforeRunCallbacktrigger the hook and are properly propagated/transformed. - OnUserMessageCallback Error: Validates that errors raised during message session appends trigger the hook and are properly propagated/transformed.
- Agent Run Loop Error: Validates that errors returning from the inner agent execution loop trigger the hook and are properly propagated/transformed.
Ran all test packages:
go test -v ./runner/...
go test ./...
Result: PASS (100% green).
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
I signed it.
cc @anFatum @wolo-lab could you please take a look and review this PR?
@indurireddy-TF @dpasiukevich @wolo-lab please anyone could take a look and review this PR?
This PR is fully implemented, verified with comprehensive tests, and has no merge conflicts. Requesting review and merge. Thank you!