Self-Healing Background Jobs with AI Intelligence
A demonstration of the Motia unified backend framework.
The Motia Agentic Layer is an intelligent orchestration system that transforms standard background job retries into a smart, decision-making process. Instead of blindly retrying failed jobs, this system uses an AI Brain to analyze errors, understand context, and make optimal recovery decisions.
It features a Polyglot Architecture running TypeScript, Python, and JavaScript seamlessly in a single runtime, visualized by a real-time React Dashboard.
- Smart Decision Engine: Classifies errors (Network, Timeout, Logic, Resource) and selects the best strategy (Retry, Backoff, Abort, Escalate).
- Short-Term Memory: "Remembers" recent failures to detect patterns and prevent retry loops.
- AI Explanations: Uses OpenAI (GPT-4) to generate human-readable root cause analysis.
Three languages, one workflow:
- TypeScript: High-performance API Gateway.
- Python: Data processing and AI integration.
- JavaScript: Lightweight logging and notification.
- Real-time visualization of job states.
- Detailed timeline of every execution attempt.
- Insight into the "Brain's" decision-making process.
- Core: Motia (Unified Backend Framework)
- Languages: TypeScript, Python 3.10+, JavaScript
- AI: OpenAI API
- State/Queue: Redis
- UI: React + Tailwind CSS
- Deployment: Docker / Railway
- Node.js 18+
- Python 3.10+
- Redis (running locally or cloud)
- OpenAI API Key
# 1. Clone the repo
git clone https://github.com/byteStealthX/autoretry.git
cd autoretry
# 2. Install dependencies (Node + Python)
npx motia install
# 3. Configure Environment
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY# Start the Unified Dev Server
npm run devVisit http://localhost:3000 to open the Workbench & Dashboard.
# Triggers TS -> Python -> JS flow
curl http://localhost:3000/hello# Starts a background job that may fail and trigger AI analysis
curl -X POST http://localhost:3000/run-jobsrc/
├── agentic/ # The "Brain" of the system
│ ├── decision-engine.ts # Logic for recovery strategies
│ ├── memory-store.ts # Failure pattern tracking
│ └── explanation-engine.ts # AI analysis integration
├── hello/ # Business Logic Steps
│ ├── hello-api.step.ts # TS API Endpoint
│ ├── process_greeting_step.py # Python Processor
│ └── run-job.step.ts # Job Trigger
└── dashboard/ # React UI
Ready to deploy? This project is Docker-ready.
Deploy to Railway:
- Fork this repo.
- New Project -> Deploy from GitHub.
- Add
OPENAI_API_KEYand Redis.
Built with ❤️ using Motia.
