Skip to content

Commit 8c3e8cf

Browse files
committed
Fix orphaned spans
1 parent 0b612b9 commit 8c3e8cf

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • apps/sim/lib/copilot/request/lifecycle

apps/sim/lib/copilot/request/lifecycle/start.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff 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 }

0 commit comments

Comments
 (0)