Skip to content

Commit 0b5abdb

Browse files
SunkenInTimeclaude
authored andcommitted
fix(server): keep anchor tie order and loosen the plan assertion
Index turn_item_id with the user-message anchors so ties at the anchor cutoff come back in the same order as the thread/ordinal index. Assert only the payload join and the missing outer sort instead of the whole top-level plan. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4e26094 commit 0b5abdb

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,12 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
633633
windowPlan.map((row) => row.detail).join("\n"),
634634
/SEARCH item USING INDEX orchestration_v2_projection_turn_items_user_message_idx \(thread_id=\? AND ordinal<\?\)/,
635635
);
636-
assert.deepEqual(
637-
windowPlan.filter((row) => row.parent === 0).map((row) => row.detail),
638-
[
639-
"MATERIALIZE retained",
640-
"SCAN retained",
641-
"SEARCH item USING INDEX sqlite_autoindex_orchestration_v2_projection_turn_items_1 (turn_item_id=?)",
642-
],
636+
const topLevel = windowPlan.filter((row) => row.parent === 0).map((row) => row.detail);
637+
assert.include(
638+
topLevel,
639+
"SEARCH item USING INDEX sqlite_autoindex_orchestration_v2_projection_turn_items_1 (turn_item_id=?)",
643640
);
641+
assert.notInclude(topLevel, "USE TEMP B-TREE FOR ORDER BY");
644642
const nodeStatement = statements.find((statement) =>
645643
statement.includes("WITH RECURSIVE retained"),
646644
);

‎apps/server/src/persistence/Migrations/060_ThreadSnapshotWindowIndexes.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default Effect.gen(function* () {
99
// find a few dozen of them. ProjectionStore's turn_anchors CTE relies on it.
1010
yield* sql`
1111
CREATE INDEX IF NOT EXISTS orchestration_v2_projection_turn_items_user_message_idx
12-
ON orchestration_v2_projection_turn_items(thread_id, ordinal)
12+
ON orchestration_v2_projection_turn_items(thread_id, ordinal, turn_item_id)
1313
WHERE type = 'user_message'
1414
`;
1515
// The same snapshot keeps every unfinished node. A long thread has thousands

0 commit comments

Comments
 (0)