Context Mode
Context Mode architecture: content search and timeline search are different paths
Trace ContentStore, SessionDB and auto-memory through searchAllSources, including partial failures, timestamp assumptions and project filtering.
What you will learn
- Relevance and timeline query different combinations of stores.
- Ascending order plus a limit is not a newest-N timeline.
- Fallback timestamps and partial results need explicit interpretation.
Before you start
- Basic JSON and MCP concepts
- An isolated test client and invented data
Explain the chapter’s actual implementation boundary and verify it with an explicit evidence fixture.
Key takeaways
- Relevance and timeline query different combinations of stores.
- Ascending order plus a limit is not a newest-N timeline.
- Fallback timestamps and partial results need explicit interpretation.
Start with the actual search entry point
src/search/unified.ts exposes searchAllSources. It always attempts a ContentStore search. With the default relevance sort, that is the source handled by this function; it does not also query SessionDB and auto-memory. With timeline sort, the function additionally attempts those two sources and merges their results. This distinction matters when a user asks why a remembered decision is absent from a relevance query.
Within ContentStore, SQLite full-text indexes provide lexical matching and ranking. That is different from asking an embedding model to retrieve semantically similar passages. The session database and adapter-aware memory search are additional information sources, not names for the same table. Draw the architecture as separate stores and query branches so their failure and retention behavior remains visible.
Understand ordering before calling it history
For timeline results, the function normalizes SQLite-style timestamps into an ISO-shaped string, sorts ascending and then slices to the requested limit. Consequently, this implementation’s bounded timeline is not automatically the newest-N view. If the candidate set contains many dated matches, earlier entries can occupy the returned window. Check your question against the ordering rather than interpreting the first result as the latest event.
ContentStore items without a timestamp receive a value captured at the start of this search call. The variable is called sessionStartTime, but its assignment uses the current time inside the function. It is therefore not proof of the original event or indexing time. An audit interface should distinguish actual timestamps from these fallback values instead of presenting every row as a precisely dated historical record.
Treat partial results and project scope carefully
Each source search is wrapped in its own error handler, allowing results from other sources to survive a failure. That improves availability but means a plausible answer can still be incomplete. The reviewed code only emits these caught errors to stderr when its debug flag is enabled. A production evaluation should test a failed source and look for evidence of incompleteness, not merely a nonempty result list.
When a string projectScope and SessionDB are supplied, the function resolves an allowed session-ID set for ContentStore filtering. The store deliberately keeps legacy chunks with empty session IDs visible. If allow-set resolution fails, the local variable remains undefined. These source-level observations are reasons to test strict isolation elsewhere; this helper alone is not a tenant-security guarantee or a complete account of every caller’s protections.
Implementation steps
- 1
Trace searchAllSources with relevance and timeline separately.
- 2
Create dated fixtures and compare the limited result order.
- 3
Exercise an unavailable source and inspect diagnostics.
- 4
Verify project boundaries with both attributed and legacy fixtures.
Copy-ready example
relevance -> ContentStore -> ranked results
timeline -> ContentStore + SessionDB + auto-memory
-> normalize timestamps -> ascending sort -> limit
A missing source can leave a partial result set.Frequently asked questions
Does relevance search always inspect historical sessions?
Not in the reviewed searchAllSources implementation: SessionDB and auto-memory calls are inside the timeline branch.
Can every timeline timestamp be used as an audit timestamp?
No. A ContentStore result without a timestamp receives the current search-call time as a fallback.
Sources
- README.mdSource checked 2026-09-07
- package.jsonSource checked 2026-09-07
- LICENSESource checked 2026-09-07
- src/store.tsSource checked 2026-09-07
- src/search/unified.tsSource checked 2026-09-07
- src/server.tsSource checked 2026-09-07
- src/executor.tsSource checked 2026-09-07
- src/security.tsSource checked 2026-09-07
- src/session/purge.tsSource checked 2026-09-07
- tests/store-bytecap.test.tsSource checked 2026-09-07