@@ -1134,6 +1134,10 @@ function codexUsageLimitError(
11341134 ) ;
11351135}
11361136
1137+ function codexModelCapacityError ( code : string | null , message : string | undefined ) : boolean {
1138+ return code === "serverOverloaded" || / ^ S e l e c t e d m o d e l i s a t c a p a c i t y \b / iu. test ( message ?? "" ) ;
1139+ }
1140+
11371141interface ActiveCodexTurnContext {
11381142 closedCommandItemIds ?: ReadonlySet < string > ;
11391143 latestProviderFailure ?: {
@@ -4566,9 +4570,11 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
45664570 failure : makeProviderFailure ( {
45674571 message : payload . error . additionalDetails ?. trim ( ) || payload . error . message ,
45684572 code : notificationCode ,
4569- class : codexUsageLimitError ( notificationCode , payload . error . codexErrorInfo )
4570- ? "usage_limit"
4571- : "provider_error" ,
4573+ class : codexModelCapacityError ( notificationCode , payload . error . message )
4574+ ? "model_capacity"
4575+ : codexUsageLimitError ( notificationCode , payload . error . codexErrorInfo )
4576+ ? "usage_limit"
4577+ : "provider_error" ,
45724578 } ) ,
45734579 } ;
45744580 return ;
@@ -4589,11 +4595,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
45894595 ? payload . error . message
45904596 : additionalDetails ,
45914597 code,
4592- class : codexUsageLimitError ( code , payload . error . codexErrorInfo )
4593- ? "usage_limit"
4594- : code ?. startsWith ( "http" ) === true || code ?. startsWith ( "responseStream" ) === true
4595- ? "transport_error"
4596- : "provider_error" ,
4598+ class : codexModelCapacityError ( code , payload . error . message )
4599+ ? "model_capacity"
4600+ : codexUsageLimitError ( code , payload . error . codexErrorInfo )
4601+ ? "usage_limit"
4602+ : code ?. startsWith ( "http" ) === true || code ?. startsWith ( "responseStream" ) === true
4603+ ? "transport_error"
4604+ : "provider_error" ,
45974605 retryable : true ,
45984606 } ) ;
45994607 const itemOrdinal =
@@ -5645,9 +5653,14 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
56455653 input . failureErrorInfo === undefined
56465654 ? undefined
56475655 : codexErrorInfoCode ( input . failureErrorInfo ) ;
5648- const failureClass = codexUsageLimitError ( failureCode ?? null , input . failureErrorInfo )
5649- ? "usage_limit"
5650- : "provider_error" ;
5656+ const failureClass = codexModelCapacityError (
5657+ failureCode ?? null ,
5658+ input . failureMessage ,
5659+ )
5660+ ? "model_capacity"
5661+ : codexUsageLimitError ( failureCode ?? null , input . failureErrorInfo )
5662+ ? "usage_limit"
5663+ : "provider_error" ;
56515664 // The notification carries the richer message, so it wins when the
56525665 // completion repeats it. An explicit exhaustion status on the
56535666 // completion still decides the class; a missing one is not evidence.
@@ -5709,17 +5722,26 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
57095722 event : CodexRootTerminalEvent ,
57105723 ) {
57115724 const current =
5712- event . status === "failed" && event . failure . class === "usage_limit "
5725+ event . status === "failed" && event . failure . class === "model_capacity "
57135726 ? {
57145727 ...event ,
57155728 failure : {
57165729 ...event . failure ,
5717- resetAt :
5718- event . failure . resetAt ??
5719- codexUsageLimitResetAt ( yield * Ref . get ( rateLimitSnapshot ) ) ,
5730+ retryable : true ,
5731+ resetAt : DateTime . formatIso ( DateTime . add ( yield * DateTime . now , { seconds : 30 } ) ) ,
57205732 } ,
57215733 }
5722- : event ;
5734+ : event . status === "failed" && event . failure . class === "usage_limit"
5735+ ? {
5736+ ...event ,
5737+ failure : {
5738+ ...event . failure ,
5739+ resetAt :
5740+ event . failure . resetAt ??
5741+ codexUsageLimitResetAt ( yield * Ref . get ( rateLimitSnapshot ) ) ,
5742+ } ,
5743+ }
5744+ : event ;
57235745 yield * emitProviderEvent ( current ) ;
57245746 for ( const turn of goalRuns . get ( context . providerTurnId ) ?? [ ] ) {
57255747 goalRuns . delete ( turn . providerTurnId ) ;
0 commit comments