2026-07-16 18:13:34 +08:00
<!-- Generated by scripts/gen-website-api.ts — do not edit by hand. Run `pnpm run gen-website-api` to regenerate. -->
# ctx.sessionPersistence
`SessionPersistence` (abstract seam) — provided by `@deepseek-ai/dsh-session-persistence` .
2026-07-16 21:36:43 +08:00
Durable append-only session storage. Implementations preserve contiguous, losslessly JSON-serializable events; append resolves only after durability, and load balances a complete interrupted tail without rewriting committed events.
2026-07-16 18:13:34 +08:00
2026-07-17 21:19:33 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/session-persistence/session-persistence/src/index.ts#L42 )
### ctx.sessionPersistence.locate(meta)
```ts website-api
2026-07-19 14:14:02 +08:00
/**
* Resolve this backend's independent local artifact for a session without
* reading, creating, flushing, or otherwise materializing it. Backends such
* as SQLite that do not own one artifact per session return ` undefined`.
* @param meta - the immutable session header whose artifact is requested.
* @returns the backend-specific absolute location, when one exists.
*/
2026-07-17 21:19:33 +08:00
abstract locate(meta: SessionHeader): SessionLocation | undefined
` ``
Resolve this backend's independent local artifact for a session without reading, creating, flushing, or otherwise materializing it. Backends such as SQLite that do not own one artifact per session return ` undefined`.
- ` meta` — the immutable session header whose artifact is requested.
**Returns** the backend-specific absolute location, when one exists.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/session-persistence/session-persistence/src/index.ts#L54)
2026-07-16 18:13:34 +08:00
### ctx.sessionPersistence.create(meta)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Register a new session's metadata. A backend MAY defer the physical write
* until the first {@link append} (lazy materialization), in which case a
* created-but-never-appended session is absent from {@link list}
* — abandoned sessions leave nothing behind.
* @param meta - the immutable header (id, version, cwd, lineage) to record.
*/
2026-07-16 18:13:34 +08:00
abstract create(meta: SessionHeader): Promise<void>
` ``
Register a new session's metadata. A backend MAY defer the physical write until the first append (lazy materialization), in which case a created-but-never-appended session is absent from list — abandoned sessions leave nothing behind.
- ` meta` — the immutable header (id, version, cwd, lineage) to record.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/session-persistence/session-persistence/src/index.ts#L63)
2026-07-16 18:13:34 +08:00
### ctx.sessionPersistence.append(id, events)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Durably persist a batch of events (called from the write-behind drain at
* the ` session/flush` checkpoint). Honors the append-only and contiguous-seq
* contracts: the first event's ` seq` MUST equal the stored next-seq (after
* ` load` has durably closed any interrupted turn). Rejects non-JSON-
* serializable ` event.data` with an error naming the offending event type.
* @param id - the session the batch belongs to.
* @param events - the contiguous batch to persist, in seq order.
*/
2026-07-16 18:13:34 +08:00
abstract append(id: SessionId, events: readonly SessionEvent[]): Promise<void>
` ``
Durably persist a batch of events (called from the write-behind drain at the ` session/flush` checkpoint). Honors the append-only and contiguous-seq contracts: the first event's ` seq` MUST equal the stored next-seq (after ` load` has durably closed any interrupted turn). Rejects non-JSON- serializable ` event.data` with an error naming the offending event type.
- ` id` — the session the batch belongs to.
- ` events` — the contiguous batch to persist, in seq order.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/session-persistence/session-persistence/src/index.ts#L74)
2026-07-16 18:13:34 +08:00
### ctx.sessionPersistence.load(id)
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Load a header and balanced contiguous log. A complete interrupted final
* turn is preserved and durably closed with missing tool errors plus any open
* step and turn boundaries; only a torn final record is discarded. Unknown
* versions and corruption in the committed prefix reject.
* @param id - the persisted session to reload.
* @returns the header and a log ending on a balanced ` turn/end`.
*/
2026-07-16 18:13:34 +08:00
abstract load(id: SessionId): Promise<{ meta: SessionHeader; events: SessionEvent[] }>
` ``
2026-07-16 21:36:43 +08:00
Load a header and balanced contiguous log. A complete interrupted final turn is preserved and durably closed with missing tool errors plus any open step and turn boundaries; only a torn final record is discarded. Unknown versions and corruption in the committed prefix reject.
2026-07-16 18:13:34 +08:00
- ` id` — the persisted session to reload.
2026-07-16 21:36:43 +08:00
**Returns** the header and a log ending on a balanced ` turn/end`.
2026-07-16 18:13:34 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/session-persistence/session-persistence/src/index.ts#L84)
2026-07-16 18:13:34 +08:00
### ctx.sessionPersistence.list()
` ``ts website-api
2026-07-19 14:14:02 +08:00
/**
* Lightweight listing from metadata, without a full-log parse.
* @returns one header per materialized session.
*/
2026-07-16 18:13:34 +08:00
abstract list(): Promise<SessionHeader[]>
` ``
Lightweight listing from metadata, without a full-log parse.
**Returns ** one header per materialized session.
2026-07-17 21:19:33 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/session-persistence/session-persistence/src/index.ts#L90 )