Skip to content

[Bug]: Completed-compaction lookup scans long conversations #45838

Done

Description

@Alb11747

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. In SQLite, use the turn-item index definitions from migrations 082 and 088.
  2. Insert 30,000 completed user_message or assistant_message turn items for one thread. Leave it without a completed compaction, or add one completed compaction near the beginning.
  3. Run EXPLAIN QUERY PLAN on the runIdsSinceLastCompaction query in ProjectionStore.ts for that thread.

Expected behavior

The compaction lookup seeks directly to completed compaction items for the thread.

Actual behavior

The query forces the conversation index. SQLite can constrain only thread_id and walks the conversation items until it finds a completed compaction or runs out of rows. This is the first lookup before the read can use its post-compaction window.

In an in-memory SQLite fixture with 30,000 conversation items, the query took a median of 8.56 ms with no compaction and 8.93 ms with an old completed compaction and a later rolled-back one. Using the existing thread/type/status index constrained all three columns and returned the same run IDs in 0.018 ms and 0.030 ms, respectively. These are SQL statement measurements from nine warm runs per case. I did not measure end-to-end prompt latency.

Impact

Minor bug or occasional failure

Version or commit

main @ 589c443725be1e578a4aa10239708066e9fdbf82

Environment

Windows, Python SQLite, synthetic database. Any provider.

Logs or stack traces

Current: SEARCH item USING INDEX orchestration_v2_projection_turn_items_conversation_idx (thread_id=?)
With type/status index: SEARCH item USING INDEX orchestration_v2_projection_turn_items_thread_type_idx (thread_id=? AND type=? AND status=?)

#43549 improved a separate status-filtered turn-item read. The compaction CTE still forces the conversation index.

Created with GPT-6.2 Sol in T3 Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions