Commit 73a7512
feat(decisioning): WebhookDeliverySupervisor + SQLAlchemy A2A stores example (#348)
* feat(decisioning): add WebhookDeliverySupervisor + SQLAlchemy A2A stores example
Round-2 P1 reliability layer for F12 sync-completion webhooks. The
existing WebhookSender is the transport (HTTP-Signatures POST, one
attempt, no retry); production sellers wrap it with retry, circuit
breaker, and per-attempt audit. This adds the SDK-side seam.
Tracks adopter feedback that salesagent's webhook reliability layer
(~1,041 LOC across webhook_delivery_service.py + protocol_webhook_service.py)
has no SDK home. After this PR, those LOC compose against the Protocol
seam instead of being adopter-rolled.
Components in src/adcp/webhook_supervisor.py:
* WebhookDeliverySupervisor Protocol — async send_mcp surface,
Protocol-conformant; adopters with infra-side retry (Celery, Kafka,
durable outbox) implement against their queue.
* InMemoryWebhookDeliverySupervisor reference impl — wraps a
WebhookSender with per-endpoint CircuitBreaker (CLOSED/OPEN/HALF_OPEN
state machine, 5-failure threshold, 60s recovery), exponential-
backoff RetryPolicy with jitter, per-sequence_key monotonic counter
for delivery-report sequence numbers, optional DeliveryLogSink
Protocol for BYO persistence.
* DeliveryAttempt frozen dataclass — one record per attempt
(success / failure / circuit_open) for audit-log persistence.
* DeliveryLogSink Protocol — adopters wire sinks to their existing
webhook_delivery_log tables; sink failures swallowed (broken sink
must not cascade into delivery loss).
Wire-through:
* PlatformHandler accepts webhook_supervisor=; F12 auto-emit routes
through supervisor when configured, falls back to bare sender
otherwise. Backward-compat: existing webhook_sender= path unchanged.
* serve() and create_adcp_server_from_platform() forward the new
param. Boot-time validate_webhook_sender_for_platform now accepts
either a sender or a supervisor (changed missing-sender error code
from "webhook_sender" to "webhook_sender_or_supervisor").
A2A stores example: examples/a2a_sqlalchemy_tasks.py. Companion to
the SQLite reference (examples/a2a_db_tasks.py). Same Protocol
surface (TaskStore + PushNotificationConfigStore) backed by
SQLAlchemy ORM so the same code runs against any backend SQLA
supports — SQLite for the demo, Postgres / MySQL in production.
Salesagent and other SQLAlchemy-based sellers wrap their existing
models behind the Protocols.
Tests: 22 new in test_webhook_supervisor.py (retry math, circuit
breaker state machine, supervisor success/retry/exception paths,
sink failure isolation, F12 wire-through, boot-validation).
Existing F12 + serve tests updated for the supervisor parameter.
79 affected tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(decisioning): address expert review on PR #348 — idempotency, breaker_key, sink timeout
Ten findings from four expert reviews on the WebhookDeliverySupervisor:
**Critical (spec compliance):**
- Idempotency-key reuse on retry — spec requires reusing the same key
on every retry. Refactored to use sender.resend(last_result) for
attempts 2+; only attempt 1 (or after exception with no result) calls
send_mcp fresh.
**High:**
- Cross-tenant breaker collision — added optional breaker_key parameter;
multi-tenant sellers scope via f"{tenant_id}:{url}".
- Sink unbounded on hot path — wrapped in asyncio.wait_for with
configurable RetryPolicy.sink_timeout_seconds (default 5s).
- Sequence number burned on circuit-open — allocated only after
can_attempt() returns True.
- InMemoryWebhookDeliverySupervisor.__init__ now raises ValueError when
sender is None (preserves F12 boot fail-fast).
- UTC = timezone.utc moved below all imports for ruff isort compliance.
**Medium:**
- response_time_ms switched from datetime deltas to time.monotonic().
- record_success while OPEN now warns + transitions to HALF_OPEN with
success_count=1 (was silently flipping to CLOSED).
- DeliveryAttempt.notification_type new optional field for delivery
reports parity with salesagent's WebhookDeliveryLog.
- sequence_key docstring clarified per-stream recommendation
(f"{media_buy_id}:{url}").
Tests: 30 (up from 22). 8 new tests cover idempotency-key reuse via
resend, breaker_key tenant isolation, sequence-number no-burn on
circuit-open, sink timeout, notification_type passthrough, monotonic
clock, init-time None-sender rejection, sender-only backward-compat.
2,990 total tests pass. ruff + mypy clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a016eca commit 73a7512
8 files changed
Lines changed: 1916 additions & 28 deletions
File tree
- examples
- src/adcp
- decisioning
- tests
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
465 | 466 | | |
466 | 467 | | |
467 | 468 | | |
| 469 | + | |
468 | 470 | | |
469 | 471 | | |
470 | 472 | | |
| |||
474 | 476 | | |
475 | 477 | | |
476 | 478 | | |
| 479 | + | |
477 | 480 | | |
478 | 481 | | |
479 | 482 | | |
| |||
569 | 572 | | |
570 | 573 | | |
571 | 574 | | |
| 575 | + | |
572 | 576 | | |
573 | 577 | | |
574 | 578 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| 81 | + | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| |||
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
130 | 143 | | |
131 | 144 | | |
132 | 145 | | |
| |||
235 | 248 | | |
236 | 249 | | |
237 | 250 | | |
| 251 | + | |
238 | 252 | | |
239 | 253 | | |
240 | 254 | | |
| |||
255 | 269 | | |
256 | 270 | | |
257 | 271 | | |
| 272 | + | |
258 | 273 | | |
259 | 274 | | |
260 | 275 | | |
| |||
271 | 286 | | |
272 | 287 | | |
273 | 288 | | |
| 289 | + | |
274 | 290 | | |
275 | 291 | | |
276 | 292 | | |
| |||
294 | 310 | | |
295 | 311 | | |
296 | 312 | | |
297 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
298 | 322 | | |
299 | 323 | | |
300 | 324 | | |
| |||
322 | 346 | | |
323 | 347 | | |
324 | 348 | | |
| 349 | + | |
325 | 350 | | |
326 | 351 | | |
327 | 352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
128 | | - | |
| 131 | + | |
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| |||
139 | 142 | | |
140 | 143 | | |
141 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
145 | | - | |
| 153 | + | |
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| |||
169 | 177 | | |
170 | 178 | | |
171 | 179 | | |
| 180 | + | |
172 | 181 | | |
173 | 182 | | |
174 | 183 | | |
| |||
217 | 226 | | |
218 | 227 | | |
219 | 228 | | |
220 | | - | |
| 229 | + | |
| 230 | + | |
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
| |||
237 | 247 | | |
238 | 248 | | |
239 | 249 | | |
240 | | - | |
241 | | - | |
| 250 | + | |
| 251 | + | |
242 | 252 | | |
243 | 253 | | |
244 | 254 | | |
| |||
279 | 289 | | |
280 | 290 | | |
281 | 291 | | |
282 | | - | |
| 292 | + | |
283 | 293 | | |
284 | 294 | | |
285 | 295 | | |
| |||
307 | 317 | | |
308 | 318 | | |
309 | 319 | | |
| 320 | + | |
310 | 321 | | |
311 | 322 | | |
312 | 323 | | |
313 | 324 | | |
314 | 325 | | |
315 | 326 | | |
316 | 327 | | |
317 | | - | |
318 | | - | |
319 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
320 | 331 | | |
321 | 332 | | |
322 | 333 | | |
| |||
335 | 346 | | |
336 | 347 | | |
337 | 348 | | |
338 | | - | |
| 349 | + | |
339 | 350 | | |
340 | 351 | | |
341 | 352 | | |
| |||
347 | 358 | | |
348 | 359 | | |
349 | 360 | | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
358 | 370 | | |
359 | 371 | | |
360 | 372 | | |
361 | | - | |
| 373 | + | |
362 | 374 | | |
363 | 375 | | |
364 | 376 | | |
| |||
0 commit comments