Fix duplicate terminal callbacks in SSE listeners · Issue #1170 · a2aproject/a2a-java · GitHub
Skip to content

Fix duplicate terminal callbacks in SSE listeners #1170

Closed

Description

@kabir

Problem

The JSON-RPC SSE listeners use a volatile completed flag with non-atomic check-and-set behavior. onComplete(), onError(), parsing failures, and final-event cancellation can race or occur in close succession, allowing the error consumer to be invoked more than once (including a null completion signal after an error/cancellation).

The native JSON-RPC listener has the same lifecycle pattern, and the 0.3 compatibility JSON-RPC listener mirrors it. This should be addressed consistently, rather than patched only in the compatibility adapter.

Expected behavior

For one streaming request, deliver exactly one terminal callback to the error/completion consumer: either one non-null failure or one null normal-completion signal. A final task/status event that cancels the stream must not allow a later terminal callback to duplicate or contradict that outcome.

Suggested direction

Define the terminal-state contract for the native JSON-RPC and 0.3 JSON-RPC SSE listeners, then guard every terminal path with one shared atomic transition (for example, AtomicBoolean.compareAndSet(false, true)). Cover concurrent or repeated completion/error notifications and cancellation after a final event. Evaluate REST separately: its native and 0.3 implementations currently both use a no-op completion callback, so changing that is an API decision rather than a compat-only fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions