MediumAgentsPython 3

Webhook Idempotency Receiver

Handle retried provider events with delivery dedupe, logical idempotency keys, and repo policy checks.

35m2 sample tests4 hidden tests

Implement WebhookReceiver, an in-memory receiver for provider events that may be retried.

Requirements

  • Constructor receives allowed_repos, a set of "org/repo" strings.
  • handle(provider, delivery_id, event) returns a response dictionary.
  • A duplicate (provider, delivery_id) returns the original response.
  • Events must contain org, repo, and action.
  • If "org/repo" isn't allowed, return {"status": "blocked", "code": 403}.
  • For allowed events, create exactly one run for each logical key.
  • The logical key is provider:org/repo:action:number, where number is optional and defaults to empty string.
  • Return {"status": "created", "code": 202, "run_id": ...} for new runs and {"status": "duplicate", "code": 200, "run_id": ...} for duplicate logical work.

Example

python
1receiver = WebhookReceiver({"cursor/app"}) 2event = {"org": "cursor", "repo": "app", "action": "issue_comment", "number": 7} 3 4first = receiver.handle("github", "delivery-1", event) 5second = receiver.handle("github", "delivery-2", event) 6 7assert first["status"] == "created" 8assert second["status"] == "duplicate" 9assert first["run_id"] == second["run_id"]

Constraints

  • Keep it in memory.
  • Don't parse provider-specific payloads.
  • Preserve deterministic run IDs: run-1, run-2, and so on.

Editor