# AI Harness Stability & Middleware (Shipped)

> **Note:** These middleware stability mechanisms have been shipped.

- The chat loop (`app/api/chat/route.ts`) acts as a robust harness that intercepts tool errors and automatically suggests recovery paths (e.g., port conflicts, container collisions).
- The maximum tool execution loop is capped (`MAX_TOOL_ROUNDS=30`) to prevent runaway AI loops.
- `fs_edit` uses line-number replacements alongside strict `oldString` matching to avoid Aider-style search-and-replace failures.
- Sentry and Coolify deployment webhooks automatically pipe deployment/build failures back to the user/AI.
