@@ -2086,6 +2086,217 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
20862086 } ) ,
20872087 ) ;
20882088
2089+ it . effect ( "maintains shell summary fields across message and activity streams" , ( ) =>
2090+ Effect . gen ( function * ( ) {
2091+ const projectionPipeline = yield * OrchestrationProjectionPipeline ;
2092+ const eventStore = yield * OrchestrationEventStore ;
2093+ const sql = yield * SqlClient . SqlClient ;
2094+ const appendAndProject = ( event : Parameters < typeof eventStore . append > [ 0 ] ) =>
2095+ eventStore
2096+ . append ( event )
2097+ . pipe ( Effect . flatMap ( ( savedEvent ) => projectionPipeline . projectEvent ( savedEvent ) ) ) ;
2098+
2099+ yield * appendAndProject ( {
2100+ type : "project.created" ,
2101+ eventId : EventId . make ( "evt-shell-summary-1" ) ,
2102+ aggregateKind : "project" ,
2103+ aggregateId : ProjectId . make ( "project-shell-summary" ) ,
2104+ occurredAt : "2026-03-01T08:00:00.000Z" ,
2105+ commandId : CommandId . make ( "cmd-shell-summary-1" ) ,
2106+ causationEventId : null ,
2107+ correlationId : CorrelationId . make ( "cmd-shell-summary-1" ) ,
2108+ metadata : { } ,
2109+ payload : {
2110+ projectId : ProjectId . make ( "project-shell-summary" ) ,
2111+ title : "Project Shell Summary" ,
2112+ workspaceRoot : "/tmp/project-shell-summary" ,
2113+ defaultModelSelection : null ,
2114+ scripts : [ ] ,
2115+ createdAt : "2026-03-01T08:00:00.000Z" ,
2116+ updatedAt : "2026-03-01T08:00:00.000Z" ,
2117+ } ,
2118+ } ) ;
2119+
2120+ yield * appendAndProject ( {
2121+ type : "thread.created" ,
2122+ eventId : EventId . make ( "evt-shell-summary-2" ) ,
2123+ aggregateKind : "thread" ,
2124+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2125+ occurredAt : "2026-03-01T08:00:01.000Z" ,
2126+ commandId : CommandId . make ( "cmd-shell-summary-2" ) ,
2127+ causationEventId : null ,
2128+ correlationId : CorrelationId . make ( "cmd-shell-summary-2" ) ,
2129+ metadata : { } ,
2130+ payload : {
2131+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2132+ projectId : ProjectId . make ( "project-shell-summary" ) ,
2133+ title : "Thread Shell Summary" ,
2134+ modelSelection : {
2135+ instanceId : ProviderInstanceId . make ( "codex" ) ,
2136+ model : "gpt-5-codex" ,
2137+ } ,
2138+ runtimeMode : "approval-required" ,
2139+ interactionMode : "default" ,
2140+ branch : null ,
2141+ worktreePath : null ,
2142+ createdAt : "2026-03-01T08:00:01.000Z" ,
2143+ updatedAt : "2026-03-01T08:00:01.000Z" ,
2144+ } ,
2145+ } ) ;
2146+
2147+ const readSummary = sql < {
2148+ readonly latestUserMessageAt : string | null ;
2149+ readonly pendingUserInputCount : number ;
2150+ readonly updatedAt : string ;
2151+ } > `
2152+ SELECT
2153+ latest_user_message_at AS "latestUserMessageAt",
2154+ pending_user_input_count AS "pendingUserInputCount",
2155+ updated_at AS "updatedAt"
2156+ FROM projection_threads
2157+ WHERE thread_id = 'thread-shell-summary'
2158+ ` ;
2159+
2160+ yield * appendAndProject ( {
2161+ type : "thread.message-sent" ,
2162+ eventId : EventId . make ( "evt-shell-summary-3" ) ,
2163+ aggregateKind : "thread" ,
2164+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2165+ occurredAt : "2026-03-01T08:00:02.000Z" ,
2166+ commandId : CommandId . make ( "cmd-shell-summary-3" ) ,
2167+ causationEventId : null ,
2168+ correlationId : CorrelationId . make ( "cmd-shell-summary-3" ) ,
2169+ metadata : { } ,
2170+ payload : {
2171+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2172+ messageId : MessageId . make ( "message-shell-summary-user" ) ,
2173+ role : "user" ,
2174+ text : "please do the thing" ,
2175+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2176+ streaming : false ,
2177+ createdAt : "2026-03-01T08:00:02.000Z" ,
2178+ updatedAt : "2026-03-01T08:00:02.000Z" ,
2179+ } ,
2180+ } ) ;
2181+
2182+ assert . deepEqual ( yield * readSummary , [
2183+ {
2184+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2185+ pendingUserInputCount : 0 ,
2186+ updatedAt : "2026-03-01T08:00:02.000Z" ,
2187+ } ,
2188+ ] ) ;
2189+
2190+ // Streaming assistant deltas bump updatedAt but must not disturb
2191+ // latestUserMessageAt or the pending counters.
2192+ yield * appendAndProject ( {
2193+ type : "thread.message-sent" ,
2194+ eventId : EventId . make ( "evt-shell-summary-4" ) ,
2195+ aggregateKind : "thread" ,
2196+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2197+ occurredAt : "2026-03-01T08:00:03.000Z" ,
2198+ commandId : CommandId . make ( "cmd-shell-summary-4" ) ,
2199+ causationEventId : null ,
2200+ correlationId : CorrelationId . make ( "cmd-shell-summary-4" ) ,
2201+ metadata : { } ,
2202+ payload : {
2203+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2204+ messageId : MessageId . make ( "message-shell-summary-assistant" ) ,
2205+ role : "assistant" ,
2206+ text : "working on it" ,
2207+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2208+ streaming : true ,
2209+ createdAt : "2026-03-01T08:00:03.000Z" ,
2210+ updatedAt : "2026-03-01T08:00:03.000Z" ,
2211+ } ,
2212+ } ) ;
2213+
2214+ assert . deepEqual ( yield * readSummary , [
2215+ {
2216+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2217+ pendingUserInputCount : 0 ,
2218+ updatedAt : "2026-03-01T08:00:03.000Z" ,
2219+ } ,
2220+ ] ) ;
2221+
2222+ // Ordinary tool activities bump updatedAt without touching the
2223+ // user-input counter; user-input lifecycle activities update it.
2224+ yield * appendAndProject ( {
2225+ type : "thread.activity-appended" ,
2226+ eventId : EventId . make ( "evt-shell-summary-5" ) ,
2227+ aggregateKind : "thread" ,
2228+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2229+ occurredAt : "2026-03-01T08:00:04.000Z" ,
2230+ commandId : CommandId . make ( "cmd-shell-summary-5" ) ,
2231+ causationEventId : null ,
2232+ correlationId : CorrelationId . make ( "cmd-shell-summary-5" ) ,
2233+ metadata : { } ,
2234+ payload : {
2235+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2236+ activity : {
2237+ id : EventId . make ( "activity-shell-summary-command" ) ,
2238+ tone : "tool" ,
2239+ kind : "command" ,
2240+ summary : "Ran a command" ,
2241+ payload : { } ,
2242+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2243+ createdAt : "2026-03-01T08:00:04.000Z" ,
2244+ } ,
2245+ } ,
2246+ } ) ;
2247+
2248+ assert . deepEqual ( yield * readSummary , [
2249+ {
2250+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2251+ pendingUserInputCount : 0 ,
2252+ updatedAt : "2026-03-01T08:00:04.000Z" ,
2253+ } ,
2254+ ] ) ;
2255+
2256+ yield * appendAndProject ( {
2257+ type : "thread.activity-appended" ,
2258+ eventId : EventId . make ( "evt-shell-summary-6" ) ,
2259+ aggregateKind : "thread" ,
2260+ aggregateId : ThreadId . make ( "thread-shell-summary" ) ,
2261+ occurredAt : "2026-03-01T08:00:05.000Z" ,
2262+ commandId : CommandId . make ( "cmd-shell-summary-6" ) ,
2263+ causationEventId : null ,
2264+ correlationId : CorrelationId . make ( "cmd-shell-summary-6" ) ,
2265+ metadata : { } ,
2266+ payload : {
2267+ threadId : ThreadId . make ( "thread-shell-summary" ) ,
2268+ activity : {
2269+ id : EventId . make ( "activity-shell-summary-user-input" ) ,
2270+ tone : "info" ,
2271+ kind : "user-input.requested" ,
2272+ summary : "User input requested" ,
2273+ payload : {
2274+ requestId : "user-input-request-shell-summary-1" ,
2275+ questions : [
2276+ {
2277+ id : "confirm" ,
2278+ header : "Confirm" ,
2279+ question : "Proceed?" ,
2280+ options : [ { label : "yes" , description : "Proceed" } ] ,
2281+ } ,
2282+ ] ,
2283+ } ,
2284+ turnId : TurnId . make ( "turn-shell-summary-1" ) ,
2285+ createdAt : "2026-03-01T08:00:05.000Z" ,
2286+ } ,
2287+ } ,
2288+ } ) ;
2289+
2290+ assert . deepEqual ( yield * readSummary , [
2291+ {
2292+ latestUserMessageAt : "2026-03-01T08:00:02.000Z" ,
2293+ pendingUserInputCount : 1 ,
2294+ updatedAt : "2026-03-01T08:00:05.000Z" ,
2295+ } ,
2296+ ] ) ;
2297+ } ) ,
2298+ ) ;
2299+
20892300 it . effect ( "ignores non-stale provider approval response failures" , ( ) =>
20902301 Effect . gen ( function * ( ) {
20912302 const projectionPipeline = yield * OrchestrationProjectionPipeline ;
0 commit comments