Configuring webhooks
A webhook is an HTTP notification sent when something happens in a graph. Your application can use it to tell another service that a session entered a node, crossed an edge or reached a terminal. The receiving service then decides what to do with that information.
Three pieces participate: a subscription selects the destination and events; a runtime listener turns the engine’s events into webhook messages; a dispatcher sends those messages or places them in a queue. Declaring a subscription alone does not start an HTTP request.
This guide connects those pieces to an endpoint you control. The example uses a small review process: node 10 means the review is in progress, edge 101 completes it, and node 20 is terminal. A notification lets another application associate completion with the reference REQ-42. Webhooks work with other kinds of process in the same way.
Choose what the other application needs to know
Section titled “Choose what the other application needs to know”Webhook subscriptions use names such as execkernel.node.terminal. These are the names in the HTTP notification, rather than the runtime listener names such as terminal.reached.
| Webhook event | What the receiving application learns |
|---|---|
execkernel.node.enter |
A session started at its root or visited another node. |
execkernel.edge.traverse |
A choice traversed an edge, including its source and destination. |
execkernel.session.update |
A session started or completed a transition. |
execkernel.node.terminal |
A terminal node was reached, with its terminal outputs. |
execkernel.rule.block |
A condition blocked an attempted choice or navigation. Its context describes the attempted values. |
For the review example, subscribe only to execkernel.node.terminal. The receiving application needs the completion notice, so notifications about every intermediate visit would add work without changing its decision.
The distinction also affects interpretation. A terminal notification has context_scope: "result". A blocked-rule notification has context_scope: "candidate": the values were used to evaluate the attempt and need not have become the saved session. The webhook contract covers the event-specific fields.
Configure the destination and shared secret
Section titled “Configure the destination and shared secret”The complete review graph places this subscription in its top-level webhooks array:
{ "webhooks": [ { "url": "http://127.0.0.1:8089/webhook", "events": ["execkernel.node.terminal"] } ]}This is a fragment of the graph definition. The URL points to the local test receiver used below. In your integration, replace it with an endpoint controlled by the receiving application and use HTTPS outside the local test.
The subscription has three supported fields:
| Field | Purpose |
|---|---|
url |
The HTTP or HTTPS destination. |
events |
A nonempty list of webhook event names to send there. |
secret |
An optional shared secret used to sign the request body. |
Supply the secret from your application’s configuration before loading the graph. The file provided with this guide deliberately leaves it out:
use ExecKernel\Infrastructure\Loader\ArrayGraphLoader;use ExecKernel\Infrastructure\Webhooks\WebhookConfig;
$definition = json_decode( file_get_contents(__DIR__ . '/webhook-graph.json'), true, 512, JSON_THROW_ON_ERROR,);$secret = getenv('WEBHOOK_SECRET');if (!is_string($secret) || $secret === '') { throw new RuntimeException('Set WEBHOOK_SECRET for both sender and receiver.');}
$definition['webhooks'][0] = WebhookConfig::fromArray( $definition['webhooks'][0] + ['secret' => $secret],)->toArray();$graph = (new ArrayGraphLoader($definition))->load('review-notice');WebhookConfig validates the subscription; ArrayGraphLoader incorporates it into the graph. The sender and receiver must obtain the same secret. The secret stays in the delivery configuration and is not included in the notification body.
Timeouts and retries belong to the dispatcher. They are not additional fields in the graph’s subscription. That separation lets your application choose delivery settings without redefining which events a graph announces.
Select the scope of the subscription
Section titled “Select the scope of the subscription”A webhooks array can belong to the whole graph, one node or one edge. Put it at the definition’s top level for the graph, inside a nodes entry for a node (nodes[].webhooks), or inside an edges entry for an edge (edges[].webhooks). The listener chooses the applicable subscriptions for each event, starting at the most specific relevant scope.
| Event being delivered | Scopes examined, in order |
|---|---|
execkernel.edge.traverse or execkernel.rule.block |
The edge, its source node, then the graph |
execkernel.node.enter, execkernel.session.update or execkernel.node.terminal |
The current node, then the graph |
At the first scope containing subscriptions for that event, the listener selects all matching subscriptions there and stops searching. It does not also add the matching subscriptions from the broader scopes.
For example, the review graph’s top-level terminal subscription applies to node 20. If node 20 has its own terminal subscription, that subscription takes precedence. If its local list subscribes only to execkernel.node.enter, the terminal event still falls back to the graph: a subscription to a different event does not hide it.
Use the graph scope for a common destination, and a node or edge scope when that particular event needs different recipients. For an edge event, remember that the node fallback is the source node, even though a successful traversal has moved the session to its destination.
Connect the listener to an HTTP dispatcher
Section titled “Connect the listener to an HTTP dispatcher”WebhookRuntimeListener reads the subscriptions from the graph and creates the notification. ResilientWebhookDispatcher performs the HTTP delivery through CurlWebhookTransport.
The dispatcher configuration provides the application helper createWebhookDispatcher(). It enables signing from the subscription, an Idempotency-Key header and a one-second timeout per attempt. Here we request one attempt; Webhook delivery, retries and queues develops the retry settings.
With that helper loaded, register the listener before running the graph:
use ExecKernel\Infrastructure\Engine\ExecKernelFactory;use ExecKernel\Infrastructure\Webhooks\WebhookRuntimeListener;
require __DIR__ . '/webhook-dispatcher.php';
$sender = createWebhookDispatcher(maxAttempts: 1);$failures = [];$engine = (new ExecKernelFactory())->build();$engine->attachRuntimeListener(new WebhookRuntimeListener( $graph, $sender, failureObserver: static function (array $failure) use (&$failures): void { $failures[] = $failure; },));The listener is associated with this graph’s code and version. The failure observer belongs to your application: it records a final delivery failure so the application can report it separately from the graph’s outcome.
Now start the review and complete its only choice:
use ExecKernel\Domain\Session\Context;
$started = $engine->start( $graph, 'en', new Context(['reference' => 'REQ-42']), sessionId: 'review-42', timestamp: 1767225600, operationId: 'review-42-start',);$completed = $engine->choose( $graph, $started->state, 101, 'en', sessionId: 'review-42', timestamp: 1767225601, operationId: 'review-42-complete',);Starting at node 10 does not match the terminal subscription. Completing edge 101 reaches node 20 and produces one terminal notification. The fixed identifiers and timestamps make this example reproducible; your application supplies its own session and operation identities.
The listener acts when the result event is published. If your application must save the session before publishing external notifications, use the deferred event publication described in Events and runtime listeners. A webhook does not itself confirm a database write.
Read the received request
Section titled “Read the received request”The receiver gets an HTTP POST with JSON. These are selected headers from the captured request; the two long values are shortened here:
POST /webhook HTTP/1.1Host: 127.0.0.1:8089Content-Type: application/jsonIdempotency-Key: 637b91f1…e2c97c63X-ExecKernel-Signature: sha256=b2c8f6ce…9ab9d11eThe signature lets the receiver check the body with the shared secret. The idempotency key lets the receiving application recognize another attempt at the same delivery; the header alone does not suppress duplicates.
This excerpt comes from the actual received JSON. The four long identifiers are omitted from this view; the complete captured HTTP request includes their full values and the original body bytes.
{ "event": "execkernel.node.terminal", "version": "1.0", "graph": "review-notice", "graph_version": "1.0.0", "operation_id": "review-42-complete", "timestamp": "2026-01-01T00:00:01Z", "session_id": "review-42", "context_scope": "result", "context": { "reference": "REQ-42" }, "node_id": 20, "outputs": []}The receiving application can use context.reference to find its review record and node_id to identify the completed stage. outputs is empty because this graph declares no terminal outputs. The envelope’s version describes the webhook format; graph_version identifies the graph revision.
The full body also contains event_id, runtime_event_id, subscription_id and delivery_id. An event identifies what happened; a delivery identifies the message for one subscription. Retain the delivery identity when recording receipt or retrying a stored message.
The context travels in the notification. Choose a destination that should receive those application values; this JSON is not the presentation payload that your user interface renders.
Check the signature before using the JSON
Section titled “Check the signature before using the JSON”Calculate HMAC-SHA256: an authentication code derived from the exact body bytes and the shared secret. Compare the entire header value using hash_equals():
$rawBody = file_get_contents('php://input');$receivedSignature = $_SERVER['HTTP_X_EXECKERNEL_SIGNATURE'] ?? '';$expectedSignature = 'sha256=' . hash_hmac('sha256', $rawBody, $secret);
if (!hash_equals($expectedSignature, $receivedSignature)) { reply(401, ['error' => 'invalid_signature']);}Here $secret is the receiver’s configured secret, and reply() is the small response helper in the complete receiver. Its preceding checks enforce the route, JSON content type and body-size limit.
Verify the raw bytes before decoding and re-encoding JSON: changing whitespace would change the bytes being checked. Then decode the body and validate the event your application expects. The supplied receiver checks execkernel.node.terminal, graph review-notice at revision 1.0.0, node 20, result context, a delivery identifier and a nonempty reference.
For the request above, the receiver records the request and answers:
{"accepted":true,"reference":"REQ-42"}This test response confirms that the endpoint accepted the notification. Your receiving application decides whether its own 2xx means “stored for processing” or “business operation completed”. The dispatcher treats either as HTTP success and does not interpret the response body.
Signature verification checks integrity and possession of the shared secret. Duplicate handling and replay decisions still belong to the receiving application; see the delivery guide and the signature contract for those boundaries.
Observe the integration in an existing PHP project
Section titled “Observe the integration in an existing PHP project”The complete example consists of the graph, dispatcher helper, sender and receiver. Put them beside your project’s vendor directory. The sender uses your existing ExecKernel installation and PHP’s cURL extension.
In one terminal, start the controlled receiver with a fresh directory for its request log:
export WEBHOOK_SECRET='local-example-secret'export WEBHOOK_RECEIVER_DIR="$(mktemp -d)"echo "$WEBHOOK_RECEIVER_DIR"php -S 127.0.0.1:8089 webhook-receiver.phpFrom a second terminal in the same project directory, send the completion notification:
WEBHOOK_SECRET='local-example-secret' php webhook-send.php en direct 1The sender reports node 20 and an empty listener_failures list. The printed receiver directory contains requests.jsonl with one request and http_status: 200. Inspect that receiver log to see what arrived. It is produced by this example endpoint, not by an automatic history inside the dispatcher. Stop the local receiver with Ctrl+C when finished.
For a browser demonstration, open Webhook Lab. Its own graph sends a terminal notification and displays the actual HTTP request and the receiver’s returned bytes. The graph’s completion and the delivery status appear separately, which is the distinction to carry into your application.