How Memory Mechanisms Work in Coding Agents: Append-Only Logs and Checkpoints
This article explains the design principles behind memory in intelligent coding agents, using the session persistence backend and checkpoint strategy of a coding tool (version 0.1.1-rc.2) as a reference. It shows why agents without memory suffer from context loss, broken references, and poor auditability, then breaks down the memory model into an append-only event log, checkpoints, and recovery. Readers will learn how session files are organized, why events are never rewritten, how packing and streaming compression reduce overhead, and how checkpoints force data to disk at key moments to ensure reliability. The content is based on logs from two real local tasks.
1. The Starting Point: Why Agents “Forget”
When a coding agent is working in a large codebase and has already modified three files, what happens if the process suddenly crashes? After a restart, does it remember where it left off? The answer depends entirely on whether the underlying harness has memory capabilities.
An agent without memory typically shows three kinds of failures:
- Context gaps: When the user asks “where did we leave off?”, it cannot answer.
- Broken references: In a multi-turn conversation, when the user says “modify that function again,” it cannot resolve what “that” refers to.
- No auditability: When something goes wrong, there is no way to trace what operations it actually performed, leaving troubleshooting without evidence.
So the memory approach for an agent can be abstracted into one equation:
Memory = an append-only log + records + checkpoints + recovery
This article uses two components of a coding tool—the session persistence backend and the checkpoint strategy (version 0.1.1-rc.2)—as the observation target. Combined with logs left by two real tasks on a local machine, it unpacks these three things one by one.
2. Look at the Artifact First: Memory Files Left by a Task
After two real tasks (demo-001 and demo-002) finished, a session directory was generated outside the workspace, in the following form:
sessions/--Users-Apple-projects-deepseek_harness-workspace--/demo-002/session.jsonl.zstd
What each path segment means:
sessions: the session root directory, kept separate from the code workspace to avoid polluting the repository;- the escaped middle segment: the encoded result of the workspace’s absolute path (
--Users-Apple-...--corresponds to/Users/Apple/projects/deepseek_harness/workspace), which keeps sessions from different workspaces from crossing over; demo-002: the session identifier;session.jsonl.zstd: the log body itself, in JSONL format compressed with zstd. Once decompressed it is plain text, with one JSON event per line.
After decompression, the file has 62 lines, meaning 62 events. The first line is the session header, recording metadata such as the session identifier, creation time, workspace path, and delegationDepth (delegation depth, 0 for a top-level session and increasing level by level for sub-agent sessions). The session header is immutable—identity is fixed on the first line, and afterward only events are appended, never written back.
3. Records: An Append-Only Event Stream
“Append-only” is the most core semantic of this log, showing up on three levels.
First, lines that have been written are never rewritten. Events are appended continuously by seq number, and events already written to disk are not modified or deleted. This is not an implementation detail but a deliberate design: the log is the single source of truth, and rewriting history is equivalent to faking memory.
Second, packing and compression save space. Log lines and events are not strictly one-to-one: when a large number of similar events appear in a row (for example, model output split into dozens of small fragments), the backend packs them into one line, reducing line count and compression overhead.
Third, the write path stays as lightweight as possible. Append writes naturally fit sequential I/O, and combined with streaming compression, disk usage can be kept within an acceptable range during long tasks.
A schematic event structure:
{"seq":17,"type":"tool_result","ts":"...","payload":{"name":"edit_file","ok":true}}{"seq":18,"type":"assistant_delta","ts":"...","payload":{"text":"fragment"}}
4. Checkpoints: Forcing Data to Disk at Key Moments
Append-only solves “not losing history,” but high-frequency writes can still cost performance at a fine granularity, and the moment of a crash may leave an incomplete tail. The checkpoint strategy is responsible for forcing writes to complete at key moments:
- Trigger timing: turn boundaries, before and after tool calls, and task phase switches;
- Integrity guarantee: ensuring confirmed events are fully written to disk, avoiding half a record;
- Tail fault tolerance: on recovery, discarding unclosed residual lines to keep the log parseable.
In engineering terms, checkpoint frequency is a matter of reliability
