@@ -5784,6 +5784,10 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
57845784 )` ;
57855785 } ;
57865786
5787+ // One bound JSON array instead of one parameter per id: SQLite caps a statement at 32,766.
5788+ const inJsonList = ( ids : ReadonlyArray < string > ) =>
5789+ sql `(SELECT value FROM json_each(${ encodeIdList ( ids ) } ))` ;
5790+
57875791 const selectShellThreadRows = (
57885792 threadId ?: ThreadId ,
57895793 {
@@ -5988,7 +5992,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
59885992 worktreePath === undefined
59895993 ? sql ``
59905994 : sql ` AND json_extract(t.payload_json, '$.worktreePath') = ${ worktreePath } `
5991- } ${ threadIds === undefined ? sql `` : sql ` AND t.thread_id IN ${ sql . in ( threadIds ) } ` }
5995+ } ${ threadIds === undefined ? sql `` : sql ` AND t.thread_id IN ${ inJsonList ( threadIds ) } ` }
59925996 ORDER BY t.updated_at ASC, t.thread_id ASC
59935997 ` ;
59945998
@@ -6001,14 +6005,14 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60016005 : sql < ShellRunRow > `
60026006 SELECT thread_id, run_id, ordinal
60036007 FROM orchestration_v2_projection_runs
6004- WHERE thread_id IN ${ sql . in ( threadIds ) }
6008+ WHERE thread_id IN ${ inJsonList ( threadIds ) }
60056009 ` ;
60066010
60076011 const selectShellRunItemCounts = ( threadIds : ReadonlyArray < ThreadId > ) =>
60086012 sql < ShellRunItemCountRow > `
60096013 SELECT thread_id, run_id, COUNT(*) AS item_count
60106014 FROM orchestration_v2_projection_turn_items
6011- WHERE run_id IS NOT NULL AND thread_id IN ${ sql . in ( threadIds ) }
6015+ WHERE run_id IS NOT NULL AND thread_id IN ${ inJsonList ( threadIds ) }
60126016 GROUP BY thread_id, run_id
60136017 ` ;
60146018
@@ -6023,7 +6027,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60236027 FROM (
60246028 SELECT thread_id, run_id, COUNT(*) AS item_count
60256029 FROM orchestration_v2_projection_turn_items
6026- WHERE thread_id IN ${ sql . in ( threadIds ) }
6030+ WHERE thread_id IN ${ inJsonList ( threadIds ) }
60276031 GROUP BY thread_id, run_id
60286032 ) counts
60296033 LEFT JOIN orchestration_v2_projection_runs r ON r.run_id = counts.run_id
@@ -6040,7 +6044,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60406044 : sql < PayloadRow & { readonly thread_id : string } > `
60416045 SELECT thread_id, payload_json
60426046 FROM orchestration_v2_projection_provider_threads
6043- WHERE thread_id IN ${ sql . in ( threadIds ) }
6047+ WHERE thread_id IN ${ inJsonList ( threadIds ) }
60446048 ` ;
60456049
60466050 const selectShellPendingTurnItemRows = (
@@ -6056,7 +6060,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60566060 WHERE i.type IN ('command_execution', 'dynamic_tool', 'subagent')
60576061 AND i.status NOT IN ('completed', 'interrupted', 'failed', 'cancelled')
60586062 AND (i.run_id IS NULL OR r.status <> 'rolled_back')
6059- ${ threadIds === undefined ? sql `` : sql `AND i.thread_id IN ${ sql . in ( threadIds ) } ` }
6063+ ${ threadIds === undefined ? sql `` : sql `AND i.thread_id IN ${ inJsonList ( threadIds ) } ` }
60606064 ${
60616065 activeRunIds . length === 0
60626066 ? sql ``
@@ -6065,7 +6069,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60656069 UNION ALL
60666070 SELECT i.thread_id, i.payload_json, NULL AS owning_provider_instance_id
60676071 FROM orchestration_v2_projection_turn_items i
6068- WHERE i.run_id IN ${ sql . in ( activeRunIds ) }
6072+ WHERE i.run_id IN ${ inJsonList ( activeRunIds ) }
60696073 AND i.type IN ('file_change', 'file_search', 'web_search', 'compaction')
60706074 AND i.status IN ('running', 'waiting')
60716075 `
0 commit comments