Skip to content

feat: deduplicate A2A message processing - #78

Closed
murilloimparavel wants to merge 1 commit into
evolution-foundation:mainfrom
murilloimparavel:codex/audio-multimodal-processor
Closed

murilloimparavel wants to merge 1 commit into
evolution-foundation:mainfrom
murilloimparavel:codex/audio-multimodal-processor

Conversation

@murilloimparavel

@murilloimparavel murilloimparavel commented Sep 30, 2026 •

Copy link
Copy Markdown

Summary\n- Persist idempotency claims and completed A2A responses keyed by agent, conversation, and stable message ID.\n- Reject conflicting payload reuse and concurrent duplicates; avoid replaying expired executions with possible external side effects.\n- Add migration and focused unit/integration coverage.\n\n## Validation\n- Targeted pytest: 13 passed.\n\nMerge this before the matching runtime PR so its retry handling can use the in-progress conflict response. No deployment is included.

Summary by Sourcery

Deduplicate retryable A2A message processing with durable claims and safe response replay.

New Features:

  • Add durable A2A message idempotency with completed-response replay keyed by agent, conversation, and stable message identifiers.
  • Return explicit responses for duplicate, conflicting, in-progress, expired, and unavailable idempotency states.

Bug Fixes:

  • Prevent repeated execution of potentially side-effecting A2A requests after processing leases expire.
  • Reject reuse of an idempotency key with a different request payload.

Enhancements:

  • Validate A2A context and idempotency key lengths and avoid exposing message contents in routine logs or persisted fingerprints.

Tests:

  • Add focused unit and integration coverage for idempotency claims, replay, conflicts, expiry handling, completion, and release.

@sourcery-ai

sourcery-ai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces durable, fail-closed A2A idempotency keyed by agent, conversation, and stable message identity, with request fingerprint validation, cached response replay, explicit duplicate/conflict/expired outcomes, and integration tests plus a database migration.

Sequence diagram for durable A2A message deduplication

sequenceDiagram
    participant Client
    participant A2ARoute as handle_message_send
    participant Idempotency as a2a_idempotency
    participant Database
    participant Agent as run_agent

    Client->>A2ARoute: message/send with idempotencyKey
    A2ARoute->>Idempotency: request_fingerprint(params)
    A2ARoute->>Idempotency: claim_or_replay(...)
    Idempotency->>Database: insert processing claim
    alt owner
        Idempotency-->>A2ARoute: owner
        A2ARoute->>Agent: run_agent(...)
        Agent-->>A2ARoute: task response
        A2ARoute->>Idempotency: complete(..., response)
        Idempotency->>Database: store completed response
        A2ARoute-->>Client: task response
    else completed duplicate
        Idempotency-->>A2ARoute: replay, cached response
        A2ARoute-->>Client: cached response
    else conflicting payload
        Idempotency-->>A2ARoute: conflict
        A2ARoute-->>Client: 409 payload mismatch
    else concurrent duplicate
        Idempotency-->>A2ARoute: in_progress
        A2ARoute-->>Client: 409 retry shortly
    else expired processing claim
        Idempotency-->>A2ARoute: expired
        A2ARoute-->>Client: 409 operator review required
    end
Loading

Entity relationship diagram for A2A idempotency records

erDiagram
    A2A_IDEMPOTENCY_RECORDS {
        uuid id PK
        uuid agent_id
        string context_id
        string idempotency_key
        string request_hash
        string state
        json response
        datetime created_at
        datetime updated_at
    }

    AGENT ||--o{ A2A_IDEMPOTENCY_RECORDS : owns
    CONVERSATION ||--o{ A2A_IDEMPOTENCY_RECORDS : scopes
Loading

File-Level Changes

Change Details Files
Add a durable PostgreSQL-backed idempotency state machine for A2A message requests.
  • Persist processing claims and completed task responses under an agent/conversation/key uniqueness constraint.
  • Canonicalize all JSON-RPC parameters into a SHA-256 fingerprint without storing raw request content.
  • Return replay, payload-conflict, in-progress, and expired-lease outcomes; prevent automatic re-execution after stale processing claims.
  • Add bounded opportunistic retention cleanup and release transient claims before agent execution begins.
migrations/versions/20260929090000_a2a_message_idempotency.py
src/models/models.py
src/services/a2a_idempotency.py
Integrate idempotency claims and response caching into message/send handling.
  • Use idempotencyKey or stable messageId for CRM requests while preserving legacy behavior for uncached requests and push notifications.
  • Fail closed with service-unavailable responses when idempotency storage cannot establish protection.
  • Complete claims only after task response creation, and release claims for cancellations or failures before execution starts.
  • Validate context and key lengths and reduce sensitive/high-volume logging.
src/api/a2a_routes.py
Cover persistence and route behavior with focused tests.
  • Test ownership, replay, payload mismatch, concurrent processing, expired leases, completion, and release semantics.
  • Update response-pipeline coverage for the new claim integration.
tests/unit/test_a2a_idempotency.py
tests/integration/test_response_pipeline.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. This changes whether agent execution occurs and persists task responses for up to 24 hours; a wrong key or fingerprint could suppress a legitimate execution or replay an incorrect response, while external tool side effects from duplicate or skipped processing cannot be undone by reverting. The scope is bounded and future behavior can be restored by reverting, but records and any already-triggered effects outlive the revert.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@murilloimparavel

Copy link
Copy Markdown
Author

Closing: this change is intended for the author's personal fork, not the evolution-foundation upstream. No merge performed.

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.

1 participant