77 type OrchestrationV2ConversationMessage ,
88 type OrchestrationV2ExecutionNode ,
99 type OrchestrationV2ProviderCapabilities ,
10- type OrchestrationV2ProviderFailure ,
1110 type OrchestrationV2ProviderRetry ,
1211 type OrchestrationV2ProviderSession ,
1312 type OrchestrationV2ProviderThread ,
@@ -28,6 +27,7 @@ import {
2827import type { MuseSettings } from "../settings.ts" ;
2928import { AgentScope } from "@t3tools/shared/AgentScope" ;
3029import { getModelSelectionStringOptionValue } from "@t3tools/shared/model" ;
30+ import { formatDuration } from "@t3tools/shared/orchestrationTiming" ;
3131import * as Cause from "effect/Cause" ;
3232import * as DateTime from "effect/DateTime" ;
3333import * as Deferred from "effect/Deferred" ;
@@ -232,7 +232,8 @@ interface MuseRetryRow {
232232 readonly method : string ;
233233 readonly nativeId : string ;
234234 readonly retry : OrchestrationV2ProviderRetry ;
235- readonly failure : OrchestrationV2ProviderFailure ;
235+ readonly cause : string ;
236+ readonly code : string | undefined ;
236237 running : boolean ;
237238}
238239
@@ -480,7 +481,16 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
480481 driver : MUSE_PROVIDER ,
481482 nodeId : turn . input . rootNodeId ,
482483 itemOrdinal : base . ordinal ,
483- failure : row . failure ,
484+ failure : makeProviderFailure ( {
485+ // Clients show only the failure message, so a waiting row carries its delay.
486+ message :
487+ status === "running"
488+ ? `${ row . cause } . Retrying in ${ formatDuration ( row . retry . retryDelayMs ?? 0 ) } .`
489+ : row . cause ,
490+ code : row . code ,
491+ class : "provider_error" ,
492+ retryable : true ,
493+ } ) ,
484494 retry : row . retry ,
485495 status,
486496 updatedAt : time ,
@@ -1695,29 +1705,25 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* (
16951705 const cause =
16961706 retry . httpStatus === undefined ? retry . errorKind : `HTTP ${ retry . httpStatus } ` ;
16971707 // A chain's first retry opens a row; its later attempts update that row.
1698- const chain =
1699- retry . attempt > 1 ? turn . retries . findLast ( ( row ) => row . method === method ) : undefined ;
1700- if ( chain ) chain . running = false ;
1708+ const index =
1709+ retry . attempt > 1 ? turn . retries . findLastIndex ( ( row ) => row . method === method ) : - 1 ;
17011710 const row : MuseRetryRow = {
17021711 method,
1703- nativeId : chain ?. nativeId ?? `retry:${ retry . sourceRange . first . id } ` ,
1712+ nativeId : turn . retries [ index ] ?. nativeId ?? `retry:${ retry . sourceRange . first . id } ` ,
17041713 // Muse counts the first request as attempt 1; T3 counts retries.
17051714 retry : {
17061715 attempt : retry . attempt ,
17071716 maxAttempts : Math . max ( 1 , retry . maxAttempts - 1 ) ,
17081717 retryDelayMs : Math . trunc ( retry . retryDelayMs ) ,
17091718 } ,
1710- failure : makeProviderFailure ( {
1711- message :
1712- retry . reason ??
1713- ( cause ? `Model request failed (${ cause } )` : "Model request failed" ) ,
1714- code : retry . errorKind ,
1715- class : "provider_error" ,
1716- retryable : true ,
1717- } ) ,
1719+ cause :
1720+ retry . reason ??
1721+ ( cause ? `Model request failed (${ cause } )` : "Model request failed" ) ,
1722+ code : retry . errorKind ,
17181723 running : true ,
17191724 } ;
1720- turn . retries . push ( row ) ;
1725+ if ( index === - 1 ) turn . retries . push ( row ) ;
1726+ else turn . retries [ index ] = row ;
17211727 yield * emitRetry ( turn , row , "running" ) ;
17221728 break ;
17231729 }
0 commit comments