@@ -70,22 +70,21 @@ export default function agentLoopCancellable(socketPath, systemPrompt, maxTurns)
7070// { respSet, respId, delta } | null (idle timeout).
7171function awaitTurn ( committed , turn ) {
7272 const respSet = obelisk . createJoinSet ( { name : `response-${ turn } ` } ) ;
73- const respId = responseSubmit ( respSet ) ;
73+ const respId = responseSubmit ( respSet ) ; // Webhook will receive the answer here
7474
7575 const raceSet = obelisk . createJoinSet ( { name : `request-${ turn } ` } ) ;
7676 const reqId = requestSubmit ( raceSet , respId , committed ) ;
77- raceSet . submitDelay ( IDLE_TIMEOUT ) ;
77+ const delayId = raceSet . submitDelay ( IDLE_TIMEOUT ) ;
7878
7979 try {
80- const winner = raceSet . joinNext ( ) ;
81- if ( winner . type === "delay" ) {
82- // Idle: no request arrived in time. Drop the unanswered response stub.
80+ const delta = raceSet . joinNext ( ) ;
81+ if ( raceSet . lastId == delayId ) {
82+ // Drop the unanswered response stub.
8383 responseStub ( respId , { err : "session idle timeout" } ) ;
8484 respSet . close ( ) ;
8585 return null ;
8686 }
87- const delta = obelisk . getResult ( reqId ) ; // ok = the delta JSON string
88- if ( typeof delta !== "string" ) throw `turn.request returned an unexpected value: ${ JSON . stringify ( delta ) } ` ;
87+ // stub activity turn_request won, meaning webhook received a request for this workflow
8988 return { respSet, respId, delta } ;
9089 } finally {
9190 // Cancel the losing idle delay once the request stub has completed.
0 commit comments