fix: add session_id fallback conversation index#379
Merged
Conversation
Add the conversations(session_id, active, created_at) composite index used by the session_id fallback lookup so SQLite can satisfy the ORDER BY/LIMIT path without a scan and temp sort. Extend the migration regression test to assert the index exists and that EXPLAIN QUERY PLAN uses it for the lookup shape. Regeneration-Prompt: |\n Improve the session_id-based conversation fallback lookup in lossless-claw without broadening index coverage beyond the hot query shape. The runtime path selects the latest conversation for a given session_id ordered by active DESC then created_at DESC, and the existing migration only created the analogous session_key composite index. Add the matching conversations(session_id, active, created_at) index in the migration path, then update targeted tests to prove the index is present and that SQLite uses it for that ORDER BY/LIMIT lookup without a temp B-tree sort. Keep the change additive and avoid unrelated schema or query changes.
Adjust the migration planner regression to use the same SELECT list as getConversationBySessionId so the assertion validates the real lookup shape instead of a narrower covering-index variant. Regeneration-Prompt: | The new session_id composite index regression should prove the real runtime fallback lookup uses the index, not a simplified proxy query. Update the planner test to run EXPLAIN QUERY PLAN against the same SELECT columns used by getConversationBySessionId and relax the assertion from COVERING INDEX to INDEX while still rejecting any temp B-tree sort.
Add the missing patch changeset for PR #379 so the session_id fallback conversation index fix is release-ready without changing the code or tests in the branch. Regeneration-Prompt: | PR #379 already adds the conversations(session_id, active, created_at) index and targeted tests for the session_id fallback lookup, but it was missing the required Changesets entry before merge. Do not broaden scope or alter the implementation. Add a single patch changeset for @martian-engineering/lossless-claw that briefly describes the performance improvement: the session_id fallback latest-conversation query now uses the matching composite index instead of a scan and temporary sort. Verify only the targeted migration and regression tests relevant to the PR, then commit the changeset addition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the missing composite
conversations(session_id, active, created_at)index so thesession_idfallback lookup can satisfy its orderedLIMIT 1query from an index instead of scanning and sorting. The migration regression test now also verifies the planner uses that index for the runtime query shape.Why
Lossless Claw already indexed the analogous
session_keylookup path, but thesession_idfallback still depended on a scan/sort plan. This change fixes that hot-path asymmetry without adding broader or redundant indexes.Changes
session_id, active, created_atindexTesting
npm test -- --run test/migration.test.tsnpm test -- --run test/regression-2026-03-17.test.tsNo changeset added because this is an internal query-planning/performance fix with no intended user-facing behavior change.