Page 3 of 8~112 min topic

Webhook lab

Implement one traceable happy path

One clean transaction through **POST /webhooks/batch-index** must match the oracle: valid event → 202 + one queue message; replay same event_id → 202 no duplicate work.

~14 min this pageVertical slice

1Try it yourself

Decision drill

Webhook lab

Webhooks push events — polling pulls. Verify signatures before acting.

Integration safety70%

1/3Nightly index job finished.

2Learn the idea

Read

Order the successful transaction

Code the narrow path that serves indexer worker waiting on provider batch.completed callbacks: accept → authorize/normalize → call dependency → validate → record. Keep stages named so a trace can show which boundary passed. Success must emit evidence useful to webhook_accept_total and duplicate_suppressed_total, not only a 200 with prose. Predict the observable for POST /webhooks/batch-index before running: valid event → 202 + one queue message; replay same event_id → 202 no duplicate work.

Read

Run with fakes first

Drive the path with recording fakes or local stubs. Assert call order and arguments. Idempotency keys or stable ids should keep retries from duplicating costly work where the product requires it. Product under test remains FastAPI receiver for batch-index completion events → durable queue — resist adding unrelated features mid-path.

Read

Implementation artifact

@app.post("/webhooks/batch-index", status_code=202)
def receive(request: Request, body: BatchCompleted):
    verify_sig(request); enqueue_once(body.event_id, body)
    return {"accepted": True}

Read

Compare prediction to result

For Webhook lab, paste the CLI/HTTP transcript beside your prediction for POST /webhooks/batch-index. If the oracle is unmet (valid event → 202 + one queue message; replay same event_id → 202 no duplicate work), stop and debug this page; do not compensate with prompt folktales. Re-run once after a clean process start to catch hidden global state that would invalidate HOOK-SIG-OFF-16.

Read

Stage depth

Performance sketch: measure local p95 for the fake-backed path so later regressions are obvious. Keep concurrency modest until failure-handling proves limits. Log a single structured event per success with request id, revision, and the evidence field behind webhook_accept_total and duplicate_suppressed_total. Avoid hidden global caches in the happy path unless the lab is about caching — and even then key by tenant. If the path calls a model, pin model id in config and echo it in the response for auditability. Remember indexer worker waiting on provider batch.completed callbacks experiences wall-clock time, not your debugger’s single-step comfort.

Read

Field notes for `webhook-lab` / `happy-path`

Prefer explicit function names over a single god-object handleRequest. Thread a correlation id from ingress to the last log line. When streaming, define what partial failure means before coding. Snapshot one successful response body in fixtures after redaction. If the path writes to a queue, assert message attributes in the fake. Stop adding retries on this page; that is the next concern. In this chapter the product is FastAPI receiver for batch-index completion events → durable queue, the human stakeholder is indexer worker waiting on provider batch.completed callbacks, and the incident id you design against is HOOK-SIG-OFF-16. Re-state the oracle in your notes — valid event → 202 + one queue message; replay same event_id → 202 no duplicate work — and keep the invariant visible: verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id. Track webhook_accept_total and duplicate_suppressed_total as the scoreboard. Surface under change control: POST /webhooks/batch-index. If you only have forty minutes, finish the fixture for signature optional in staging config accidentally shipped to prod before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.

Go deeper

Before you start

Why this matters

Without calling production, order the steps a single success takes for indexer worker waiting on provider batch.completed callbacks. Circle the first irreversible side effect. Your prediction should mention POST /webhooks/batch-index and the evidence field that proves valid event → 202 + one queue message; replay same event_id → 202 no duplicate work.

Check your understanding

Page assessment

Answer from memory. Completion is saved from this evidence, not from opening the next page.

1. Is call order asserted, not assumed?
2. Does success evidence support webhook_accept_total and duplicate_suppressed_total?
3. Did you compare prediction vs transcript?

All responses are required.