Skip to content

The open-source app everyone uses to manage agents at work

test(server): prove execution span overlap with explicit barriers (#16712)

Dotta8de28c12e4c7
diff --git a/server/src/services/execution-timing-context.test.ts b/server/src/services/execution-timing-context.test.ts
index 7ac9ca1f6b..5967453a7d 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<string, { source: string | undefined; readers: string | undefined }>();
await context.with(trace.setSpanContext(context.active(), trigger), () => Promise.all(["one", "two"].map(runId =>
withRunExecutionTiming(runId, async () => {
+ let sourceSpan: ReturnType<typeof trace.getActiveSpan>, readersSpan: ReturnType<typeof trace.getActiveSpan>;
+ let started!: () => void, checked!: () => void;
+ const bothStarted = new Promise<void>(resolve => { started = resolve; });
+ const bothChecked = new Promise<void>(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();