Code Agent Dissection (10): When the Agent Crashes, How Does It Recover? Where Is Conversation History Stored?
Description and use
MyCodeAgent uses an event stream in JSONL format to recover conversation history and tool state after crashes, eliminating data loss and incomplete file edits.
Problem
Agent conversation history is lost on crash and tool calls may leave files in an inconsistent state.
Outcome
Using an event‑stream transcript, MyCodeAgent restores conversation history and tool state after crashes, eliminating data loss and inconsistent file edits.
Workflow
- 1. Agent emits events (message, state_transition, tool_lifecycle, checkpoint, terminal).
- 2. RuntimeRunner forwards events to CompositeRuntimeEventSink.
- 3. CompositeRuntimeEventSink writes events to two sinks: TraceRuntimeEventSink (debug) and TranscriptRuntimeEventSink.
- 4. TranscriptRuntimeEventSink records events via TranscriptRecorder.
- 5. TranscriptRecorder appends each event to a JSONL file using TranscriptStore.append_event().
- 6. TranscriptStore repairs any incomplete trailing line before writing.
- 7. On restart, the agent reads the transcript file, replays events to rebuild HistoryManager and tool state.
Evidence
Once the process crashes — network timeout, OOM, Ctrl+C — all that history is gone.
MyCodeAgent solves both problems with Transcript: continuously writing all key facts to an append‑only JSONL file, then rebuilding runtime state from the file after a crash.
- Record date: 2026-09-06T21:36:54.176Z