Skip to content

feat: Add push notification plugin hooks in DefaultPushNotificationSender - #841

Merged
bartek-gralewicz merged 6 commits into
mainfrom
bgralewicz/push_hooks
Nov 20, 2026
Merged

bartek-gralewicz merged 6 commits into
mainfrom
bgralewicz/push_hooks

Conversation

@bartek-gralewicz

Copy link
Copy Markdown
Collaborator

Description

Runs the push hooks from @a2a-js/sdk/plugins (#826) around each webhook delivery in DefaultPushNotificationSender. Plugins are set with the new DefaultPushNotificationSenderOptions.plugins. DefaultRequestHandler passes its own plugins option to the default sender it creates.

const pushTracing: A2APlugin = {
  name: 'push-tracing',
  beforePushSend: (req) => {
    req.headers['traceparent'] = currentTraceparent(); // your own helper
  },
  onPushSent: ({ request, statusCode, durationMs, error }) =>
    console.log(request.url, statusCode, `${durationMs.toFixed(1)}ms`, error ?? 'ok'),
};

const sender = new DefaultPushNotificationSender(store, { plugins: [pushTracing] });

Behavior

  • beforePushSend gets a PushRequest with the task id, URL, headers, event, a skip flag and a state map. It can add or change headers, which the POST then sends, and set skip.
  • The URL can't be changed by a plugin, so a delivery can't be redirected. This matches a2a-python.
  • If beforePushSend throws, nothing is sent and the delivery fails. send logs it the same way as a failed POST.
  • If skip is set, nothing is sent.
  • onPushSent runs exactly once per delivery:
    • on success, with the status code;
    • on a non-2xx response, with the status code and the error;
    • on a network error, with the error and no status code;
    • on skip, with skipped: true;
    • when beforePushSend throws, with that error.
  • durationMs covers beforePushSend and the POST. The webhook timeout covers only the POST.
  • createLegacyAwarePushNotificationSender passes its options through, so it accepts plugins too. A sender you pass to DefaultRequestHandler yourself needs its own plugins, as in a2a-python.
  • With no push hooks registered, delivery is unchanged, except that the body is now serialized before the timeout starts.

@bartek-gralewicz
bartek-gralewicz requested a review from a team as a code owner November 18, 2026 14:13
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/server/push_notification/default_push_notification_sender.ts 94.11% 95.18% 🟢 +1.07%
src/server/store.ts 71.42% 73.8% 🟢 +2.38%
Total 85.21% 85.27% 🟢 +0.06%

Generated by coverage-comment.yml

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.

2 participants