DSH plugin session query: bounded reads, traces and search
DSH plugin session query has two faces: exact reads and trace relationships, which are backend-independent, and full-text search, whose index lifetime belongs to the provider. Both share the live-preferred premise — when an id exists in memory and on disk, data comes from the live source, with live and persisted flags reported separately. The most common misuse is filter combination semantics: arrays AND together, values within a clause OR together, ranges are inclusive; and text clauses scan semantic text literally rather than acting as executable FTS syntax.
DSH plugin session query API: exact reads and full-text search
Bottom line: exact reads, filters and traces share one abstract service; the provider owns indexing and swapping it keeps the vocabulary.
- Backend-independent: bounded reads, filters, traces, lineage and title observation.
- Backend-related: full-text observation, reconciliation, ranking, cursor generations and query execution.
- One entry point: everything hangs off
ctx.sessionQuery. - Selection: exact reads when you need a specific event and its context; search when you need "which sessions mention X."
- Rule of thumb: require stable order and exact seqs for reads, relevance ranking for search.
DSH plugin logical records: availability flags and one-shot snapshots
Bottom line: SessionRecord reports availability; the snapshot types are observations, not subscriptions.
| Type | Contents | Use |
|---|---|---|
SessionRecord | header + live + persisted | Listing and provenance |
SessionLogSnapshot | header, inherited count, validated raw log | Restore preflight |
SessionSurfaceSnapshot | header, captured seq, surface events | Exact surface read |
- Listings cover the corpus:
listSessions()returns deterministic newest-first records. - Snapshots are one-shot: re-read to refresh.
- Surface classification:
current,shadowed,log-onlydistinguish current context, replaced context and raw-log-only. - Title observation follows the same rule: batch results come in request order, one failure affects only that id, and cancellation rejects the whole call.
- Do not treat persisted as live: persisted-only sessions go through cold reads with different semantics.
DSH plugin filters: AND, OR and literal text scans
Bottom line: arrays AND, clauses OR, ranges inclusive; text is a literal scan, not an executable query language.
const sessions = await ctx.sessionQuery.filterSessions([
{ kind: 'cwd', values: ['/work/a', '/work/b'] },
{ kind: 'created-at', from, to },
])
- Session filters:
id,cwd,created-at,parent,availability. - Event filters:
seq,time,type,surface,text. - Text rule: literal, Unicode case-insensitive, whitespace-flexible.
- Semantic text scope: messages, tool calls and results, todos, failures and status details are included; reasoning blocks, blocked prompts, structural events and stream chunks are not.
- Ordering:
filterEventsreturns matching documents by ascending seq.
DSH plugin full-text search: grouped hits, in-session hits and cursors
Bottom line: cross-session search groups by strongest event; in-session search returns events and always the target header.
- Cross-session:
searchSessions({ query, sessionFilters, eventFilters, limit, cursor }), each group carryingbestMatch. - In-session:
searchEvents({ sessionId, query, filters, limit, cursor }), returning the target header even with zero hits. - Query is data: text is interpreted as data, never as executable FTS syntax.
- Cursor binding: a cursor is bound to the normalized query, metadata filters and limit; changing any of them restarts the search.
- Metadata filters only: provider filters exclude text scanning and apply before ranking.
- Pagination:
itemsplus an optionalnextCursor, absent on the last page.
DSH plugin bounded reads, event traces and lineage
Bottom line: reads give raw windows, traces give replacement chains and citations, lineage gives ancestors and descendant trees.
- Bounded reads: a request specifies the target seq plus before/after counts and returns a window with
startSeq/endSeq; the result carries a header rather than availability flags. - Replacement relations:
replacedByis the immediate replacer,replacementChainreaches the final replacement, andreplacedEventSeqslists positional nodes this event removed. - Citation relations:
sourceEventSeqsare earlier cited events,derivedEventSeqsare later events citing this one. - Lineage:
ancestorsnearest-first,descendantsas a recursive forest;complete: falsesuppliesunresolvedParentIdrather than pretending to be a root. - Stable errors:
EVENT_NOT_FOUND,INVALID_CURSOR,STALE_CURSOR,SEARCH_DISABLED,INDEX_FAILEDandSOURCE_CONFLICTare codes — branch on them, not on message text.
DSH plugin session query troubleshooting
Bottom line: separate no results, slow results and odd order — filter semantics, indexing and ordering contracts.
- No results — check AND/OR semantics and whether text was treated as syntax.
- Zero in-session hits — normal:
itemsis empty but the header is still returned. - Stale cursor — the query or limit changed; restart the search.
- Unexpected order — search ranks by relevance; only exact reads are seq-ascending.
- Incomplete lineage — read
completeandunresolvedParentId; do not invent a root. - Repair status, stated honestly: record types, filter semantics, search requests and error codes follow the official Session query page; confirm signatures against its Cordis API and your version.
Sources: Session query, session-query package, Session persistence.
FAQ
DSH plugin sessionQuery is live-preferred: when an id exists both in memory and on disk, records and events come from the live source. SessionRecord exposes live and persisted availability separately so you can see where data came from.
In DSH plugin session filtering, items in a filter array are ANDed while values inside one clause are ORed, and ranges are inclusive. A text clause scans extracted semantic text literally, case-insensitively, with flexible whitespace.
DSH plugin searchSessions groups the corpus by the strongest matching event and includes a bestMatch per group, while searchEvents searches one session and always returns the target header even with zero hits. Both paginate with opaque cursors bound to the normalized request.
A DSH plugin bounded read centers on the target seq and includes the requested number of raw events before and after, returning a window with start and end seqs. It gives raw log context rather than the projected surface.
In DSH plugin event traces, replacedBy gives only the immediate replacer's seq, while replacementChain follows direct replacers through to the final positional replacement. Use the chain when you need the final replacement.
Related Terms
- SessionQueryEngine
- SessionQueryEngine is the abstract service behind ctx.sessionQuery, providing live-preferred exact reads, filters, traces and full-text search. Exact reads and traces are backend-independent while index lifetimes belong to the provider.— https://deepseek-harness.github.io/deepseek-harness/reference/subsystems/session-query
- SessionEventSurface
- SessionEventSurface classifies an event within the folded surface as current model context, shadowed context, or log-only presence, using the values current, shadowed and log-only.— https://deepseek-harness.github.io/deepseek-harness/reference/subsystems/session-query
- SessionSearchCursor
- SessionSearchCursor is a provider-owned opaque continuation token bound to the normalized query, metadata filters and result limit. Changing any of them invalidates the cursor.— https://deepseek-harness.github.io/deepseek-harness/reference/subsystems/session-query
- SessionLineageTrace
- SessionLineageTrace describes the known ancestors and descendant forest of one logical session, ancestors ordered nearest-first. Its completeness field makes a known root mutually exclusive with a missing parent.— https://deepseek-harness.github.io/deepseek-harness/reference/subsystems/session-query
Sources
- DeepSeek Harness docs — Session query (records, filters, search pages, lineage, bounded reads, errors)· deepseek-harness.github.io
- session-query package (exact reads, traces and provider-independent filters)· deepseek-ai (GitHub)
- DeepSeek Harness docs — Session persistence (read handles and cold-read cache)· deepseek-harness.github.io