Architecture: How should agent loop state survive process crashes?

Documentation for Sessions

🏗️ Architecture: How should agent loop state survive process crashes?

Date: 2026-03-11
Time: 04:20:27 UTC
Session: gspace1-202.4
Agent: backend
Confidence: 90%
Status: ✅ Documented


📋 Decision Context

Question:

How should agent loop state survive process crashes?

Task: S202 Phase 4.1 checkpoint persistence


🎯 Decision Made

Chosen:

Redis-backed CheckpointService with save before each LLM call and clear on completion. @Optional injection so missing Redis doesn't break anything. Key format: checkpoint:{taskId}, TTL = task timeout.

Options Considered:

  1. Redis checkpoint (chosen)
  2. MongoDB checkpoint (too slow for per-iteration)
  3. BullMQ job data (couples to queue impl)
  4. In-memory only with faster recovery (no real persistence)

💭 Reasoning

The agent loop holds ephemeral state (messages, tool records, cost state) that's lost on crash. MongoDB is too slow for per-iteration writes. Redis with TTL is the right balance: fast writes, automatic cleanup, and the existing RedisService already handles reconnection. Made it @Optional so tests and environments without Redis work unchanged.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation