adk-go icon indicating copy to clipboard operation
adk-go copied to clipboard

feat: Add OnPipelineErrorCallback lifecycle hook to Plugin Config

Open mramansayyad opened this issue 6 months ago • 5 comments

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

  1. Callback Signature:
    type OnPipelineErrorCallback func(agent.InvocationContext, error) error
    
  2. Extended plugin.Config & plugin.Plugin: Added OnPipelineErrorCallback fields and constructor mappings, along with the OnPipelineErrorCallback() accessor on plugin.Plugin.
  3. Plugin Manager Execution: Added RunOnPipelineErrorCallback in PluginManager to 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
    }
    
  4. Orchestrator Integration: Intercepted pipeline errors in Run and RunLive loops in runner/runner.go and 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 BeforeRunCallback trigger 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).

mramansayyad avatar May 25 '26 03:05 mramansayyad

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.

google-cla[bot] avatar May 25 '26 03:05 google-cla[bot]

I signed it.

mramansayyad avatar May 25 '26 03:05 mramansayyad

cc @anFatum @wolo-lab could you please take a look and review this PR?

mramansayyad avatar May 25 '26 06:05 mramansayyad

@indurireddy-TF @dpasiukevich @wolo-lab please anyone could take a look and review this PR?

mramansayyad avatar May 28 '26 17:05 mramansayyad

This PR is fully implemented, verified with comprehensive tests, and has no merge conflicts. Requesting review and merge. Thank you!

mramansayyad avatar Jun 05 '26 17:06 mramansayyad