@@ -113,6 +113,11 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
113113 > ( ) ;
114114
115115 private readonly workerClient : SupervisorHttpClient ;
116+ // Bounded map for trace contexts used by compute snapshot spans.
117+ // Entries are added on dequeue and consumed on snapshot callback, which may arrive
118+ // hours later after a checkpoint/restore cycle. Using a capped map avoids unbounded
119+ // growth while keeping recent contexts available. Oldest entries are evicted first.
120+ private static readonly MAX_TRACE_CONTEXTS = 10_000 ;
116121 private readonly runTraceContexts = new Map < string , RunTraceContext > ( ) ;
117122 private readonly snapshotDelayWheel ?: TimerWheel < DelayedSnapshot > ;
118123
@@ -821,6 +826,14 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
821826 }
822827
823828 registerRunTraceContext ( runFriendlyId : string , ctx : RunTraceContext ) {
829+ // Evict oldest entries if we've hit the cap
830+ if ( this . runTraceContexts . size >= WorkloadServer . MAX_TRACE_CONTEXTS ) {
831+ const firstKey = this . runTraceContexts . keys ( ) . next ( ) . value ;
832+ if ( firstKey ) {
833+ this . runTraceContexts . delete ( firstKey ) ;
834+ }
835+ }
836+
824837 this . runTraceContexts . set ( runFriendlyId , ctx ) ;
825838 }
826839
@@ -829,6 +842,11 @@ export class WorkloadServer extends EventEmitter<WorkloadServerEvents> {
829842 }
830843
831844 async stop ( ) {
845+ // Intentionally drop pending snapshots rather than dispatching them. The supervisor
846+ // is shutting down, so our callback URL will be dead by the time the gateway responds.
847+ // Runners detect the supervisor is gone and reconnect to a new instance, which
848+ // re-triggers the snapshot workflow. Snapshots are an optimization, not a correctness
849+ // requirement - runs continue fine without them.
832850 const remaining = this . snapshotDelayWheel ?. stop ( ) ?? [ ] ;
833851 if ( remaining . length > 0 ) {
834852 this . logger . info ( "Snapshot delay wheel stopped, dropped pending snapshots" , {
0 commit comments