@@ -5191,45 +5191,45 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
51915191 } ) ,
51925192 ) ;
51935193
5194- it . effect ( "keeps a limited provider's queue held after another provider completes a turn " , ( ) =>
5194+ it . effect ( "holds a limited provider's queue through another provider's turn until reset " , ( ) =>
51955195 Effect . gen ( function * ( ) {
51965196 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
51975197 const eventSink = yield * EventSink . EventSinkV2 ;
5198- const threadId = ThreadId . make ( "runtime-layer-queue-limit-other-provider " ) ;
5199- const otherSelection = { instanceId : alternateInstanceId , model : "gpt-5.5" } ;
5198+ const threadId = ThreadId . make ( "runtime-layer-queue-limit-switch " ) ;
5199+ const switchedSelection = { instanceId : alternateInstanceId , model : "gpt-5.5" } ;
52005200 yield * orchestrator . dispatch ( {
52015201 type : "thread.create" ,
52025202 commandId : CommandId . make ( `${ threadId } :create` ) ,
52035203 threadId,
52045204 createdBy : "user" ,
52055205 creationSource : "web" ,
52065206 projectId : ProjectId . make ( `${ threadId } :project` ) ,
5207- title : "Limited queue " ,
5207+ title : "Limit switch " ,
52085208 modelSelection,
52095209 runtimeMode : "full-access" ,
52105210 interactionMode : "default" ,
52115211 branch : null ,
52125212 worktreePath : process . cwd ( ) ,
52135213 } ) ;
52145214 const send = (
5215- index : number ,
5216- selection : ModelSelection ,
5215+ name : string ,
5216+ selection : typeof modelSelection | typeof switchedSelection ,
52175217 type : "start_immediately" | "queue_after_active" ,
52185218 ) =>
52195219 orchestrator . dispatch ( {
52205220 type : "message.dispatch" ,
5221- commandId : CommandId . make ( `${ threadId } :${ index } ` ) ,
5221+ commandId : CommandId . make ( `${ threadId } :${ name } ` ) ,
52225222 threadId,
5223- messageId : MessageId . make ( `${ threadId } :${ index } ` ) ,
5224- text : `Prompt ${ index } ` ,
5223+ messageId : MessageId . make ( `${ threadId } :${ name } ` ) ,
5224+ text : name ,
52255225 attachments : [ ] ,
52265226 createdBy : "user" ,
52275227 creationSource : "web" ,
52285228 modelSelection : selection ,
52295229 dispatchMode : { type } ,
52305230 } ) ;
5231- yield * send ( 0 , modelSelection , "start_immediately" ) ;
5232- yield * send ( 1 , modelSelection , "queue_after_active" ) ;
5231+ yield * send ( "limited" , modelSelection , "start_immediately" ) ;
5232+ yield * send ( "queued" , modelSelection , "queue_after_active" ) ;
52335233 const [ limited , queued ] = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs ;
52345234 assert . isDefined ( limited ) ;
52355235 assert . isDefined ( queued ) ;
@@ -5265,7 +5265,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
52655265 message : "Usage limit reached" ,
52665266 code : "usage_limit" ,
52675267 retryable : null ,
5268- resetAt : DateTime . formatIso ( DateTime . add ( now , { days : 5 } ) ) ,
5268+ resetAt : DateTime . formatIso ( DateTime . add ( now , { hours : 1 } ) ) ,
52695269 } ,
52705270 } ,
52715271 } ,
@@ -5280,27 +5280,31 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
52805280 } ,
52815281 ] ,
52825282 } ) ;
5283- yield * send ( 2 , otherSelection , "start_immediately" ) ;
5284- const other = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs . at ( - 1 ) ;
5285- assert . equal ( other ?. providerInstanceId , alternateInstanceId ) ;
5283+
5284+ // A message on another provider starts ahead of the held queue and
5285+ // completes there.
5286+ yield * send ( "switch" , switchedSelection , "start_immediately" ) ;
5287+ const switched = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs . find (
5288+ ( run ) => run . userMessageId === MessageId . make ( `${ threadId } :switch` ) ,
5289+ ) ;
5290+ assert . equal ( switched ?. status , "starting" ) ;
52865291 yield * eventSink . write ( {
52875292 events : [
52885293 {
5289- id : EventId . make ( `${ threadId } :other- completed` ) ,
5294+ id : EventId . make ( `${ threadId } :switch: completed` ) ,
52905295 type : "run.updated" ,
52915296 threadId,
5292- runId : other ! . id ,
5293- providerInstanceId : alternateInstanceId ,
5297+ runId : switched ! . id ,
5298+ providerInstanceId : switched ! . providerInstanceId ,
52945299 occurredAt : now ,
5295- payload : { ...other ! , status : "completed" , completedAt : now } ,
5300+ payload : { ...switched ! , status : "completed" , completedAt : now } ,
52965301 } ,
52975302 ] ,
52985303 } ) ;
52995304
53005305 yield * orchestrator . resumeQueuedRuns ;
5301-
5302- const after = yield * orchestrator . getThreadProjection ( threadId ) ;
5303- assert . equal ( after . runs . find ( ( run ) => run . id === queued . id ) ?. status , "queued" ) ;
5306+ const held = yield * orchestrator . getThreadProjection ( threadId ) ;
5307+ assert . equal ( held . runs . find ( ( run ) => run . id === queued . id ) ?. status , "queued" ) ;
53045308 const blocked = yield * orchestrator
53055309 . dispatch ( {
53065310 type : "queue.resume" ,
@@ -5309,6 +5313,14 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
53095313 } )
53105314 . pipe ( Effect . flip ) ;
53115315 assert . equal ( blocked . _tag , "OrchestratorDispatchError" ) ;
5316+
5317+ // Once the reported reset passes, the queued message starts on its own provider.
5318+ yield * TestClock . adjust ( "61 minutes" ) ;
5319+ yield * orchestrator . resumeQueuedRuns ;
5320+ const reset = yield * orchestrator . getThreadProjection ( threadId ) ;
5321+ const resumed = reset . runs . find ( ( run ) => run . id === queued . id ) ;
5322+ assert . equal ( resumed ?. status , "starting" ) ;
5323+ assert . deepEqual ( resumed ?. modelSelection , modelSelection ) ;
53125324 } ) ,
53135325 ) ;
53145326
0 commit comments