AWS Builder Center
We Don't Just Detect Failed Orders. We Make Recovery Safer: Building Aftermath AI

We Don't Just Detect Failed Orders. We Make Recovery Safer: Building Aftermath AI

Building an intelligent commerce resilience platform that investigates failed order workflows, coordinates human-approved recovery, and verifies business outcomes.

We Don't Just Detect Failed Orders. We Make Recovery Safer: Building Aftermath AI, an Intelligent Commerce Resilience Platform

How I built a commerce recovery system that investigates failed order workflows, reconstructs business evidence, coordinates human-approved recovery, and verifies the outcome.

Introduction: When a Successful Payment Still Produces a Failed Order

Imagine a customer purchasing a product from an online store.
The payment succeeds. The inventory is reserved. The order is recorded.
But something goes wrong.
The shipping service times out before creating the shipment.
From the customer's perspective, the order has been placed and paid for. From the business's perspective, however, the order is incomplete.
Now several questions appear:
  • Was the payment actually successful?
  • Was inventory reserved?
  • Did the shipping provider receive the request?
  • Was a shipment created despite the timeout?
  • Is it safe to retry the operation?
  • Should the customer be refunded, or should the order be recovered?
A conventional application might simply return an error or retry the failed request.
But that can create another problem.
What if the original shipment was created, but the response was lost? A blind retry could create a duplicate shipment. What if the payment succeeded but the inventory reservation was released? What if the order is already in a different state?
The difficult part of commerce failure is not detecting that something went wrong. It is understanding the business state before deciding what should happen next.
That question became the starting point for Aftermath AI.



1. The Problem: Commerce Systems Don't Fail in Isolation

Modern commerce platforms depend on multiple interconnected services.
A typical order lifecycle may involve:
  1. Customer checkout.
  1. Payment processing.
  1. Inventory reservation.
  1. Order creation.
  1. Shipment allocation.
  1. Carrier handoff.
  1. Delivery confirmation.
Each component may work independently, but the complete business workflow depends on their coordination.
Consider this scenario:
Customer places an order
|
v
Payment succeeds
|
v
Inventory is reserved
|
v
Shipment allocation begins
|
v
Shipping service times out
|
v
Order becomes inconsistent
The timeout does not necessarily tell us whether the shipment was created.
It only tells us that the expected response was not received.
This distinction matters.
A system that immediately retries without checking persisted state can turn one failure into several.
Traditional error handling is often designed around technical responses:
  • HTTP errors
  • Timeouts
  • Failed requests
  • Retry attempts
  • Service availability
Commerce recovery requires something more: understanding the relationship between payment, inventory, order, and shipment state.
The system must answer:
What actually happened, what is the current business state, and which recovery action is safe?



2. The Idea: Aftermath AI

Aftermath AI is an intelligent commerce resilience platform designed to investigate failed business workflows and coordinate controlled recovery.
Rather than treating every error as an isolated technical problem, Aftermath examines the available business records and reconstructs the incident.
Its workflow follows six stages:
Detect → Investigate → Diagnose → Approve → Recover → Verify
The system is built around three important principles:
  • Evidence before assumptions.
  • Approval before consequential actions.
  • Verification before declaring success.
The goal is not to automate every possible failure blindly.
The goal is to make recovery more understandable, controlled, and auditable.



3. The Architecture: Separating Investigation from Recovery

One of the important design decisions was separating the investigation process from the recovery execution process.
An AI-generated diagnosis should not automatically become permission to modify business state.
Aftermath therefore separates the responsibilities into distinct components.

The main components

1. Commerce Storefront
The storefront creates the business scenario.
It includes:
  • Product catalogue.
  • Shopping cart.
  • Inventory validation.
  • Razorpay Test Mode checkout.
  • Server-side payment verification.
  • Persistent order and inventory records.
2. GhostTrail AI
GhostTrail is the investigation intelligence behind Aftermath.
It gathers available business evidence, reconstructs the incident timeline, produces an advisory diagnosis, and prepares a recovery proposal.
3. Diagnosis Engine
The diagnosis engine organizes the available evidence into an understandable explanation of the failure and its potential recovery path.
The diagnosis is advisory. It does not independently authorize a recovery action.
4. Operations Dashboard
The dashboard provides an operational view of:
  • Incident status.
  • Investigation details.
  • Recovery proposals.
  • Event timelines.
  • Audit history.
  • Current business state.
5. Discord Recovery Control Room
Discord provides the operator-facing approval interface.
Operators can inspect a case, retrieve its current status, and explicitly approve an eligible simulated recovery.
6. Recovery and Verification Engine
The recovery engine checks the required business preconditions before executing an approved action.
After execution, it reads persisted records again to verify the expected outcome.

Architecture diagram

flowchart TD
A["Customer Checkout"] --> B["Payment Verification"]
B --> C["Inventory Reservation"]
C --> D["Shipment Allocation"]
D --> E["Failure Detection"]
E --> F["Incident Persistence"]

F --> G["GhostTrail Investigation"]
G --> H["Evidence Collection"]
H --> I["Diagnosis Engine"]
I --> J["Recovery Proposal"]

J --> K["Discord Operator Review"]
K --> L["Approval and Preconditions"]
L --> M["Guarded Recovery Engine"]
M --> N["Persisted Business State"]
N --> O["Read-back Verification"]
O --> P["Updated Customer Shipment View"]
The architecture intentionally keeps AI-assisted investigation separate from the execution of consequential business actions.



4. GhostTrail: Reconstructing What Actually Happened

The most important question during an incident is not simply:
"What error occurred?"
It is:
"What happened across the different business components before the error occurred?"
This is where GhostTrail comes in.
When an incident is investigated, GhostTrail gathers the available records associated with the affected order.
These include:
  • Order information.
  • Payment state.
  • Inventory records.
  • Shipment information.
  • Available event history.
  • Existing recovery information.
The investigation uses this information to build a more understandable view of the incident.
For example:
Order Created
|
v
Payment Verified
|
v
Inventory Reserved
|
v
Shipment Allocation Requested
|
v
Shipping Service Timeout
|
v
Incident Recorded
|
v
GhostTrail Investigation
|
v
Diagnosis and Recovery Proposal
The important distinction is that a timeout is not automatically interpreted as proof that no shipment exists.
The system must examine the available persisted business state before recommending a recovery.
GhostTrail prepares an advisory diagnosis and recovery proposal, which can then be reviewed through the operator workflow.



5. Why I Didn't Allow AI to Execute Recovery Directly

An obvious first approach would be:
Failure
|
v
AI Diagnosis
|
v
AI Executes Recovery
It looks simple, but it creates a significant trust problem.
An AI model can interpret evidence and generate recommendations. That does not mean it should have unrestricted authority to change payment, inventory, or shipment state.
Consider a few possibilities:
  • The original shipment request succeeded, but its response timed out.
  • Payment is successful, but the order state is inconsistent.
  • Inventory has already been released.
  • A previous recovery attempt has already completed.
  • The proposed action is no longer valid because the business state changed.
Executing a recommendation without checking these conditions can create a second incident.
I therefore separated the responsibilities:
AI investigates
|
v
AI recommends
|
v
Operator reviews
|
v
System validates preconditions
|
v
Guarded recovery executes
|
v
System verifies persisted state
This creates a human-in-the-loop recovery architecture.
AI helps explain the incident. The application controls whether an action is eligible to execute.



6. Discord as an Operational Control Room

I wanted the recovery process to be more than an internal dashboard notification.
For the prototype, I implemented a Discord-based operator workflow.
When GhostTrail prepares a recovery handoff, the notification includes the available case context and the information required for operator review.
The operator can use three commands:
Command
Purpose
 CASE <code> 
Inspect the incident and proposed recovery
 STATUS <code> 
Read the latest persisted business state
 CONFIRM <code> 
Approve and execute an eligible simulated recovery
The workflow also incorporates important safety checks:
  • Time-limited recovery handoff codes.
  • Explicit operator confirmation.
  • Payment and shipment precondition checks.
  • Idempotency protection.
  • Persistent audit records.
  • Read-back verification.
The distinction between a recommendation and an approved action is intentional.
A recovery proposal is not permission to execute it.



7. Preventing Recovery from Becoming Another Failure

Automation can make a system faster, but speed alone does not make it reliable.
A recovery system needs to protect against repeated execution, stale state, and invalid assumptions.
Aftermath demonstrates several reliability principles.

Idempotency

Repeated confirmation should not create duplicate recovery actions.

Precondition validation

The system checks relevant business conditions before executing a recovery.

Expiring handoffs

A recovery handoff is time-limited so an old approval opportunity cannot remain valid indefinitely.

Auditability

Recovery decisions and actions are recorded for later inspection.

Read-back verification

The system does not treat an execution request as proof of success.
Instead, it reads persisted records again and checks whether the expected state was achieved.
A simplified recovery lifecycle looks like this:
Recovery Requested
|
v
Check Eligibility
|
v
Check Business Preconditions
|
v
Validate Approval
|
v
Execute Guarded Action
|
v
Read Persisted State
|
v
Verify Expected Outcome
|
+---+---+
| |
Verified Not Verified
| |
v v
Success Escalation /
Investigation
The principle is simple:
A system should report what it has verified, not what it merely attempted.



8. The Customer Experience: Keep Internal Complexity Internal

An important design decision was keeping the customer-facing experience separate from the internal recovery process.
Customers do not need to understand:
  • Internal incident identifiers.
  • Diagnosis terminology.
  • Recovery handoff codes.
  • Operator commands.
  • Backend implementation details.
They need to understand what is happening with their order.
Aftermath therefore provides a customer shipment monitoring experience with:
  • Order and product details.
  • Shipment status.
  • Recorded event timeline.
  • Recovery status.
  • Clear distinctions between confirmed and pending milestones.
The operations team gets the investigation details. The customer gets a simpler, understandable view.
This separation keeps the recovery process operationally useful without exposing unnecessary internal complexity.



9. Technology Stack

The prototype uses a straightforward application architecture.
Layer
Technology
Frontend
React, Vite, JavaScript, CSS
Backend
Python, FastAPI
Database
PostgreSQL, SQLAlchemy
Payment
Razorpay Test Mode
Operations
Discord.py, Discord Gateway
API
REST, OpenAPI, Swagger
Background Processing
Python notification worker
Testing
Pytest
Version Control
Git, GitHub
FastAPI provides the application API and backend services.
PostgreSQL stores the business state and related records.
React provides the storefront, investigation interface, operations dashboard, and shipment monitoring experience.
Discord provides the operator-facing recovery control room.
The notification worker handles the background notification workflow, while the Discord gateway bot supports operator commands.
The application is structured so that the customer interface, investigation process, recovery execution, and persistent business state have separate responsibilities.



10. What the Prototype Actually Demonstrates

The most useful way to understand Aftermath AI is to follow a single order through the complete scenario.
The demonstration involves:
  1. Creating an order through the storefront.
  1. Completing checkout using Razorpay Test Mode.
  1. Observing the deliberately seeded shipment-allocation failure.
  1. Opening Shipment Monitoring to inspect the order.
  1. Opening GhostTrail to review the investigation.
  1. Inspecting the recovery proposal.
  1. Switching to Discord to inspect the case.
  1. Checking the current business state.
  1. Explicitly confirming an eligible simulated recovery.
  1. Reading the persisted state again to verify the result.
This demonstrates the complete recovery lifecycle rather than simply generating an AI explanation.
The important engineering result is the separation between evidence collection, recommendation, approval, execution, and verification.



11. What I Learned While Building Aftermath AI

Building this prototype highlighted several engineering lessons.

1. A timeout does not always mean an operation failed

Distributed systems can lose responses even when downstream operations have succeeded.
The system needs to examine business state before retrying.

2. AI reasoning and business execution should have separate boundaries

An AI-generated recommendation should not automatically authorize a consequential business action.
Deterministic application checks and explicit approval are important boundaries.

3. Idempotency is essential for recovery workflows

A retry or repeated confirmation must not create duplicate business operations.

4. Verification is different from execution

A successful API response does not necessarily prove that the desired business state was achieved.
Persisted state must be checked.

5. Customer and operator interfaces have different responsibilities

Operators need detailed evidence and control. Customers need clear and trustworthy status information.

6. A prototype must be honest about its boundaries

A simulated recovery should not be described as a live carrier integration. A seeded failure should not be described as universal failure detection.
Clear boundaries make the architecture easier to understand and provide a realistic foundation for future development.



12. Current Scope and Limitations

Aftermath AI is a working prototype demonstrating a deliberately constrained recovery workflow.
The current implementation has several important boundaries:
  • The automated failure scenario is a seeded shipment-allocation timeout, not a universal detector for arbitrary external commerce systems.
  • GhostTrail investigation and recovery-plan preparation are initiated by opening the investigation page; a durable autonomous investigation worker is not yet implemented.
  • Recovery execution is a guarded database simulation. No live carrier API is contacted and no physical parcel is created or moved.
  • The Operations Dashboard uses periodic polling rather than WebSockets or server-sent events.
  • Discord approval, precondition checks, idempotency, audit, and read-back verification apply to the seeded demonstration scenario.
  • Razorpay is used in Test Mode; no real payments are processed.
These limitations are important because a production recovery platform would require additional engineering.



13. What Comes Next?

The prototype provides a foundation for expanding the recovery architecture.
Some of the directions I would explore next include:
Area
Potential enhancement
Investigation
Durable background investigation workers
Integrations
Real payment, inventory, and carrier adapters
Event ingestion
Webhooks and change-data-capture pipelines
Recovery
Provider-backed retry and compensation workflows
Intelligence
More advanced diagnosis and recommendations
Observability
Live event streaming and deeper operational metrics
Reliability
Reconciliation, resilience, and failure-injection testing
Deployment
Production infrastructure and operational hardening
The long-term direction is to move from a constrained recovery demonstration toward a system that can coordinate business recovery across multiple commerce services.
That requires more than a capable AI model. It requires reliable state management, explicit authorization, deterministic business rules, observability, and verification.



Conclusion: Recovery Needs More Than Another Retry

A failed commerce workflow is rarely just a failed API request.
It can leave payments, inventory, orders, and shipments in different states. Treating every failure as an opportunity to retry can create duplicate actions and additional inconsistencies.
Aftermath AI explores a different approach.
It investigates available evidence, explains what happened, prepares a recovery proposal, requires operator approval, validates business preconditions, and verifies the resulting persisted state.
The most important idea behind the project is not autonomous execution.
It is controlled recovery.
Because in commerce systems, recovering from a failure should never become the reason another failure occurs.



Project Links

  • Technology: React, FastAPI, PostgreSQL, Discord, Razorpay Test Mode
  • Core Components: GhostTrail AI, Diagnosis Engine, Recovery Engine, Operations Dashboard
Aftermath AI — When workflows fail, recovery begins.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article