Guides
Webhooks and provider actions
Your code registers webhook endpoints through the vendor’s own API, as it does in production. The simulator records every event it would send and, when you turn delivery on, POSTs each one to your receiver, signed the way the vendor signs it. Provider actions cause the events only the provider can: a dispute, a bounce, a USPS scan.
Which simulators send what
Each simulator’s page says what it sends, what its egress log records, how to register a receiver and whether it retries. These simulators deliver to your receiver:
| Simulator | Delivers to | Turned on by | Retries |
|---|---|---|---|
| Slack | Socket Mode connections | its boot variables | yes |
| Slack | one URL set at boot | its boot variables | yes |
| GitHub | endpoints registered through its API | RYSTIC_WEBHOOK_DELIVERY=on | no |
| Linear | endpoints registered through its API | RYSTIC_WEBHOOK_DELIVERY=on | yes |
| Stripe | endpoints registered through its API | RYSTIC_WEBHOOK_DELIVERY=on | yes |
| Resend | endpoints registered through its API | RYSTIC_WEBHOOK_DELIVERY=on | no |
| Clerk | one URL set at boot | its boot variables | no |
| Dropbox | one URL set with POST /_rystic/webhooks | RYSTIC_WEBHOOK_DELIVERY=on | yes |
| Shopify | one URL set with POST /_rystic/webhooks | RYSTIC_WEBHOOK_DELIVERY=on | yes |
A simulator turned on by its boot variables needs the URL or mode they name; its page lists them. Every other simulator delivers nothing; its page says what its egress log records.
Receive signed webhooks
- A receiver the table turns on by
RYSTIC_WEBHOOK_DELIVERY=ongets nothing without it (rystic run … --env RYSTIC_WEBHOOK_DELIVERY=on). Boot configuration lists its other values.rystic compose upsets it toonfor every simulator it starts; to turn delivery off for one, setenv: {RYSTIC_WEBHOOK_DELIVERY: "off"}on that service inrystic.yaml. - Each event goes to every enabled endpoint whose event list names it, signed with that endpoint’s own secret. A disabled endpoint receives nothing.
- A receiver set at boot, or with
POST /_rystic/webhooks, is one URL for every event: the simulator’s page has the variables. - Instead of registering through the API, a boot seed file can declare the endpoint, signing with the secret your app already holds:
"secret": {"$env": "STRIPE_WEBHOOK_SECRET"}. With delivery on, an enabled seeded endpoint without an absolute URL or a usable secret stops the simulator at startup.
The simulator signs with the vendor’s own headers and scheme, so verify each delivery as your production receiver does, with the vendor’s library where it ships a verifier. Where the vendor ships none, the simulator’s page gives the signature to check.
Run a receiver
A receiver for Stripe and Resend, in Python:
python3 -m venv .venv && . .venv/bin/activate
pip install stripe svix
# receiver.py: verifies each delivery with the vendor's own library
import json, os
from http.server import BaseHTTPRequestHandler, HTTPServer
import stripe
from svix.webhooks import Webhook
class Receiver(BaseHTTPRequestHandler):
def do_POST(self):
body = self.rfile.read(int(self.headers["Content-Length"]))
try:
if self.path == "/stripe":
event = stripe.Webhook.construct_event(
body, self.headers["Stripe-Signature"], os.environ["STRIPE_WEBHOOK_SECRET"])
else: # /resend
Webhook(os.environ["RESEND_WEBHOOK_SECRET"]).verify(body, dict(self.headers))
event = json.loads(body)
except Exception as e:
print("rejected", self.path, e, flush=True)
self.send_response(400)
else:
print("verified", self.path, event["type"], flush=True)
self.send_response(200)
self.end_headers()
def log_message(self, *args):
pass
HTTPServer(("127.0.0.1", 4242), Receiver).serve_forever()
Start both simulators with delivery on:
rystic pull stripe-twin && rystic pull resend-twin
STRIPE=$(rystic run stripe-twin -d --name stripe-hooks --port 0 --env RYSTIC_WEBHOOK_DELIVERY=on --json | jq -r .data.port)
RESEND=$(rystic run resend-twin -d --name resend-hooks --port 0 --env RYSTIC_WEBHOOK_DELIVERY=on --json | jq -r .data.port)
Register an endpoint on each through the vendor’s API, keep the secrets, then start the receiver:
export STRIPE_WEBHOOK_SECRET=$(curl -s localhost:$STRIPE/v1/webhook_endpoints -u sk_test_twin: \
-d url=http://127.0.0.1:4242/stripe \
-d 'enabled_events[]=charge.succeeded' -d 'enabled_events[]=charge.dispute.created' | jq -r .secret)
echo $STRIPE_WEBHOOK_SECRET
# -> whsec_gHGhSZXLpsl6MSRz5ujbOwJ4dgqfh438
export RESEND_WEBHOOK_SECRET=$(curl -s localhost:$RESEND/webhooks -H 'Authorization: Bearer re_test' \
-H 'Content-Type: application/json' \
-d '{"endpoint":"http://127.0.0.1:4242/resend","events":["email.sent","email.bounced"]}' | jq -r .signing_secret)
echo $RESEND_WEBHOOK_SECRET
# -> whsec_f886911f8d6c49918000000000000001
python3 receiver.py & RECEIVER=$!
Each secret is derived the same way every run, so a fresh simulator hands out the same ones. Charge a card on Stripe and send to Resend’s sandbox bounce address:
curl -s localhost:$STRIPE/v1/charges -u sk_test_twin: \
-d amount=2000 -d currency=usd -d source=tok_visa > /dev/null
curl -s localhost:$RESEND/emails -H 'Authorization: Bearer re_test' -H 'Content-Type: application/json' \
-d '{"from":"Acme <onboarding@resend.dev>","to":["bounced@resend.dev"],"subject":"Receipt","html":"<p>Thanks</p>"}' > /dev/null
# receiver: verified /stripe charge.succeeded
# verified /resend email.sent
# verified /resend email.bounced
Which receivers a simulator may reach
A simulator delivers to a receiver at a public address. It refuses a loopback (127.0.0.0/8, ::1), link-local (169.254.0.0/16, fe80::/10), private (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7), shared (100.64.0.0/10) or unspecified (0.0.0.0/8, ::) address unless RYSTIC_WEBHOOK_ALLOW allows it. That boot variable is a comma-separated list. Each entry is a CIDR range, or a host name or IP address with an optional :port: localhost, 127.0.0.1:4242, app, host.docker.internal, 10.0.0.0/8. No request changes it.
rystic runon your machine, listening on127.0.0.1, sets it tolocalhost,127.0.0.0/8,::1, so the receiver above needs nothing more. A value you set, exported or with--env, replaces it.--bind 0.0.0.0, the Docker runner and a container get no default.rystic composesets it to the names of the services in your Compose files, andrystic gridtolocalhost,127.0.0.0/8,::1.- From Docker, a receiver on your machine is at
host.docker.internal, a private address the simulator reaches only withRYSTIC_WEBHOOK_ALLOW=host.docker.internal. - A refused attempt is
failedwithreasondestination_refused, and is retried as an unreachable receiver is. The simulator’s log names the setting that would allow it, and the action log records each destination.
rystic run -d prints the list in effect. Here an endpoint names the cloud metadata address, which nothing allows, and Stripe’s first retry comes due 30 minutes later on the simulator’s clock:
rystic run stripe-twin -d --name refused --port 8098 --env RYSTIC_WEBHOOK_DELIVERY=on \
--env RYSTIC_ACTION_LOG=$PWD/deliveries.jsonl 2>&1 >/dev/null | grep '^rystic: webhooks:'
# -> rystic: webhooks: public addresses and localhost,127.0.0.0/8,::1, the default for a loopback bind (RYSTIC_WEBHOOK_ALLOW replaces it)
curl -s localhost:8098/v1/webhook_endpoints -u sk_test_twin: \
-d url=http://169.254.169.254/latest/meta-data -d 'enabled_events[]=charge.succeeded' > /dev/null
curl -s localhost:8098/v1/charges -u sk_test_twin: -d amount=2000 -d currency=usd -d source=tok_visa > /dev/null
rystic settle refused > /dev/null
curl -s localhost:8098/_rystic/egress | jq -c '.delivery.results[]'
# -> {"generation":0,"seq":1,"endpoint":"we_0000000000000001","status":"failed","attempt":0,"reason":"destination_refused"}
curl -s -X POST localhost:8098/_rystic/clock -d '{"advance_seconds":1800}'
rystic settle refused > /dev/null
curl -s localhost:8098/_rystic/egress | jq -c '.delivery.results[] | {attempt, status, reason}'
# -> {"attempt":0,"status":"failed","reason":"destination_refused"}
# -> {"attempt":1,"status":"failed","reason":"destination_refused"}
rystic logs refused | grep -o 'rystic: delivery to .*'
# -> rystic: delivery to 169.254.169.254:80 refused: 169.254.169.254 is link-local and RYSTIC_WEBHOOK_ALLOW does not name it; boot with RYSTIC_WEBHOOK_ALLOW=169.254.169.254 to allow it
jq -c 'select(.kind == "delivery") | .data' deliveries.jsonl
# -> {"address":"169.254.169.254:80","attempt":0,"destination":"http://169.254.169.254","endpoint":"we_0000000000000001","reason":"destination_refused","refused":true,"seq":1,"status":"failed"}
# -> {"address":"169.254.169.254:80","attempt":1,"destination":"http://169.254.169.254","endpoint":"we_0000000000000001","reason":"destination_refused","refused":true,"seq":1,"status":"failed"}
rystic stop refused
A Stripe container on Docker Desktop reaches the receiver above at host.docker.internal, which a plain container refuses:
docker run -d --name stripe-docker -p 127.0.0.1:8096:8080 -e RYSTIC_TOKEN -e RYSTIC_WEBHOOK_DELIVERY=on \
registry.rystic.ai/stripe-twin:0.0.36 > /dev/null
until curl -sf -o /dev/null localhost:8096/_rystic/version; do sleep 1; done
curl -s localhost:8096/v1/webhook_endpoints -u sk_test_twin: \
-d url=http://host.docker.internal:4242/stripe -d 'enabled_events[]=charge.succeeded' > /dev/null
curl -s localhost:8096/v1/charges -u sk_test_twin: -d amount=2000 -d currency=usd -d source=tok_visa > /dev/null
curl -s localhost:8096/_rystic/settle > /dev/null
docker logs stripe-docker 2>&1 | grep -o 'rystic: delivery to .*'
# -> rystic: delivery to host.docker.internal:4242 refused: ... is private and RYSTIC_WEBHOOK_ALLOW does not name it; boot with RYSTIC_WEBHOOK_ALLOW=host.docker.internal to allow it
docker rm -f stripe-docker > /dev/null
Started with the setting the log names, the same calls reach the receiver:
docker run -d --name stripe-docker -p 127.0.0.1:8096:8080 -e RYSTIC_TOKEN -e RYSTIC_WEBHOOK_DELIVERY=on \
-e RYSTIC_WEBHOOK_ALLOW=host.docker.internal registry.rystic.ai/stripe-twin:0.0.36 > /dev/null
until curl -sf -o /dev/null localhost:8096/_rystic/version; do sleep 1; done
curl -s localhost:8096/v1/webhook_endpoints -u sk_test_twin: \
-d url=http://host.docker.internal:4242/stripe -d 'enabled_events[]=charge.succeeded' > /dev/null
curl -s localhost:8096/v1/charges -u sk_test_twin: -d amount=2000 -d currency=usd -d source=tok_visa > /dev/null
# receiver: verified /stripe charge.succeeded
docker rm -f stripe-docker > /dev/null
Start the simulators before your app
Simulators that start before your app would send their first webhooks to a receiver that isn’t listening yet. RYSTIC_WEBHOOK_HOLD_UNTIL holds them:
- Set it to your app’s health URL, such as
http://app:3000/health. The simulator holds every webhook, in order and unsent, until that URL first returns2xx, then sends each once. - With
RYSTIC_SEED_EVENTS=on, the records a boot seed creates send their webhooks too, a record after the records it names, so the users and organizations it declares arrive once your app listens. releaseinstead of a URL holds them untilPOST /_rystic/webhook-holdwith{"release": true}.- A hold sends what it holds after
RYSTIC_WEBHOOK_HOLD_TIMEOUT(10m) anyway;0waits forever.
rystic compose sets RYSTIC_SEED_EVENTS=on for a simulator with a seed file and, when it wires an app, RYSTIC_WEBHOOK_HOLD_UNTIL=release; its rystic-hold service releases the hold once your services are up: Seeds.
What a delivery does
- Retries as the table says. A receiver that retries does so on the simulator’s own schedule, which its page gives. Any other sends one POST per event and never retries it.
- Outside the request. Deliveries go out in event order after the API has responded; a failed delivery never undoes the write or changes the response.
- Recorded on the egress log. Under delivery,
GET /_rystic/egressadds a top-leveldeliveryobject, besideevents, with one row per attempt:
curl -s localhost:$STRIPE/_rystic/egress | jq -c '.delivery.results[]'
# -> {"generation":0,"seq":1,"endpoint":"we_0000000000000001","status":"delivered","http_status":200,"attempt":0}
-
seqis the event’s egressseq;endpointis the registered endpoint’s id (a receiver set as one URL leaves it out). -
statussays how the attempt ended. Treat any status butdeliveredas a failure:statusMeans deliveredthe receiver returned a 2xx failedit returned another status, or could not be reached (no http_status)queue_fullnever sent: the queue is at its limit invalid_endpointnever sent: the URL is not a valid target, the destination is unknown or signing failed retries_fullnever sent: no room to schedule a retry prepare_failed,request_too_large,invalid_requestnever sent endpoint_deleted,endpoint_disableda queued retry whose endpoint was deleted or disabled before it went out -
attemptis0for an event’s first attempt and counts up on each retry. Afailedrow’sreasonistimeout,connection_failed,tls_error,http_errorordestination_refused(Which receivers a simulator may reach). -
A copy that
/_rystic/duplicate-deliverysends is markedduplicateand never retried. -
pendingcounts deliveries queued or waiting out a retry delay, andin_flightistruewhile one is being sent.GET /_rystic/settle, orrystic settle <name>, waits until no delivery is queued, in flight or due and your app has gone quiet; assert onresultsafter it. Settle lists a retry due later underscheduledand does not wait for it. -
Without delivery on, the response has no
deliverykey.
A reset wipes endpoints registered through the vendor’s API and clears delivery, so register again after one. A URL set with POST /_rystic/webhooks stays (What reset does).
Test a stale signature
A signature’s timestamp is wall-clock time, not the simulator’s clock, so the vendor’s verifier accepts a delivery wherever the clock stands. wall_offset_seconds on /_rystic/clock shifts that timestamp, so you can check that your receiver refuses an old delivery. A positive offset matches a receiver whose clock you moved forward. 0 or a reset puts it back.
The offset applies to the whole simulator process, not to one endpoint. It reaches webhook deliveries, except a receiver whose simulator’s page says it signs on the wall clock. It also shifts the time the simulator checks incoming signatures and presigned URLs against, so a signature skew check and a URL expiry follow it too.
curl -s -X POST localhost:$STRIPE/_rystic/clock -d '{"wall_offset_seconds":-600}'
curl -s localhost:$STRIPE/v1/charges -u sk_test_twin: \
-d amount=500 -d currency=usd -d source=tok_visa > /dev/null
# receiver: rejected /stripe Timestamp outside the tolerance zone (…)
curl -s localhost:$STRIPE/_rystic/egress | jq -c '.delivery.results[-1]'
# -> {"generation":0,"seq":2,"endpoint":"we_0000000000000001","status":"failed","http_status":400}
curl -s -X POST localhost:$STRIPE/_rystic/clock -d '{"wall_offset_seconds":0}'
Run webhook agents in parallel
rystic grid runs one agent per grid cell, each against its own simulator. Every cell’s simulator delivers webhooks (--webhooks=false turns delivery off in every cell), and every cell’s agent gets a loopback port no other cell holds, as $PORT and {{port}}. An agent that listens on $PORT and registers its endpoint there receives only its own cell’s events:
rystic grid github-pulls-twin -j 5 \
-worlds github-pulls_open_queue,github-pulls_bot_pr_broken,github-pulls_bot_pr_queue,github-pulls_checks_red,github-pulls_issue_tracker \
-- python3 agent.py
Each cell’s simulator may deliver to loopback, as its log in the -out folder shows:
rystic grid stripe-twin -worlds design_studio -out cells -- true > /dev/null
grep -ho 'webhook delivery: .*' cells/*/logs/*.twin.log
# -> webhook delivery: public addresses and RYSTIC_WEBHOOK_ALLOW=localhost,127.0.0.0/8,::1
Assert without a receiver: the egress log
GET /_rystic/egress lists every event a simulator would send, in order, whether or not delivery is on and whether or not an endpoint is registered. An event’s payload is the body its delivery carries. A URL in it on the vendor’s hosts, such as a Stripe charge’s receipt_url, names the origin you read the log on; ?raw=1 keeps the vendor’s host.
curl -s localhost:$RESEND/_rystic/egress | jq -r '.events[] | "\(.seq) \(.type)"'
# -> 1 smtp-delivery/bounced@resend.dev
# -> 2 email.sent
# -> 3 email.bounced
Provider actions
Each provider action is a control route on the simulator; send its body as JSON. Any event it emits goes to the egress log and to every receiver subscribed to it, like any other.
| Simulator | Call | What changes | Event |
|---|---|---|---|
| Stripe | POST /_dispute {"charge":"ch_…","reason"?,"amount"?} | the charge reads disputed: true; a refund returns 400 charge_disputed | charge.dispute.created, carrying a needs_response Dispute |
| Resend | POST /_bounce {"email_id":"…","subType"?,"message"?,"diagnosticCode"?} | an email that has gone out reads last_event: "bounced" with its bounce | email.bounced |
| Lob | POST /_tracking_event {"postcard":"psc_…","name":"In Transit","location"?,"time"?} | a USPS scan joins the postcard’s tracking_events | none: Lob sends no webhooks |
| Kalshi | POST /_settle {"ticker":"…","result":"yes"} | the market settles | market_lifecycle_v2 frames |
Each route’s page lists its errors.
Dispute the charge from Run a receiver, and bounce an email to an ordinary address:
curl -s -X POST localhost:$STRIPE/_dispute -H 'Content-Type: application/json' \
-d '{"charge":"ch_000000000000000000000001","reason":"product_not_received"}' | jq -c '{id, status, reason}'
# -> {"id":"du_000000000000000000000001","status":"needs_response","reason":"product_not_received"}
# receiver: verified /stripe charge.dispute.created
ID=$(curl -s localhost:$RESEND/emails -H 'Authorization: Bearer re_test' -H 'Content-Type: application/json' \
-d '{"from":"Acme <onboarding@resend.dev>","to":["ada@example.com"],"subject":"Receipt","html":"<p>Thanks</p>"}' | jq -r .id)
curl -s -X POST localhost:$RESEND/_bounce -H 'Content-Type: application/json' \
-d "{\"email_id\":\"$ID\",\"subType\":\"NoEmail\"}" | jq -c '{last_event, subType: .bounce.subType}'
# -> {"last_event":"bounced","subType":"NoEmail"}
# receiver: verified /resend email.sent
# verified /resend email.bounced
Schedule events on a timeline
A timeline fires calls on the simulator’s clock, provider actions included; Timelines has the mechanism. A provider action is a call to its route with no as. Charge a card a minute in and dispute it three days later, binding the charge id as ${ch}:
printf '%s\n' '{"events": [' \
' {"id": "charge", "at": "+1m",' \
' "call": {"method": "POST", "path": "/v1/charges",' \
' "body": {"amount": 4200, "currency": "usd", "source": "tok_visa"}},' \
' "bind": {"ch": "/id"}},' \
' {"id": "dispute", "at": "+72h",' \
' "call": {"method": "POST", "path": "/_dispute", "body": {"charge": "${ch}"}}}' \
']}' | curl -s -X POST localhost:$STRIPE/_rystic/inject -H 'Content-Type: application/json' -d @-
# returns 204
curl -s -X POST localhost:$STRIPE/_rystic/clock -d '{"advance_seconds":259200}'
# receiver: verified /stripe charge.succeeded
# verified /stripe charge.dispute.created
The clock stays put unless paced, so a test reaches each event by moving it. How it runs says what a reset does to the schedule.
Clean up:
kill $RECEIVER
rystic stop stripe-hooks resend-hooks