description, kind
| description | kind |
|---|---|
| Save and reopen Session histories in SQLite, import existing JSONL histories, and coordinate concurrent readers and writers. | package-reference |
@deepseek-ai/dsh-session-persistence-sqlite
English | 中文
Summary
Save Session histories in SQLite and reopen them through the existing persistence API. Existing JSONL histories import on first open while their source files remain intact. Readers can share a database with an active writer; each Session permits one writer. Choose this provider explicitly: shipped profiles continue to use JSONL.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
Mount this provider for the storage root whose Sessions should use SQLite.
Minimal configuration
Replace the JSONL provider's package name in your composition, preserving its root and legacy encoding settings:
- name: '@deepseek-ai/dsh-session-persistence-sqlite'
config:
root: './.sessions'
The database lives at <root>/.segments/sessions.sqlite. Application callers continue to use ctx.sessionPersistence and its Session handles.
| Field | Default | Meaning |
|---|---|---|
root |
Required | Storage root containing the database and any existing JSONL histories. |
compression |
zstd |
Existing JSONL encoding; SQLite events use ordinary JSON. |
listConcurrency |
3 |
Concurrent filesystem reads for legacy metadata and routing records. |
The generated configuration catalog documents all accepted fields.
Opening existing history
A first read or write open decodes the selected JSONL generation through its version migration chain, then imports the current logical history into SQLite. Import preserves metadata, event order, source coordinates and the inheritance marker. It creates an independent root Segment and retains the JSONL source bytes. The imported Session and its later events reopen through SQLite.
An active JSONL writer retains ownership until it closes. A SQLite read open waits for that ownership; a competing write open rejects. Cancellation or provider disposal stops the wait. After import, readers can open while the SQLite writer remains active. stat() and list() observe metadata without importing history.
Durability and shutdown
Direct append, live Session events and durability checkpoints use the same handle. flush() drains pending events; writer close and provider disposal finish admitted writes before releasing ownership. An automatic write failure retains its pending batch and pauses automatic writes; the next explicit checkpoint retries and reports any remaining failure.
Understand the implementation
Implementation internals — click to expand
The plugin supplies the existing persistence service and uses a JSONL provider in an isolated service context to read legacy histories. Import acquires the Session's artifact lease, commits its metadata and events in a database transaction, then records SQLite routing. A write open retains the lease through the handoff.
SQLite keeps thread metadata, predecessor-linked Segment metadata and indexed JSON event rows. WAL is enabled before schema publication so a concurrent reader cannot prevent the first mode switch. Journal-mode lock contention retries within the five-second busy budget before any schema or Session write; persistent contention and other failures are reported. The backend owns write queues, live-event buffering, transaction completion and handle cleanup; callers do not address Segments.
| Source | Responsibility |
|---|---|
| persistence.ts | Service routing and durable JSONL takeover. |
| migration.ts | Import sequencing, ownership handoff and cancellation. |
| sqlite.ts | Database, Segment access, handles and durability. |
Further Exploration
- Session persistence — the shared service and handle semantics.
- JSONL persistence — physical generations and version migration.
- Persistence subsystem — recovery and consumer-facing APIs.
Model Experience
Restored history
What the model sees
This provider adds no prompt or tool schema. Restored user/message and assistant/message events supply the same conversation history; the Session consumer owns interrupted-turn repair.
Token effect
Storage adds no tokens. Restored history has its usual conversation cost.
KV Cache effect
Storage preserves event order and does not rewrite model request prefixes.
Known Limitations and Deferred Work
These constraints apply when selecting this provider.
- The first legacy read open writes the SQLite database and requires write access to the storage root.
- Retained JSONL files contain the imported prefix and exclude later SQLite events; they cannot restore the latest history on their own.
- All processes writing imported Sessions must use the SQLite provider.
- SQLite accepts the current Session format; a future event-format upgrade needs its own SQLite history migration.
Dev Note
Working context for maintainers — click to expand
None.