@@ -177,6 +177,31 @@ const createFailure = Effect.fn(function* (
177177 } ) ;
178178} ) ;
179179
180+ const attachSessionError = Effect . fn ( function * ( threadId : ThreadId , lastError : string ) {
181+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
182+ const driver = ProviderDriverKind . make ( "codex" ) ;
183+ yield * store . apply ( {
184+ id : EventId . make ( `event:session:${ threadId } ` ) ,
185+ type : "provider-session.attached" ,
186+ threadId,
187+ driver,
188+ providerInstanceId,
189+ occurredAt : old ,
190+ payload : {
191+ id : ProviderSessionId . make ( `provider-session:${ threadId } ` ) ,
192+ driver,
193+ providerInstanceId,
194+ status : "error" ,
195+ cwd : "/workspace" ,
196+ model : modelSelection . model ,
197+ capabilities : CodexProviderCapabilitiesV2 ,
198+ createdAt : old ,
199+ updatedAt : old ,
200+ lastError,
201+ } ,
202+ } ) ;
203+ } ) ;
204+
180205it . effect (
181206 "sql: discovers settlement work with the same activity and background semantics as the shell" ,
182207 ( ) =>
@@ -273,33 +298,21 @@ it.effect(
273298 yield * createRun ( limitEndedLast , "failed" , 2 ) ,
274299 "provider_error" ,
275300 ) ;
276- // A newer, different session error replaces the limit, as in threadErrorSummary.
301+ // threadErrorSummary: a matching session error keeps the limit, a differing one replaces it.
302+ const sessionErrorMatchingLimit = yield * createThread ( "session-error-matching-limit" ) ;
303+ yield * createFailure (
304+ sessionErrorMatchingLimit ,
305+ yield * createRun ( sessionErrorMatchingLimit , "failed" ) ,
306+ "usage_limit" ,
307+ ) ;
308+ yield * attachSessionError ( sessionErrorMatchingLimit , "usage_limit" ) ;
277309 const sessionErrorAfterLimit = yield * createThread ( "session-error-after-limit" ) ;
278310 yield * createFailure (
279311 sessionErrorAfterLimit ,
280312 yield * createRun ( sessionErrorAfterLimit , "failed" ) ,
281313 "usage_limit" ,
282314 ) ;
283- yield * store . apply ( {
284- id : EventId . make ( "event:settlement:session-error" ) ,
285- type : "provider-session.attached" ,
286- threadId : sessionErrorAfterLimit ,
287- driver : ProviderDriverKind . make ( "codex" ) ,
288- providerInstanceId,
289- occurredAt : old ,
290- payload : {
291- id : ProviderSessionId . make ( "provider-session:settlement:session-error" ) ,
292- driver : ProviderDriverKind . make ( "codex" ) ,
293- providerInstanceId,
294- status : "error" ,
295- cwd : "/workspace" ,
296- model : modelSelection . model ,
297- capabilities : CodexProviderCapabilitiesV2 ,
298- createdAt : old ,
299- updatedAt : old ,
300- lastError : "Session crashed." ,
301- } ,
302- } ) ;
315+ yield * attachSessionError ( sessionErrorAfterLimit , "Session crashed." ) ;
303316 const providerFailed = yield * createThread ( "provider-failed" ) ;
304317 yield * createFailure (
305318 providerFailed ,
0 commit comments