Skip to main content

Error Recovery

Myrm’s error recovery system ensures agents keep running through network failures, model outages, rate limits, and unexpected errors — automatically, without user intervention.

14-Layer Recovery Architecture

Circuit Breaker

The circuit breaker prevents cascading failures when a model provider goes down:

States

Error Classification

Credential Pool

When one API key hits rate limits, the system automatically rotates to the next available key:
  • 4 dispatch strategies (round-robin, least-used, random, priority)
  • Per-key error-aware cooldown
  • Exponential backoff per key
  • Automatic probe when cooldown expires

Error Diagnostics

When errors occur, the system provides structured, actionable feedback:

9 Error Categories

Each error includes a structured context with error_hint, error_category (28 canonical categories via ToolErrorCategory StrEnum, fully i18n-translated in 4 languages), and suggested RecoveryAction — displayed as clickable buttons in the GUI. A cross-layer sync test suite (46 tests) ensures the harness enum and frontend i18n keys never drift.

Interactive Recovery Buttons

For common LLM errors, the error card includes one-click fix buttons that take you directly to the right settings page: Button labels are localized into 5 languages (English, Chinese, Japanese, Korean, German) and automatically match your interface language. If the diagnostic engine encounters an unexpected error, it degrades gracefully — the base error message still displays without recovery buttons.

Code Execution Auto-Diagnosis

When the agent runs Python code or Bash commands, the execution engine automatically classifies errors and generates actionable hints: The engine includes a built-in import-to-PyPI mapping table (PIL → Pillow, sklearn → scikit-learn, yaml → PyYAML, and more) and auto-detects whether uv pip is available. All code runs in an isolated shared virtual environment managed by VenvManager, ensuring user-installed packages never pollute the system Python.

Model Self-Escalation

When a lightweight model detects it lacks the capability to complete a task:
  1. Model outputs a special <<<NEEDS_PRO>>> marker
  2. The EscalationScrubber intercepts the marker (hidden from user)
  3. Agent automatically switches to the configured stronger model
  4. Task continues seamlessly
This enables cost-efficient routing: simple tasks use cheap models, complex tasks auto-escalate.

Loop Detection

7 independent detectors identify different types of agent loops: Detection follows a graduated response: first a warning with context-aware suggestions is injected into the agent’s context, then a forced break if the pattern persists (severity: WARNING 3-5x → ERROR 6-9x → CRITICAL 10+x).

Post-Compaction Loop Protection

When context overflow triggers emergency compaction, LoopGuard handles the transition with precision:
  • Loop detection state survives intact — the sliding window (pattern detection) and error signatures operate in ContextVar, fully decoupled from the message list that compaction modifies
  • Iteration budget is intelligently resetnotify_compaction() resets total_calls so the agent is not prematurely terminated due to pre-compaction call history, while preserving error_signatures for cross-compaction failure tracking
  • Agent phase is preserved — the current execution phase (exploration, execution, etc.) carries over, maintaining context-aware detection thresholds
This dual approach — detect loops more sensitively while giving the agent a fresh budget — fundamentally eliminates both the “post-compaction doom loop” and the “premature termination after compaction” failure patterns. No competing system addresses this compaction×budget intersection.

Post-Compaction Memory Protection

After context compaction, the agent’s memory retrieval remains fully intact with zero lag or data loss, thanks to a 5-layer memory protection architecture:
  1. SystemMessage Immune to Compaction: User profile and rules are injected as SystemMessage at position 0, never touched by the compress processor
  2. Learned Context Immune to Compaction: Learned context is injected as HumanMessage, not a tool call pair, so it’s never selected for compression
  3. PreCompactProcessor Proactive Recall: Before compaction, the system automatically triggers vector database semantic search and injects relevant memories as standalone message blocks, ensuring the LLM retains access to critical memories after compaction
  4. Real-time Vector Index: Qdrant vector database entries are searchable immediately after write — no index lag
  5. Independent Memory Extraction: End-of-session memory extraction uses the original dialogue, unaffected by in-session compaction
This architectural design fundamentally eliminates “post-compaction memory loss” — a problem competitors must patch with forced index refresh mechanisms.

Iteration Budget

Agents have configurable iteration limits (default: 50) with dynamically computed thresholds based on the graph recursion limit: The thresholds are automatically derived from graph_recursion_limit and converted to tool-call counts, ensuring the budget scales correctly regardless of configuration. The grace summary provides a structured wrap-up of completed work, remaining tasks, and suggestions for continuation.

Silent Tool Retry

When a tool call fails due to transient errors (network timeouts, rate limits, temporary unavailability), the system retries automatically — the user only sees a heartbeat timer ticking, never the failure.

6-Layer Retry Architecture

How It Differs from Competitors

  • Not prompt-based: Retry logic is deterministic code (Pydantic schemas + counters), not LLM instructions that may be ignored
  • Not developer-only: Unlike framework-level retry configs (e.g. LangGraph’s RetryPolicy), the heartbeat UI provides end-user visibility
  • Not noisy: Retries are silent — no error popups, no user decisions required for transient failures

File Checkpoint

Before any destructive file operation, AutoSnapshotInterceptor automatically takes a snapshot:
  • Covers 6 tool categories: write_file, patch_file, delete_file, move_file, execute_terminal, code_execute
  • Per-turn deduplication prevents redundant snapshots
  • Snapshots enable single-click rollback in the GUI

Database Safety

A 5-layer protection system ensures your data (conversations, scheduled tasks, memories) survives any failure: Multi-step table rebuild migrations (e.g. CREATE TABLE AS SELECT → DROP → RENAME) are fully protected: if the process is interrupted mid-migration, the pre-migration backup provides a clean restore point.

Subagent Error Compaction

When a child agent crashes with a long traceback, the error message is automatically compacted before reaching the parent agent’s context — preventing pollution that would degrade the parent’s reasoning quality. This prevents a common multi-agent failure pattern: a child agent’s verbose crash output consuming the parent’s context window, causing cascading reasoning degradation across the agent hierarchy.

Subagent Partial Progress on Failure

When a sub-agent fails mid-execution (LLM error, budget exceeded, timeout, or runtime exception), all accumulated work is preserved and returned to the parent agent — never lost.

Why This Matters

Without partial progress preservation, a sub-agent that completed 80% of a complex task before hitting a rate limit would lose all its work. The parent agent would have to start from scratch — wasting the tokens already consumed and doubling the cost. With Myrm’s approach:
  • Parent receives all completed work as structured output
  • Parent can resume from where the sub-agent left off
  • Token cost for the successful portion is not wasted
  • Over-long partial output is automatically truncated (configurable via max_error_chars * 2)

Competitor Comparison

Myrm provides defense-in-depth against cascading failures at every level of the agent hierarchy: Unlike traditional microservice dependency chains, LLM agents don’t have explicit tool DAGs — the LLM decides the call sequence at runtime. Myrm addresses cascading errors at the right abstraction level: infrastructure-level circuit breaking, behavioral pattern detection, and hierarchical cancellation — rather than attempting to model non-existent tool dependencies. Verified: 604 tests passed across all cascading error protection modules (LoopGuard, FrequencyGuard, E-Stop, ToolCallBroadcaster, SubagentExecutor, CircuitBreaker, ToolGuards).

Retry Storm & Budget Protection

Myrm actively prevents runaway retry loops and protects your API budget: This is active truncation (immediately stop execution), not passive monitoring (just log and alert). When a retry storm is detected, the agent is forced to stop and provide its best answer with whatever results it has — protecting both cloud compute costs and local API key balance. Verified: 330 tests passed across all retry protection modules (LoopGuard, FrequencyGuard, BudgetGuard, MultidimensionalBudgetGuard, BudgetBoundaryMiddleware).

Budget Protection

Myrm provides comprehensive budget control across all deployment modes:
  • MultidimensionalBudgetGuard: Per-session, daily, and per-call USD limits with 4-level progressive response (OK → WARNING → FINALIZATION → EXCEEDED)
  • Dynamic Budget Hints: When budget drops to WARNING or FINALIZATION, the exact remaining USD is injected into the LLM prompt — the AI knows precisely how much it can spend and self-adjusts behavior accordingly
  • BudgetBadge: Real-time budget indicator in the chat input area showing usage percentage with color-coded status
  • BudgetExceededDialog: One-click top-up or plan upgrade when budget is exceeded
  • ChannelBudget: Independent budget limits for each IM channel (Telegram, WeChat, etc.)
  • BudgetPolicySection: Full UI for configuring budget policies with finalization reserve
  • DailyChart: 30-day usage trend with cache hit rate overlay
Verified: 181 tests passed across all budget protection modules (harness framework: 102 passed, server business layer: 79 passed).

Data Lifecycle Management

Myrm automatically manages data retention across all storage engines — no manual cleanup needed:
  • 9 Automated Schedulers: Context files (3-tier: 30d/14d/7d), auth logs (configurable retention), chat trash (30d auto-purge), SQLite WAL checkpoint (every 6h), database rotation backup, Qdrant segment optimization, browser zombie detection (48h threshold), Kanban GC, incognito auto-wipe (1h)
  • MemoryGuardian: Adaptive maintenance frequency — every 6h when healthy, every 2h when degraded. Health scoring (70 normal / 35 critical) drives automatic force maintenance after 2 consecutive unhealthy checks
  • File Access Tracking: Prevents accidental deletion of referenced context files via file_access_tracker
  • Scheduler Health API: Real-time green/yellow/red status monitoring for all background schedulers
  • Hot Backups: Automatic SQLite hot backup after every maintenance cycle
Verified: 413 tests passed across all data lifecycle modules (server lifecycle: 265 passed, harness lifecycle: 90 passed, cron + memory: 58 passed).

Skill Evolution — Self-Improving Agent

Myrm’s agents learn from failures and evolve their skills autonomously:
  • Automatic Evolution: When a skill fails or receives negative feedback, the system generates an evolution proposal that updates the skill itself — not a temporary prompt patch
  • Review Lifecycle: Safe changes auto-apply; risky ones become reviewable growth cases with approve/reject workflow
  • Semantic Deduplication: Similarity checker prevents skill entropy — duplicate or near-identical skills are caught before saving
  • Experience Ledger: Every evolution event (14 types) is permanently recorded for audit and analytics
  • Quality Alerts: Webhook notifications when skill quality degrades, enabling proactive maintenance
Verified: 489 tests passed across all skill evolution modules (server: 107 passed, harness framework: 382 passed).

What Users Experience

All recovery happens transparently:
  • Model goes down? — Automatic switch to backup in milliseconds
  • Network drops? — Stream resumes from the exact token where it stopped
  • Rate limited? — Key rotation or backoff, then retry
  • API key expired? — One-click button to update it, right in the error card
  • Agent loops? — Detected early, before wasting budget
  • Response truncated? — Text truncation: seamless keep+continue with progressive output boost (2x/3x/4x, cap 32768); Tool truncation: discard invalid + auto-retry; JSON truncation: local repair. Output-cap auto-recovery across 5 provider formats (Anthropic, OpenRouter, LM Studio, vLLM, DashScope). SSE status notification in 5 languages. 388 output-cap + 294 truncation/recovery tests verified (Jul 2026)
  • Upgrade interrupted? — Pre-migration snapshot restores your data automatically
  • Child agent crashes? — Error auto-compacted, parent receives a clean summary, reasoning stays unpolluted
  • Tool call fails? — Silent retry with heartbeat timer; you see “running… 15s” instead of an error
  • Stream error with actionable recovery? — Errors include recovery_actions buttons (retry, switch model, install dependency) directly in the chat UI, plus diagnostic_result with i18n error messages and step-by-step resolution guides. No guesswork needed — just click the suggested action
  • Repeated failures? — 3-Strike protocol auto-escalates to ask for your help — no infinite loops
  • Environment broken? — Doctor Dashboard runs 9 parallel diagnostic probes (Python version, dependencies, LLM connectivity, network, workspace storage, database, browser, hooks, desktop control) and shows health status at a glance with one-click repair actions. Unlike CLI-only competitors that require terminal access, the GUI health cards display real-time status with actionable fix buttons
  • SSE disconnects mid-task? — Goal progress panel auto-clears stale indicators on reconnect, re-syncs from server, and preserves completed steps. No ghost spinners, no misleading “in progress” after the agent has stopped
  • Cancel a running task? — End-to-end cancellation propagates through the entire execution chain within 0.5s (CancellationMonitor polling interval). Background jobs killed, subagents cascade-cancelled, resources cleaned up, token registry unregistered
  • Disconnect during long task? — Grace period tolerance keeps the task alive. If disconnection persists, OfflineDurableTask registers the work for background completion with user notification on finish. Background processes (npm install, webpack watch, test suites) are managed by a process-level singleton registry completely decoupled from the SSE stream — refreshing the page or reconnecting never kills live daemon sessions. SSE reconnection uses Last-Event-ID with a 5MB sliding window buffer for lossless event replay. 108 tests verified across 4 batches (registry, streaming, reconnect)
  • Server restarts mid-goal? — Orphaned goals auto-pause with clear reason. Durable tasks resume from LangGraph checkpoint on next startup — zero repeated work
  • Process crash during normal conversation? — InterruptedTurnMarker writes a durable write-ahead record before every agent stream. On restart, eligible markers are scanned and automatically dispatched for background continuation with chat history reload, message persistence, crash-loop breaker (max 2 attempts), 15-minute freshness window, and user notification on success or failure. User-controllable via autoContinueInterruptedTurns setting (default: enabled)
  • Emergency halt needed? — E-Stop API (/freeze) cancels ALL active agent streams globally in one call — the panic button for production incidents