@@ -401,46 +401,64 @@ export class ManagedRunController {
401401 } ) satisfies SupervisorSocket ;
402402
403403 socket . on ( "run:notify" , async ( { version, run } ) => {
404+ // Generate a unique ID for the notification
405+ const notificationId = Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) ;
406+
407+ // Use this to track the notification incl. any processing
408+ const notification = {
409+ id : notificationId ,
410+ runId : run . friendlyId ,
411+ version,
412+ } ;
413+
414+ // Lock this to the current run and snapshot IDs
415+ const controller = {
416+ runFriendlyId : this . runFriendlyId ,
417+ snapshotFriendlyId : this . snapshotFriendlyId ,
418+ } ;
419+
404420 this . sendDebugLog ( {
405421 runId : run . friendlyId ,
406422 message : "run:notify received by runner" ,
407- properties : { version, runId : run . friendlyId } ,
423+ properties : {
424+ notification,
425+ controller,
426+ } ,
408427 } ) ;
409428
410- if ( ! this . runFriendlyId ) {
429+ if ( ! controller . runFriendlyId ) {
411430 this . sendDebugLog ( {
412431 runId : run . friendlyId ,
413432 message : "run:notify: ignoring notification, no local run ID" ,
414433 properties : {
415- currentRunId : this . runFriendlyId ,
416- currentSnapshotId : this . snapshotFriendlyId ,
434+ notification ,
435+ controller ,
417436 } ,
418437 } ) ;
419438 return ;
420439 }
421440
422- if ( run . friendlyId !== this . runFriendlyId ) {
441+ if ( run . friendlyId !== controller . runFriendlyId ) {
423442 this . sendDebugLog ( {
424443 runId : run . friendlyId ,
425444 message : "run:notify: ignoring notification for different run" ,
426445 properties : {
427- currentRunId : this . runFriendlyId ,
428- currentSnapshotId : this . snapshotFriendlyId ,
429- notificationRunId : run . friendlyId ,
446+ notification,
447+ controller,
430448 } ,
431449 } ) ;
432450 return ;
433451 }
434452
435- const latestSnapshot = await this . httpClient . getRunExecutionData ( this . runFriendlyId ) ;
453+ const latestSnapshot = await this . httpClient . getRunExecutionData ( controller . runFriendlyId ) ;
436454
437455 if ( ! latestSnapshot . success ) {
438456 this . sendDebugLog ( {
439- runId : this . runFriendlyId ,
457+ runId : run . friendlyId ,
440458 message : "run:notify: failed to get latest snapshot data" ,
441459 properties : {
442- currentRunId : this . runFriendlyId ,
443- currentSnapshotId : this . snapshotFriendlyId ,
460+ notification ,
461+ controller ,
444462 error : latestSnapshot . error ,
445463 } ,
446464 } ) ;
@@ -451,19 +469,29 @@ export class ManagedRunController {
451469
452470 if ( ! this . currentExecution ) {
453471 this . sendDebugLog ( {
454- runId : runExecutionData . run . friendlyId ,
455- message : "handleSnapshotChange: no current execution" ,
472+ runId : run . friendlyId ,
473+ message : "run:notify: no current execution" ,
474+ properties : {
475+ notification,
476+ controller,
477+ } ,
456478 } ) ;
457479 return ;
458480 }
459481
460- const [ error ] = await tryCatch ( this . currentExecution . handleSnapshotChange ( runExecutionData ) ) ;
482+ const [ error ] = await tryCatch (
483+ this . currentExecution . enqueueSnapshotChangeAndWait ( runExecutionData )
484+ ) ;
461485
462486 if ( error ) {
463487 this . sendDebugLog ( {
464- runId : runExecutionData . run . friendlyId ,
465- message : "handleSnapshotChange: unexpected error" ,
466- properties : { error : error . message } ,
488+ runId : run . friendlyId ,
489+ message : "run:notify: unexpected error" ,
490+ properties : {
491+ notification,
492+ controller,
493+ error : error . message ,
494+ } ,
467495 } ) ;
468496 }
469497 } ) ;
0 commit comments