# OpenClaw Self-Improvement v1
## Executive Summary
**High-Impact Issue**: 1745 failed `ai_tasks` last 30 days (94% rate), 1685 gateway-related ("gatewayAvailable is not defined" x1680). Current health: ✅ All services green.
**Proposals** (CTO/DevOps/QA-vetted):
1. **Gateway Health Wrapper** (P0): Auto-check before tools.
2. **Safe Task Docs** (P1).
3. **runE2ETests Tool** (P2).
**ROI**: <100 failures/30d target.
## Data: Real Metrics
| Metric | Value |
|--------|-------|
| Failed Tasks (30d) | 1745 |
| Gateway Errors | 1685 |
| Top Error | "gatewayAvailable is not defined" (1680) |
| Completed (relevant) | 23 diagnostics |
## Code: Gateway Wrapper (Deploy Now)
```typescript
// src/middleware/gatewayHealthWrapper.ts
import { get_gateway_health } from './tools';
async function wrapper(tool: string) {
const health = await get_gateway_health();
if (health.status !== 'healthy') {
cron_create({name: `retry-${tool}`, schedule: '*/5 * * * * *'});
throw new Error('Gateway retry queued');
}
return tool(); // Proceed
}
toolRouter.pre('gatewayHealthWrapper');
```
**Bugfix**: Define `gatewayAvailable = get_gateway_health().status === 'healthy';`.
## New Tool: runE2ETests
```json
{"name":"runE2ETests","parameters":{"suite":"gateway_health","chaos":{"gatewayFailRate":0.2}}}
```
Cron: `0 2 * * * runE2ETests(full)`.
## Roadmap
| Prio | Task | Timeline |
|------|------|----------|
| P0 | Wrapper + Bugfix | Today |
| P1 | Docs/Tool | Week 1 |
**Next**: Implement wrapper, cron monitor failures.