@@ -455,6 +455,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
455455 updatedAt : "2026-02-24T00:00:07.000Z" ,
456456 } ,
457457 latestUserMessageAt : "2026-02-24T00:00:04.000Z" ,
458+ hasQueuedTurns : false ,
458459 hasPendingApprovals : true ,
459460 hasPendingUserInput : false ,
460461 hasActionableProposedPlan : false ,
@@ -2405,6 +2406,73 @@ projectionSnapshotLayer("ProjectionSnapshotQuery windowed thread detail", (it) =
24052406 } ) ,
24062407 ) ;
24072408
2409+ it . effect ( "hydrates durable queued messages into command and shell reads" , ( ) =>
2410+ Effect . gen ( function * ( ) {
2411+ const sql = yield * SqlClient . SqlClient ;
2412+ const snapshotQuery = yield * ProjectionSnapshotQuery ;
2413+
2414+ yield * sql `DELETE FROM projection_thread_turn_queue` ;
2415+ yield * sql `DELETE FROM projection_thread_messages` ;
2416+ yield * sql `DELETE FROM projection_thread_sessions` ;
2417+ yield * sql `DELETE FROM projection_thread_proposed_plans` ;
2418+ yield * sql `DELETE FROM projection_turns` ;
2419+ yield * sql `DELETE FROM projection_threads` ;
2420+ yield * sql `DELETE FROM projection_projects` ;
2421+ yield * sql `DELETE FROM projection_state` ;
2422+
2423+ yield * sql `
2424+ INSERT INTO projection_projects (
2425+ project_id, title, workspace_root, scripts_json, created_at, updated_at, deleted_at
2426+ ) VALUES (
2427+ 'project-queue-read', 'Queue read', '/tmp/queue-read', '[]',
2428+ '2026-08-16T12:00:00.000Z', '2026-08-16T12:00:00.000Z', NULL
2429+ )
2430+ ` ;
2431+ yield * sql `
2432+ INSERT INTO projection_threads (
2433+ thread_id, project_id, title, model_selection_json, runtime_mode, interaction_mode,
2434+ pending_approval_count, pending_user_input_count, has_actionable_proposed_plan,
2435+ created_at, updated_at, deleted_at
2436+ ) VALUES (
2437+ 'thread-queue-read', 'project-queue-read', 'Queue read',
2438+ '{"provider":"codex","model":"gpt-5-codex"}', 'full-access', 'default',
2439+ 0, 0, 0, '2026-08-16T12:00:00.000Z', '2026-08-16T12:01:00.000Z', NULL
2440+ )
2441+ ` ;
2442+ yield * sql `
2443+ INSERT INTO projection_thread_messages (
2444+ message_id, thread_id, turn_id, role, text, is_streaming,
2445+ created_at, updated_at, delivery_state
2446+ ) VALUES
2447+ ('message-history', 'thread-queue-read', NULL, 'user', 'Already delivered', 0,
2448+ '2026-08-16T12:00:00.000Z', '2026-08-16T12:00:00.000Z', NULL),
2449+ ('message-queued', 'thread-queue-read', NULL, 'user', 'Run next', 0,
2450+ '2026-08-16T12:01:00.000Z', '2026-08-16T12:01:00.000Z', 'queued')
2451+ ` ;
2452+ yield * sql `
2453+ INSERT INTO projection_thread_turn_queue (
2454+ message_id, thread_id, event_id, command_id, model_selection_json, title_seed,
2455+ runtime_mode, interaction_mode, source_proposed_plan_thread_id,
2456+ source_proposed_plan_id, queued_at, event_sequence, status
2457+ ) VALUES (
2458+ 'message-queued', 'thread-queue-read', 'event-queue-read', 'command-queue-read',
2459+ NULL, NULL, 'full-access', 'default', NULL, NULL,
2460+ '2026-08-16T12:01:00.000Z', 1, 'queued'
2461+ )
2462+ ` ;
2463+
2464+ const commandRead = yield * snapshotQuery . getCommandReadModel ( ) ;
2465+ assert . deepEqual (
2466+ commandRead . threads [ 0 ] ?. messages . map ( ( message ) => message . id ) ,
2467+ [ asMessageId ( "message-queued" ) ] ,
2468+ ) ;
2469+ assert . equal ( commandRead . threads [ 0 ] ?. messages [ 0 ] ?. deliveryState , "queued" ) ;
2470+
2471+ const shellRead = yield * snapshotQuery . getShellSnapshot ( ) ;
2472+ assert . equal ( shellRead . threads [ 0 ] ?. hasQueuedTurns , true ) ;
2473+ } ) ,
2474+ ) ;
2475+
24082476 it . effect ( "a thread with no turns returns its content unwindowed on the first page" , ( ) =>
24092477 Effect . gen ( function * ( ) {
24102478 const sql = yield * SqlClient . SqlClient ;
0 commit comments