Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/server-utils/src/ai/pi-durable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ function runPhase(

const runInScope = async (scope: Scope): Promise<unknown> => {
// Read at the first phase of a run, which is a `pi.tool` phase when a restarted Harness reruns a
// tool call.
// tool call, and at each phase outside a run, such as an idle compaction or a task of an extension.
let sessionId = run?.sessionId;
if (!sessionId && (run || kind === PI_TASK.COMPACTION)) {
if (!sessionId) {
sessionId = await readProviderSessionId(runtime, context);
if (run && sessionId) {
run.sessionId = sessionId;
Expand Down
29 changes: 29 additions & 0 deletions packages/server-utils/test/ai/lib/tracing/pi-durable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,35 @@ describe('instrumentPiDurableHarnessOptions', () => {
);
});

it('uses the provider session id for a task of an extension on an idle conversation', async () => {
const sessionId = '019a2b3c-4d5e-7f60-8172-93a4b5c6d7e8';
const task: PiTask = {
definition: {
name: 'app.title',
phases: {
request: async () => {
await harness.models!.completeSimple!(MODEL, { messages: [] });
},
},
},
};
const harness: PiHarnessOptions = instrumentPiDurableHarnessOptions({
models: { completeSimple: async () => ANSWER },
registry: { snapshot: () => ({ task: () => task, tasks: () => [task] }), subscribe: () => () => undefined },
});
const runtime: PiTaskRuntime = {
taskId: 7,
conversationId: 1,
agent: async () => ({}),
commit: async () => undefined,
snapshot: async () => ({ sessionId }),
};

await harness.registry!.snapshot().task('app.title')!.definition.phases.request!(undefined, runtime, undefined);

expect(spanToJSON(endedSpans[0]!).attributes[GEN_AI_CONVERSATION_ID]).toBe(sessionId);
});

it('ends the open runs when the Harness closes', async () => {
const harness = harnessFor(generationPhase([{ run: { inputs: [5] } }]));
let onClose: (() => void) | undefined;
Expand Down
Loading