@@ -2422,44 +2422,35 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
24222422 json_object('requestId', 'user-input-active'),
24232423 NULL,
24242424 '2026-02-26T12:35:07.000Z'
2425- ),
2426- (
2427- 'activity-user-input-active-failed',
2428- 'thread-stale-user-input',
2429- NULL,
2430- 'error',
2431- 'provider.user-input.respond.failed',
2432- 'Provider user input response failed',
2433- json_object(
2434- 'requestId',
2435- 'user-input-active',
2436- 'detail',
2437- 'Provider is temporarily unavailable'
2438- ),
2439- NULL,
2440- '2026-02-26T12:35:08.000Z'
24412425 )
24422426 ` ;
24432427
2428+ // A user-input lifecycle activity is one of the events that still
2429+ // refreshes the shell summary, so it forces the read under test.
24442430 yield * appendAndProject ( {
2445- type : "thread.message-sent " ,
2431+ type : "thread.activity-appended " ,
24462432 eventId : EventId . make ( "evt-stale-user-input-3" ) ,
24472433 aggregateKind : "thread" ,
24482434 aggregateId : ThreadId . make ( "thread-stale-user-input" ) ,
2449- occurredAt : "2026-02-26T12:35:09 .000Z" ,
2435+ occurredAt : "2026-02-26T12:35:08 .000Z" ,
24502436 commandId : CommandId . make ( "cmd-stale-user-input-3" ) ,
24512437 causationEventId : null ,
24522438 correlationId : CorrelationId . make ( "cmd-stale-user-input-3" ) ,
24532439 metadata : { } ,
24542440 payload : {
24552441 threadId : ThreadId . make ( "thread-stale-user-input" ) ,
2456- messageId : MessageId . make ( "message-stale-user-input" ) ,
2457- role : "user" ,
2458- text : "Continue" ,
2459- turnId : null ,
2460- streaming : false ,
2461- createdAt : "2026-02-26T12:35:09.000Z" ,
2462- updatedAt : "2026-02-26T12:35:09.000Z" ,
2442+ activity : {
2443+ id : EventId . make ( "activity-user-input-active-failed" ) ,
2444+ tone : "error" ,
2445+ kind : "provider.user-input.respond.failed" ,
2446+ summary : "Provider user input response failed" ,
2447+ payload : {
2448+ requestId : "user-input-active" ,
2449+ detail : "Provider is temporarily unavailable" ,
2450+ } ,
2451+ turnId : null ,
2452+ createdAt : "2026-02-26T12:35:08.000Z" ,
2453+ } ,
24632454 } ,
24642455 } ) ;
24652456
@@ -2474,6 +2465,217 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
24742465 } ) ,
24752466 ) ;
24762467
2468+ it . effect ( "maintains shell summary fields across message and activity streams" , ( ) =>
2469+ Effect . gen ( function * ( ) {
2470+ const projectionPipeline = yield * OrchestrationProjectionPipeline ;
2471+ const eventStore = yield * OrchestrationEventStore ;
2472+ const sql = yield * SqlClient . SqlClient ;
2473+ const appendAndProject = ( event : Parameters < typeof eventStore . append > [ 0 ] ) =>
2474+ eventStore
2475+ . append ( event )
2476+ . pipe ( Effect . flatMap ( ( savedEvent ) => projectionPipeline . projectEvent ( savedEvent ) ) ) ;
2477+
2478+ yield * appendAndProject ( {
2479+ type : "project.created" ,
2480+ eventId : EventId . make ( "evt-shell-summary-1" ) ,
2481+ aggregateKind : "project" ,
2482+ aggregateId : ProjectId . make ( "project-shell-summary" ) ,
2483+ occurredAt : "2026-03-01T08:00:00.000Z" ,
2484+ commandId : CommandId . make ( "cmd-shell-summary-1" ) ,
2485+ causationEventId : null ,
2486+ correlationId : CorrelationId . make ( "cmd-shell-summary-1" ) ,
2487+ metadata : { } ,
2488+ payload : {
2489+ projectId : ProjectId . make ( "project-shell-summary" ) ,
2490+ title : "Project Shell Summary" ,
2491+ workspaceRoot : "/tmp/project-shell-summary" ,
2492+ defaultModelSelection : null ,
2493+ scripts : [ ] ,
2494+ createdAt : "2026-03-01T08:00:00.000Z" ,
2495+ updatedAt : "2026-03-01T08:00:00.000Z" ,
2496+ } ,
2497+ } ) ;
2498+
2499+ yield * appendAndProject ( {
2500+ type : "thread.created" ,
2501+ eventId : EventId . make ( "evt-shell-summary-2" ) ,
2502+ aggregateKind : "thread" ,
2503+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2504+ occurredAt : "2026-03-01T08:00:01.000Z" ,
2505+ commandId : CommandId . make ( "cmd-shell-summary-2" ) ,
2506+ causationEventId : null ,
2507+ correlationId : CorrelationId . make ( "cmd-shell-summary-2" ) ,
2508+ metadata : { } ,
2509+ payload : {
2510+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2511+ projectId : ProjectId . make ( "project-shell-summary" ) ,
2512+ title : "Thread Shell Summary" ,
2513+ modelSelection : {
2514+ instanceId : ProviderInstanceId . make ( "codex" ) ,
2515+ model : "gpt-5-codex" ,
2516+ } ,
2517+ runtimeMode : "approval-required" ,
2518+ interactionMode : "default" ,
2519+ branch : null ,
2520+ worktreePath : null ,
2521+ createdAt : "2026-03-01T08:00:01.000Z" ,
2522+ updatedAt : "2026-03-01T08:00:01.000Z" ,
2523+ } ,
2524+ } ) ;
2525+
2526+ const readSummary = sql < {
2527+ readonly latestUserMessageAt : string | null ;
2528+ readonly pendingUserInputCount : number ;
2529+ readonly updatedAt : string ;
2530+ } > `
2531+ SELECT
2532+ latest_user_message_at AS "latestUserMessageAt",
2533+ pending_user_input_count AS "pendingUserInputCount",
2534+ updated_at AS "updatedAt"
2535+ FROM projection_threads
2536+ WHERE thread_id = 'thread-shell-summary'
2537+ ` ;
2538+
2539+ yield * appendAndProject ( {
2540+ type : "thread.message-sent" ,
2541+ eventId : EventId . make ( "evt-shell-summary-3" ) ,
2542+ aggregateKind : "thread" ,
2543+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2544+ occurredAt : "2026-03-01T08:00:02.000Z" ,
2545+ commandId : CommandId . make ( "cmd-shell-summary-3" ) ,
2546+ causationEventId : null ,
2547+ correlationId : CorrelationId . make ( "cmd-shell-summary-3" ) ,
2548+ metadata : { } ,
2549+ payload : {
2550+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2551+ messageId : MessageId . make ( "message-shell-summary-user" ) ,
2552+ role : "user" ,
2553+ text : "please do the thing" ,
2554+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2555+ streaming : false ,
2556+ createdAt : "2026-03-01T08:00:02.000Z" ,
2557+ updatedAt : "2026-03-01T08:00:02.000Z" ,
2558+ } ,
2559+ } ) ;
2560+
2561+ assert . deepEqual ( yield * readSummary , [
2562+ {
2563+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2564+ pendingUserInputCount : 0 ,
2565+ updatedAt : "2026-03-01T08:00:02.000Z" ,
2566+ } ,
2567+ ] ) ;
2568+
2569+ // Streaming assistant deltas bump updatedAt but must not disturb
2570+ // latestUserMessageAt or the pending counters.
2571+ yield * appendAndProject ( {
2572+ type : "thread.message-sent" ,
2573+ eventId : EventId . make ( "evt-shell-summary-4" ) ,
2574+ aggregateKind : "thread" ,
2575+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2576+ occurredAt : "2026-03-01T08:00:03.000Z" ,
2577+ commandId : CommandId . make ( "cmd-shell-summary-4" ) ,
2578+ causationEventId : null ,
2579+ correlationId : CorrelationId . make ( "cmd-shell-summary-4" ) ,
2580+ metadata : { } ,
2581+ payload : {
2582+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2583+ messageId : MessageId . make ( "message-shell-summary-assistant" ) ,
2584+ role : "assistant" ,
2585+ text : "working on it" ,
2586+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2587+ streaming : true ,
2588+ createdAt : "2026-03-01T08:00:03.000Z" ,
2589+ updatedAt : "2026-03-01T08:00:03.000Z" ,
2590+ } ,
2591+ } ) ;
2592+
2593+ assert . deepEqual ( yield * readSummary , [
2594+ {
2595+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2596+ pendingUserInputCount : 0 ,
2597+ updatedAt : "2026-03-01T08:00:03.000Z" ,
2598+ } ,
2599+ ] ) ;
2600+
2601+ // Ordinary tool activities bump updatedAt without touching the
2602+ // user-input counter; user-input lifecycle activities update it.
2603+ yield * appendAndProject ( {
2604+ type : "thread.activity-appended" ,
2605+ eventId : EventId . make ( "evt-shell-summary-5" ) ,
2606+ aggregateKind : "thread" ,
2607+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2608+ occurredAt : "2026-03-01T08:00:04.000Z" ,
2609+ commandId : CommandId . make ( "cmd-shell-summary-5" ) ,
2610+ causationEventId : null ,
2611+ correlationId : CorrelationId . make ( "cmd-shell-summary-5" ) ,
2612+ metadata : { } ,
2613+ payload : {
2614+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2615+ activity : {
2616+ id : EventId . make ( "activity-shell-summary-command" ) ,
2617+ tone : "tool" ,
2618+ kind : "command" ,
2619+ summary : "Ran a command" ,
2620+ payload : { } ,
2621+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2622+ createdAt : "2026-03-01T08:00:04.000Z" ,
2623+ } ,
2624+ } ,
2625+ } ) ;
2626+
2627+ assert . deepEqual ( yield * readSummary , [
2628+ {
2629+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2630+ pendingUserInputCount : 0 ,
2631+ updatedAt : "2026-03-01T08:00:04.000Z" ,
2632+ } ,
2633+ ] ) ;
2634+
2635+ yield * appendAndProject ( {
2636+ type : "thread.activity-appended" ,
2637+ eventId : EventId . make ( "evt-shell-summary-6" ) ,
2638+ aggregateKind : "thread" ,
2639+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2640+ occurredAt : "2026-03-01T08:00:05.000Z" ,
2641+ commandId : CommandId . make ( "cmd-shell-summary-6" ) ,
2642+ causationEventId : null ,
2643+ correlationId : CorrelationId . make ( "cmd-shell-summary-6" ) ,
2644+ metadata : { } ,
2645+ payload : {
2646+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2647+ activity : {
2648+ id : EventId . make ( "activity-shell-summary-user-input" ) ,
2649+ tone : "info" ,
2650+ kind : "user-input.requested" ,
2651+ summary : "User input requested" ,
2652+ payload : {
2653+ requestId : "user-input-request-shell-summary-1" ,
2654+ questions : [
2655+ {
2656+ id : "confirm" ,
2657+ header : "Confirm" ,
2658+ question : "Proceed?" ,
2659+ options : [ { label : "yes" , description : "Proceed" } ] ,
2660+ } ,
2661+ ] ,
2662+ } ,
2663+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2664+ createdAt : "2026-03-01T08:00:05.000Z" ,
2665+ } ,
2666+ } ,
2667+ } ) ;
2668+
2669+ assert . deepEqual ( yield * readSummary , [
2670+ {
2671+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2672+ pendingUserInputCount : 1 ,
2673+ updatedAt : "2026-03-01T08:00:05.000Z" ,
2674+ } ,
2675+ ] ) ;
2676+ } ) ,
2677+ ) ;
2678+
24772679 it . effect ( "ignores non-stale provider approval response failures" , ( ) =>
24782680 Effect . gen ( function * ( ) {
24792681 const projectionPipeline = yield * OrchestrationProjectionPipeline ;
0 commit comments