From 8de28c12e4c77b5fe0089ddeaf9ea18d216344c9 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Sun, 18 Oct 2026 03:00:21 -0500 Subject: [PATCH] test(server): prove execution span overlap with explicit barriers (#16712) Prove overlapping execution spans with per-run promise barriers, live recording checks, and exported span identity matching. Preserve the existing run ownership, parent, ingress-link, count, and test-budget assertions. Co-Authored-By: Paperclip --- .../services/execution-timing-context.test.ts | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/server/src/services/execution-timing-context.test.ts b/server/src/services/execution-timing-context.test.ts index 7ac9ca1f6b1..5967453a7d4 100644 --- a/server/src/services/execution-timing-context.test.ts +++ b/server/src/services/execution-timing-context.test.ts @@ -32,11 +32,29 @@ afterEach(async () => { it("parents overlapping preparation and response work to their own execution attempts independently of ingress sampling", async () => { const trigger = { traceId: "1".repeat(32), spanId: "2".repeat(16), traceFlags: TraceFlags.NONE, isRemote: true }; + const overlappingSpanIds = new Map(); await context.with(trace.setSpanContext(context.active(), trigger), () => Promise.all(["one", "two"].map(runId => withRunExecutionTiming(runId, async () => { + let sourceSpan: ReturnType, readersSpan: ReturnType; + let started!: () => void, checked!: () => void; + const bothStarted = new Promise(resolve => { started = resolve; }); + const bothChecked = new Promise(resolve => { checked = resolve; }); + let arrivals = 0, observations = 0; + const assertOverlap = async () => { + if (++arrivals === 2) started(); + await bothStarted; + try { + expect(sourceSpan?.isRecording()).toBe(true); + expect(readersSpan?.isRecording()).toBe(true); + } finally { + if (++observations === 2) checked(); + } + await bothChecked; + }; await createRunPreparationTiming(runId)("workspace", () => Promise.all([ measureRunPhase("workspace.sources", async () => { - await Promise.resolve(); + sourceSpan = trace.getActiveSpan(); + await assertOverlap(); await measureRunPhase("workspace.sources.alias_scan", () => { const parent = getActiveStepContext()?.parentContext; expect(parent).toBeDefined(); @@ -44,8 +62,12 @@ it("parents overlapping preparation and response work to their own execution att expect(getRunExecutionTraceContext(runId === "one" ? "two" : "one")).toBeUndefined(); }); }), - measureRunPhase("workspace.readers", async () => { await Promise.resolve(); }), + measureRunPhase("workspace.readers", async () => { + readersSpan = trace.getActiveSpan(); + await assertOverlap(); + }), ])); + overlappingSpanIds.set(runId, { source: sourceSpan?.spanContext().spanId, readers: readersSpan?.spanContext().spanId }); await measureRunPhase("response.add_comment", () => undefined); }), ))); @@ -68,9 +90,7 @@ it("parents overlapping preparation and response work to their own execution att expect(readers.parentSpanContext?.spanId).toBe(phase.spanContext().spanId); expect(aliases.parentSpanContext?.spanId).toBe(source.spanContext().spanId); expect(reply.parentSpanContext?.spanId).toBe(attempt.spanContext().spanId); - const ns = (time: readonly [number, number]) => time[0] * 1e9 + time[1]; - expect(ns(readers.startTime)).toBeLessThanOrEqual(ns(source.endTime)); - expect(ns(source.startTime)).toBeLessThanOrEqual(ns(readers.endTime)); + expect(overlappingSpanIds.get(runId)).toEqual({ source: source.spanContext().spanId, readers: readers.spanContext().spanId }); expect(owned).toHaveLength(6); } expect(getRunExecutionTraceContext("one")).toBeUndefined();