Returns Center · Case study
A return combines facts the application already knows—the item, its delivery date and the resolutions it supports—with information supplied by the person who bought it. ExecKernel can use those facts to determine which routes remain available. Your application retrieves the order, accepts the reason and turns the result into an understandable response.
Returns Center brings those pieces together in a web assistant using the local PHP SDK. The engine runs inside the PHP backend. The interface displays fictional orders and leads to a return, replacement, repair or review request; the application’s case record stays associated with the session that produced that result.
Follow two different requests
Section titled “Follow two different requests”The demo uses a fixed clock: 20 November 2026 at 12:00 UTC. Elapsed days are calculated against that instant, so these routes remain reproducible. Its example policy distinguishes an ordinary return from a defective-item issue.
Start with the Wireless headphones from order RC-1042:
- Select the item and start the request.
- Choose I changed my mind and confirm the reason.
- Continue through View eligible return options.
- Select Request return and refund, then confirm.
Next, start a new request for the Electric kettle from order RC-1031. Choose There is a problem, confirm the reason, continue through View available resolutions and select Request repair.
| Data and decision | Headphones | Kettle |
|---|---|---|
| Delivery | 12 November: 8 days before the demo’s clock | 6 October: 45 days before |
| Confirmed reason | changed_mind |
defective |
| Graph check | Ordinary return allowed and within 30 days | Issue within 90 days |
| Resolution we select | Return and refund | Repair, with repair_supported: true |
| Result | Terminal 90 |
Terminal 92 |
These windows and restrictions belong to this application’s fictional policy. For the kettle, more than 30 elapsed days prevents the ordinary route but still permits the defective-item route. The reason determines which time check applies.
The diagram selects the routes being compared. The complete graph and sample orders include the other resolutions and restrictions.
Observe what the simulation accepted
Section titled “Observe what the simulation accepted”At the end, the application presents the terminal’s title and content alongside the case reference and order data:


The terminal expresses the resolution selected through the route. The demo retains the case and displays that result; it does not move money, reserve inventory or schedule a repair.
The application obtains the order data
Section titled “The application obtains the order data”When starting a request, the browser sends orderId, itemId and language. The backend checks that the item belongs to the specified order and obtains its data from the prepared catalogue. It does not accept the date, price or item conditions as values chosen by the browser.
Here we reuse session context: data accompanying execution and allowing conditions to be evaluated. The contextFor() function in demos/returns-center/backend/src/CaseService.php prepares that part of the order:
private function contextFor(array $order, array $item): array{ return [ 'order_id' => $order['id'], 'item_id' => $item['id'], 'delivered_at' => (new DateTimeImmutable( $order['delivered_at'] ))->getTimestamp(), ] + $item['facts'];}$order and $item are already the records found by the backend. The date becomes a timestamp for time rules. facts adds booleans such as ordinary_returnable, replacement_available, repair_supported and exception_available.
The price and item name help present the order summary. They are not conditions in this graph and do not need to be in its context. The return reason arrives later, when the person selects it.
The application configures the engine to evaluate time using the simulation clock:
$this->engine = (new ExecKernelFactory())->build( timeProvider: FixedTimeProvider::fromTimestamp($this->simulationTime),);$this->simulationTime comes from the sample orders’ simulation_clock field. The time rule therefore compares delivered_at with a controlled instant. The visitor workspace’s lifetime is managed separately using real time; freezing the policy clock does not make the demo’s case permanent.
Propose the reason and confirm the choice
Section titled “Propose the reason and confirm the choice”Before advancing, the interface lets someone select a reason and ask which route it would enable. This uses context updates and candidate values: a query can evaluate proposed data without modifying the saved session.
At initial node 10, CaseService.preview() calls the engine directly:
$raw = $this->engine->getPayload( $this->graph, $state, $lang, contextUpdates: new Context(['reason' => $reason]),);$state is the engine state retrieved from the store, and $reason is one of the two reasons accepted by the backend. With changed_mind, the query enables edge 101 toward the ordinary policy. With defective, it enables 102 toward the issue-reporting window. The Context object contains the values proposed for this query. The response is a payload: presentation data for the step, including its choices and their availability, as explained in Payloads and presentation. It lets the interface prepare its continue button; the saved session remains at node 10, with the same revision and no confirmed reason.
On confirmation, the application sends the reason again alongside the edge. It performs that step through the local PHP SDK: the client and adapter coordinate the engine call and the session save.
$client = $this->client();$dto = $client->resume($row['engine_id'], $lang);$client->navigate( $dto, $edge, $reason === null ? [] : ['reason' => $reason],);This fragment from CaseService.next() assumes the case and revision checks. $row['engine_id'] identifies the saved session; $dto is the typed response the SDK returns when restoring it. At the initial step, $reason contains the selected reason. At later steps it is null, and navigation uses the already confirmed context.
The engine checks the edge with that reason, and the adapter retains the accepted result. The application reads it again to prepare the next screen. An earlier query does not replace this check: submitting the defective-item edge with changed_mind causes a rejection, and the earlier query does not confirm the reason.
How the resolutions change
Section titled “How the resolutions change”Each node returns the options appropriate to the current state. The interface also shows blocked choices with an explanation and allows an available choice to be confirmed. Its code uses the node identifier to select a presentation stage; option eligibility comes from the payload.
These are the main routes in the definition:
| Case situation | Options provided by the graph |
|---|---|
| Ordinary return, eligible item, up to 30 days | Return and refund; replacement if replacement_available is true. |
| Ordinary return, eligible item, more than 30 days | Exception review if exception_available is true; otherwise an ineligible result. |
| Item not eligible for an ordinary return | Ineligible result for that route. |
| Defective item, up to 90 days | Replacement if available, repair if supported, and manual review. |
| Defective item, more than 90 days | Manual review. |
For example, the backpack in order RC-1028 is outside the ordinary window but has exception_available: true: its route allows an exception review request. That terminal communicates a referral for review; it does not approve the return. The personalized mug instead has ordinary_returnable: false and reaches the ineligible result on the ordinary route.
The conditions separate different questions: which policy matches the reason, whether its time window is met and which resolutions the item supports. Your application supplies the facts; the graph combines those conditions and determines which options to present as available.
Retain the case and recover the screen
Section titled “Retain the case and recover the screen”The local integration uses a configured engine, a graph loader and a FilesystemSessionStore. CaseService assembles them with ExecKernelLocalAdapter and ExecKernelLocalClient. Engine calls happen in the same PHP process; the web interface communicates with the application’s backend.
The case record and session have different roles:
| Data | Where the demo retains it | What it is used for |
|---|---|---|
Visitor association, caseId and session identifier |
Application tables in SQLite | Authorize access and find the corresponding execution. |
| Order, item, graph version, simulation clock and coordination phase | returns_cases in SQLite |
Identify the case and verify that the recovered session belongs to it. |
| Node, context and history | FilesystemSessionStore |
Continue the engine’s route from the saved state. |
| Item summary and visible result | View prepared by the backend when reading a case | Combine catalogue data with the current payload to present the screen. |
The returns_cases row is not a full copy of the engine state. For example, the confirmed reason stays in the session context, and the result title is obtained from the terminal payload.
Before starting execution, the application assigns its session identifier and records the case association with phase starting. If the SDK saves the session and the request is interrupted afterwards, a later read can find it using that identifier, check its data and complete the coordination. The store and SQLite remain separate components; the demo retains that information so it can determine what happened.
Try reloading the page after confirming the reason or reaching the result. While the visitor workspace remains valid, the backend retrieves the case, verifies its association and reconstructs the screen from the saved session. If a request fails, the interface reads the state and avoids automatically repeating the operation.
To adapt this design, keep commercial data and each person’s case association in your application; give the graph the facts it needs to decide. If a resolution should produce a real refund or repair order, that action and its record belong to your application’s business process.