How DeepSeek Harness Persists Session Events
DeepSeek Harness represents a session as an append-only event log, derives model-visible messages from that log, and relies on a separately mounted persistence provider to make events durable. A message visible in memory is not, by itself, evidence that it has survived a crash.
DeepSeek Harness: what is actually stored?
The session reference describes a Session as an in-memory, event-sourced log. Its typed SessionEvent records are the source of truth for an agent's interaction. The model's message history is derived from those events; it is not maintained as a second, separately stored conversation. Replaying the log re-derives the history.
The distinction matters when an operator compares a transcript with storage. The log contains more than messages: for example, turn and step boundaries describe execution, while message-producing events contribute to a model-visible surface. An assistant message can include usage when the adapter reports it and the exact compact raw stream for that attempt. If a turn is cancelled mid-stream, an emitted assistant message can carry interrupted: true; a cancelled turn without such an event streamed no visible content. These records describe different facts and should not be flattened into an assumed list of complete answers.
| Layer | Responsibility | What it does not prove |
|---|---|---|
| Session event log | Ordered interaction and execution records | That a storage provider has persisted them |
| Model-visible surface | Derive current messages from surface operations | That every original message remains visible to the model |
| Persistence handle | Read and append a session's stored log | That every acknowledged append has crossed the crash-durability barrier |
| Header | Store metadata beside the log | That its fields are conversation messages |
The surface is a projection, not a second event store. An append operation normally adds a message to the tail. A replacement can shadow an existing surface span and insert a new event in its place, while the original events remain in the append-only log. The human-facing transcript uses append-origin events, so it need not equal the model-visible surface after a replacement. This difference is especially important when investigating a compacted conversation: a record may remain in the log without remaining in the model's current view.
DeepSeek Harness: how do events reach storage?
The persistence reference separates the storage contract from the session model. ctx.sessionPersistence offers create, open, stat, and list; create and open return a per-session SessionHandle. The handle supplies read, append, flush, and close, and carries access and single-writer ownership. The repository ships a JSONL provider, while another provider can implement the same contract. The API describes a seam, not a promise that every deployment uses the same backend.
The session store itself is in memory. The agent lifecycle attaches a session-log writer to each published session's write handle; a session published outside that lifecycle persists nothing. Consequently, seeing a session object or an event in a live process is not enough to infer durable storage. Check the actual composition and lifecycle, not only the presence of the session API.
The persistence backend routes synchronous session/event notifications into a bounded write-behind window for the active write handle. The first pending event starts a fixed batching window; later arrivals join it without resetting the deadline. When it expires, a durable append starts. Events arriving during that write form a follow-up batch. This is a deliberately asynchronous path: the notification does not wait for the producer's storage operation to finish.
DeepSeek Harness: when is an event durable?
A successful handle append and a successful flush answer different questions. The contract says only a resolved flush promises that acknowledged appends survive a crash. A backend may persist earlier, but a caller that needs a durability barrier must not assume that it did. session/flush cancels the batching wait and drains through quiescence; the loop uses it as an ordering and error-observation checkpoint before claiming the next ordinary turn.
The session reference also notes that the loop does not await a flush at turn boundaries. A producer needing an immediate durability barrier explicitly awaits ctx.sessions.flush(session). A turn-end event is therefore not a substitute for observing the relevant flush outcome. close() on a write handle completes pending durability and releases ownership; disposal also drains and closes the handle. Do not infer successful teardown merely from the intention to close it: observe the actual result.
A failed background write retains its events in order, pauses the automatic path, and is logged. The next explicit flush retries and reports failure to its caller if it cannot complete. This gives a concrete troubleshooting sequence: inspect the original failure, then observe the explicit flush result. The batching window bounds intentional waiting, not event-loop scheduling or storage latency; it is not a maximum time-to-durability guarantee.
DeepSeek Harness: what happens after a crash?
An interrupted turn can contain many successfully persisted events. The persistence layer returns the physically valid contiguous log instead of discarding the entire open turn. An incomplete fragment of a torn physical tail from an append that never resolved is discarded. The documented JSONL backend can partially decode a torn Zstandard frame; recovered complete records are durably rewritten on the write path before its first new append.
Resuming is a separate step from reading the raw valid prefix. The agent loop obtains write ownership, computes missing closers for an interrupted turn—including missing tool errors, any open step/end, and a synthetic turn/end whose reason is interrupted—and appends them before publishing the session. A read-only observer balances the same kind of cold log in memory without writing those closers back. Thus a repaired read-only projection does not prove the underlying file was modified.
The write handle prevents two live in-process owners from racing: a second open(id, 'write') rejects with SessionAlreadyOwnedError while an owner is active. A read handle is different: mutation on it raises SessionReadOnlyError. Reads return validated contiguous prefix slices, omit torn tails, and do not move backwards on repeated reads through the same handle. These properties do not give an operator license to edit a live backend artifact by hand.
DeepSeek Harness: how should I investigate missing history?
- Separate the live view from the stored view. Determine whether the session was published through the lifecycle that attaches its writer, and identify the active persistence provider.
- Compare the event log, the human transcript, and the model-visible surface. A surface replacement can change the latter without erasing the original append-origin records.
- Establish the last confirmed durability checkpoint and inspect errors. A live event, an acknowledged append, a turn boundary, and a resolved flush are not interchangeable evidence.
- If recovering after interruption, inspect the valid stored prefix and distinguish a torn physical tail from a logically open turn. Let the documented resume path perform write-owned repair; read-only balancing is not a persistent repair.
- Check ownership and provider-specific diagnostics before retrying. Keep a protected copy of relevant evidence where operationally appropriate, and avoid changing an actively owned log.
The header is another useful boundary. It carries metadata such as the format version, session ID, creation time, optional working directory, parent session, and seeded-lineage flag alongside the log. It is not part of SessionEventMap and does not enter derived messages. A fork's inherited event count is session state rather than ordinary header metadata. A created session can be visible in the creating process before a backend physically materializes it; if it never materializes before a crash, other processes cannot recover it as an existing stored session.
DeepSeek Harness: what are the limits and safety boundaries?
These are documented contracts, not a guarantee that a particular deployment has mounted the JSONL provider or that every storage failure is recoverable. The session and persistence references do not give a universal directory or a universal recovery command for all providers. Consult the installed provider and version instead of guessing a file path or manually deleting a tail.
Session logs and diagnostics can contain prompts, tool output, paths, and other sensitive data. Restrict access and review material before sharing it. A flush is a durability barrier, not a confidentiality control; successful replay does not establish that the recorded instructions or tool actions were safe. If the storage format is unsupported, preserve the evidence and use the provider's refusal diagnostics rather than forcing an interpretation.
DeepSeek Harness: what do the terms mean?
- Event log: the append-only sequence of typed session records.
- Surface: the current model-visible projection produced from message events and their placement operations.
- Persistence provider: an implementation of the storage service contract.
- Write handle: a per-session channel carrying write ownership and log operations.
- Flush: the explicit durability barrier for acknowledged appends.
- Torn tail: an incomplete physical end fragment, distinct from a valid but interrupted turn.
Frequently asked questions
Are model messages stored separately from events?
No. The session reference describes model message history as derived from the event log.
Does an append guarantee crash durability?
Only a resolved flush promises crash durability for acknowledged appends under the documented handle contract.
Does recovery discard an entire interrupted turn?
No. The valid contiguous log is retained; resume appends missing closers under write ownership.
Sources
Every claim in this article was checked against the sources below. Community discussions are user reports, not official behavior.
This is an independent community article, not official DeepSeek documentation. Listing a plugin in the registry is not a security review.