File tree Expand file tree Collapse file tree
apps/sim/lib/copilot/request/lifecycle Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -164,14 +164,22 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
164164 const otelContext = activeOtelRoot . context
165165 let rootOutcome : CopilotLifecycleOutcome = RequestTraceV1Outcome . error
166166 let rootError : unknown
167+ // `cancelReason` must be declared OUTSIDE the outer `try` so
168+ // it remains in scope for the outer `finally` that calls
169+ // `activeOtelRoot.finish(rootOutcome, rootError, cancelReason)`.
170+ // `let` bindings declared inside a `try` block are NOT visible
171+ // in the paired `finally`; referencing one there raises a
172+ // TDZ ReferenceError, skipping `finish()`, leaving the root
173+ // span never-ended, and making Tempo see every child as an
174+ // orphan under a phantom parent. (Regression landed 2026-04-21.)
175+ let cancelReason : CopilotRequestCancelReasonValue | undefined
167176 try {
168177 const requestSpan = collector . startSpan ( 'Mothership Request' , 'request' , {
169178 streamId,
170179 chatId,
171180 runId,
172181 } )
173182 let outcome : CopilotLifecycleOutcome = RequestTraceV1Outcome . error
174- let cancelReason : CopilotRequestCancelReasonValue | undefined
175183 let lifecycleResult :
176184 | {
177185 usage ?: { prompt : number ; completion : number }
You can’t perform that action at this time.
0 commit comments