Skip to content

Commit be71f7f

Browse files
authored
Improve clarity in compensation actions and notes
Clarified the explanation of compensation actions and modified the note about injecting failures for better readability.
1 parent fe78a3b commit be71f7f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

blog/2026-02-07-building-a-durable-ai-travel-agent-with-laravel.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@ private function bookHotel(array $data, ?string $injectFailure)
430430

431431
After each successful booking, we register a compensation action. `addCompensation` takes a callable that knows *exactly* how to undo what was just done, including the confirmation number, dates, and all the details returned by the booking activity.
432432

433-
The framework remembers the hotel confirmation.
434-
435433
If any subsequent step throws an exception, the `catch` block runs:
436434

437435
```php
@@ -443,7 +441,7 @@ catch (Throwable $th) {
443441
}
444442
```
445443

446-
`$this->compensate()` executes all registered compensation actions **in reverse order**. If you booked a hotel, then a flight, then a rental car, and the rental car fails, the flight gets cancelled first, then the hotel. To cancel them in parallel instead, we can set `$this->setParallelCompensation(true)`.
444+
`$this->compensate()` executes all registered compensation actions **in reverse order**. If you booked a hotel, then a flight, then a rental car, and the rental car fails, the flight gets cancelled first, then the hotel. (To cancel them in parallel instead, we can set `$this->setParallelCompensation(true)`.)
447445

448446
And notice: the inactivity timeout and message limit are thrown as exceptions too. If a user walks away mid-booking, the `catch` block fires, compensation runs, and all their reservations get cleaned up. Every exit path goes through the same cleanup logic.
449447

@@ -583,4 +581,4 @@ To try it:
583581
```bash
584582
php artisan app:ai
585583
```
586-
Note: You can optionally inject a failure at one of the booking steps by running it with the `--inject-failure` e.g. `php artisan app:ai --inject-failure flight`. Valid options are `hotel`, `flight` or `car`.
584+
Note: You can optionally inject a failure at one of the booking steps by running it with the `--inject-failure` flag e.g. `php artisan app:ai --inject-failure flight`. Valid options are `hotel`, `flight` or `car`.

0 commit comments

Comments
 (0)