Skip to content

feat: Add task plugin hooks for task store writes - #840

Merged
bartek-gralewicz merged 4 commits into
mainfrom
bgralewicz/task_event_hooks
Nov 20, 2026
Merged

bartek-gralewicz merged 4 commits into
mainfrom
bgralewicz/task_event_hooks

Conversation

@bartek-gralewicz

@bartek-gralewicz bartek-gralewicz commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Calls onTaskEvent from @a2a-js/sdk/plugins (#826) after every successful task write made by DefaultRequestHandler. The hook uses the same plugins option as the server hooks (#835).

const transitions: A2APlugin = {
  name: 'transitions',
  onTaskEvent: ({ taskId, fromState, toState }) => {
    if (fromState !== toState) console.log(taskId, fromState, '->', toState);
  },
};

Behavior

  • ResultManager saves the task, then calls onTaskEvent with the task, the event that caused the write, and the state stored before it:
    • a task event reports the stored state, or undefined when it creates the task;
    • a statusUpdate reports the stored state;
    • an artifactUpdate reports the same state as fromState and toState.
  • Nothing is reported when no write happens (message events, updates to terminal tasks, events for unknown tasks) or when the store write throws.
  • The handler passes its plugins to every ResultManager it creates: sendMessage, sendMessageStream, and both cancel paths. That includes the direct CANCELED write when no agent is running.
  • A follow-up message to an existing task appends it to the history and saves it directly. That write is reported with no event and an unchanged state.
  • onTaskEvent runs after the per-task write lock is released, so a hook may write to the same task, for example to cancel it, without deadlocking. The states in each report are captured inside the lock, so they match that write. Reports from one request arrive in write order. Reports from concurrent requests on the same task may interleave.
  • Errors thrown by onTaskEvent are logged and ignored.

ResultManager is public, so plugins is an optional third constructor argument and existing callers are unaffected. The fields match a2a-python's TaskEventInfo.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage

⬇️ Download Full Report

Base PR Delta
src/server/request_handler/default_request_handler.ts 86.93% 87.02% 🟢 +0.09%
src/server/result_manager.ts 85.29% 88.35% 🟢 +3.06%
Total 85.12% 85.21% 🟢 +0.09%

Generated by coverage-comment.yml

Comment thread src/server/result_manager.ts Resolved
@bartek-gralewicz
bartek-gralewicz merged commit ac275df into main Nov 20, 2026
19 checks passed
@bartek-gralewicz
bartek-gralewicz deleted the bgralewicz/task_event_hooks branch November 20, 2026 17:22
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