@@ -3185,58 +3185,6 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
31853185 return { threadId, activeRun, wakeRun } ;
31863186 } ) ;
31873187
3188- const failRun = ( run : OrchestrationV2Run ) =>
3189- Effect . gen ( function * ( ) {
3190- const eventSink = yield * EventSink . EventSinkV2 ;
3191- const now = yield * DateTime . now ;
3192- yield * eventSink . write ( {
3193- events : [
3194- {
3195- id : EventId . make ( `${ run . id } :error` ) ,
3196- type : "turn-item.updated" ,
3197- threadId : run . threadId ,
3198- runId : run . id ,
3199- ...( run . rootNodeId === null ? { } : { nodeId : run . rootNodeId } ) ,
3200- providerInstanceId : run . providerInstanceId ,
3201- occurredAt : now ,
3202- payload : {
3203- id : TurnItemId . make ( `${ run . id } :error` ) ,
3204- type : "error" ,
3205- threadId : run . threadId ,
3206- runId : run . id ,
3207- nodeId : run . rootNodeId ,
3208- providerThreadId : run . providerThreadId ,
3209- providerTurnId : null ,
3210- nativeItemRef : null ,
3211- parentItemId : null ,
3212- ordinal : 2 ,
3213- status : "failed" ,
3214- title : "Provider failure" ,
3215- startedAt : now ,
3216- completedAt : now ,
3217- updatedAt : now ,
3218- failure : {
3219- class : "provider_error" ,
3220- message : "Provider failed." ,
3221- code : "provider_failed" ,
3222- retryable : null ,
3223- } ,
3224- } ,
3225- } ,
3226- {
3227- id : EventId . make ( `${ run . id } :failed` ) ,
3228- type : "run.updated" ,
3229- threadId : run . threadId ,
3230- runId : run . id ,
3231- ...( run . rootNodeId === null ? { } : { nodeId : run . rootNodeId } ) ,
3232- providerInstanceId : run . providerInstanceId ,
3233- occurredAt : now ,
3234- payload : { ...run , status : "failed" , completedAt : now } ,
3235- } ,
3236- ] ,
3237- } ) ;
3238- } ) ;
3239-
32403188 // Completes `run`, then dispatches automatic settlement while the completion reaction waits
32413189 // before releasing and starting the queue: the window the settlement sweep races.
32423190 const autoSettleBeforeCompletionReaction = ( run : OrchestrationV2Run , commandId : CommandId ) =>
@@ -3331,52 +3279,6 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
33313279 } ) ,
33323280 ) ;
33333281
3334- it . effect ( "automatic settlement waits for a held wake that a completed run releases" , ( ) =>
3335- Effect . gen ( function * ( ) {
3336- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
3337- const eventSink = yield * EventSink . EventSinkV2 ;
3338- const { threadId, activeRun, wakeRun } = yield * queuedWatchWake ( "pr-watch-released-wake" ) ;
3339- const beforeFailure = yield * orchestrator . getThreadEventSequence ( threadId ) ;
3340- yield * failRun ( activeRun ) ;
3341- yield * eventSink
3342- . stream ( { threadId, afterSequence : beforeFailure , eventType : "run.updated" } )
3343- . pipe (
3344- Stream . filter (
3345- ( stored ) =>
3346- stored . event . type === "run.updated" &&
3347- stored . event . payload . id === wakeRun . id &&
3348- stored . event . payload . queueHeld === true ,
3349- ) ,
3350- Stream . runHead ,
3351- ) ;
3352- // The server's own message: a later completion releases the wake's hold.
3353- yield * orchestrator . dispatch ( {
3354- type : "message.dispatch" ,
3355- createdBy : "agent" ,
3356- creationSource : "server" ,
3357- commandId : CommandId . make ( "pr-watch-released-wake-tick" ) ,
3358- threadId,
3359- messageId : MessageId . make ( "pr-watch-released-wake-tick" ) ,
3360- text : "Scheduled tick" ,
3361- attachments : [ ] ,
3362- modelSelection,
3363- dispatchMode : { type : "start_immediately" } ,
3364- } ) ;
3365- const tickRun = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs . find (
3366- ( run ) => run . status === "starting" ,
3367- ) ;
3368- assert . isDefined ( tickRun ) ;
3369-
3370- const { window, afterSettle, after } = yield * autoSettleBeforeCompletionReaction (
3371- tickRun ,
3372- CommandId . make ( "pr-watch-released-wake-auto-settle" ) ,
3373- ) ;
3374- assert . equal ( window . runs . find ( ( run ) => run . id === wakeRun . id ) ?. queueHeld , true ) ;
3375- assert . isNull ( afterSettle . thread . settledAt ) ;
3376- assert . equal ( after . runs . find ( ( run ) => run . id === wakeRun . id ) ?. status , "starting" ) ;
3377- } ) ,
3378- ) ;
3379-
33803282 it . effect ( "automatic settlement refuses a held wake only within the queued-turn grace" , ( ) =>
33813283 Effect . gen ( function * ( ) {
33823284 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments