Skip to content

bug(webhooks): PgWebhookDeliverySupervisor never sends a task webhook (status_str holds the task status) #1606

Closed

Description

@bokelley

Summary

PgWebhookDeliverySupervisor never sends a task webhook. send_mcp stores the task's status (completed, failed, ...) in the queue's status_str column, but the worker only claims rows whose status_str is pending or retry. Every job enqueued through send_mcp with a real task status stays in the queue unsent.

Reproduction (adcp 9.0.0b4 and 9.1.0; webhook_supervisor_pg.py is identical in both)

# DATABASE_URL=postgresql://... uv run --no-project --with 'adcp[pg]==9.1.0' python repro_b1.py
import asyncio
import os

from cryptography.hazmat.primitives.asymmetric import ed25519
from psycopg_pool import AsyncConnectionPool

from adcp.webhook_sender import WebhookSender
from adcp.webhook_supervisor_pg import PgWebhookDeliverySupervisor


async def main() -> None:
    pool = AsyncConnectionPool(os.environ["DATABASE_URL"], open=False)
    await pool.open()
    sender = WebhookSender(private_key=ed25519.Ed25519PrivateKey.generate(), key_id="k1", alg="ed25519")
    supervisor = PgWebhookDeliverySupervisor(pool, sender)
    await supervisor.create_schema()
    await supervisor.send_mcp(
        url="https://buyer.example/hook",
        task_id="task_1",
        status="completed",
        task_type="create_media_buy",
        result={"media_buy_id": "mb_1"},
        operation_id="op_1",
    )
    async with pool.connection() as conn:
        rows = await (await conn.execute("SELECT id, status_str FROM adcp_webhook_delivery_queue")).fetchall()
    print("queued rows:", rows)
    print("worker picked a job:", await supervisor._poll_and_process())
    await pool.close()


asyncio.run(main())
queued rows: [(1, 'completed')]
worker picked a job: False

Where

  • adcp/webhook_supervisor_pg.py, send_mcp: status_str = status if isinstance(status, str) else str(status) is written into status_str by _sql_enqueue.
  • _sql_poll: WHERE status_str IN ('pending', 'retry') AND scheduled_at <= now().
  • _poll_and_process, exception-retry branch: when sent_body is empty it calls send_mcp(status=status_str, ...). After one reschedule status_str is 'retry', so even a job that was claimed would be re-sent with status: "retry", which is not a task status.

The column is doing two jobs: the queue state and the task status. Splitting it (for example a queue_state column for pending/retry, and task_status for the payload) fixes both.

Also worth deciding

  • The supervisor takes one fixed WebhookSender, so a multi-tenant seller cannot sign per tenant. PgNotificationOutbox and PgTaskWebhookOutbox take a sender_resolver.
  • task_webhook_owner_ready already refuses configurations that wire a supervisor, and the module docstring says it does not meet the AdCP 3.2 retry-horizon contract. If PgNotificationOutbox / PgTaskWebhookOutbox are the durable path, deprecating PgWebhookDeliverySupervisor (with a pointer to them) may be better than fixing it.

Why an adopter hits this

The Embedded Sales Agent's target shape names webhook_supervisor_pg as its webhook path (scope3data/agentic-api docs/spec/sales-agents/embedded-sales-agent.md, "SDK first"). Moving onto it as shipped would silently stop every task webhook, so the ESA is moving onto PgNotificationOutbox instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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