@@ -925,11 +925,15 @@ export const SessionRoutes = lazy(() =>
925925 return stream ( c , async ( stream ) => {
926926 const sessionID = c . req . valid ( "param" ) . sessionID
927927 const body = c . req . valid ( "json" )
928- // altimate_change start — bind the client's trace to this turn's user message (see TraceContext)
928+ // altimate_change start — bind the client's trace to this turn's user message (see TraceContext).
929+ // A noReply prompt runs no turn, so binds nothing; a prompt that fails before its loop is released.
929930 const messageID = body . messageID ?? MessageID . ascending ( )
930- TraceContext . bind ( messageID , c . req . header ( "traceparent" ) )
931+ TraceContext . bind ( messageID , body . noReply ? undefined : c . req . header ( "traceparent" ) )
932+ const msg = await SessionPrompt . prompt ( { ...body , sessionID, messageID } ) . catch ( ( error ) => {
933+ TraceContext . release ( sessionID , [ messageID ] )
934+ throw error
935+ } )
931936 // altimate_change end
932- const msg = await SessionPrompt . prompt ( { ...body , sessionID, messageID } )
933937 stream . write ( JSON . stringify ( msg ) )
934938 } )
935939 } ,
@@ -961,11 +965,15 @@ export const SessionRoutes = lazy(() =>
961965 return stream ( c , async ( ) => {
962966 const sessionID = c . req . valid ( "param" ) . sessionID
963967 const body = c . req . valid ( "json" )
964- // altimate_change start — bind the client's trace to this turn's user message (see TraceContext)
968+ // altimate_change start — bind the client's trace to this turn's user message (see TraceContext).
969+ // A noReply prompt runs no turn, so binds nothing.
965970 const messageID = body . messageID ?? MessageID . ascending ( )
966- TraceContext . bind ( messageID , c . req . header ( "traceparent" ) )
971+ TraceContext . bind ( messageID , body . noReply ? undefined : c . req . header ( "traceparent" ) )
967972 // altimate_change end
968973 SessionPrompt . prompt ( { ...body , sessionID, messageID } ) . catch ( ( err ) => {
974+ // altimate_change start — a prompt that failed before its loop is released here
975+ TraceContext . release ( sessionID , [ messageID ] )
976+ // altimate_change end
969977 log . error ( "prompt_async failed" , { sessionID, error : err } )
970978 Bus . publish ( Session . Event . Error , {
971979 sessionID,
@@ -1008,11 +1016,15 @@ export const SessionRoutes = lazy(() =>
10081016 async ( c ) => {
10091017 const sessionID = c . req . valid ( "param" ) . sessionID
10101018 const body = c . req . valid ( "json" )
1011- // altimate_change start — bind the client's trace to this turn's user message (see TraceContext)
1019+ // altimate_change start — bind the client's trace to this turn's user message (see TraceContext);
1020+ // a command that fails before its loop is released
10121021 const messageID = body . messageID ?? MessageID . ascending ( )
10131022 TraceContext . bind ( messageID , c . req . header ( "traceparent" ) )
1023+ const msg = await SessionPrompt . command ( { ...body , sessionID, messageID } ) . catch ( ( error ) => {
1024+ TraceContext . release ( sessionID , [ messageID ] )
1025+ throw error
1026+ } )
10141027 // altimate_change end
1015- const msg = await SessionPrompt . command ( { ...body , sessionID, messageID } )
10161028 return c . json ( msg )
10171029 } ,
10181030 )
0 commit comments