Skip to content

Commit 11cb7d0

Browse files
refactor(server): trace the provider-exit lost-work ingestion as a named span
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5138245 commit 11cb7d0

1 file changed

Lines changed: 33 additions & 31 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderEventIngestor.ts‎

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -462,38 +462,40 @@ export const layer: Layer.Layer<
462462
});
463463

464464
// The run records what an unexpected process exit took, as a server restart would.
465-
const lostBackgroundWorkEvents = Effect.fnUntraced(function* (
466-
input: ProviderEventIngestInput,
467-
event: Extract<
468-
ProviderAdapter.ProviderAdapterV2Event,
469-
{ readonly type: "background_work.lost" }
470-
>,
471-
) {
472-
const threadId = event.threadId;
473-
const run = latestStartedRun(
474-
(yield* projections.getThreadRecords(threadId, ["runs"])).runs,
475-
event.providerThreadId,
476-
);
477-
if (run === undefined) return [];
478-
const work = event.tasks.map((task) => ({
479-
...cancelledRosterTaskWork(task),
480-
cause: "provider_exit" as const,
481-
}));
482-
return [
483-
yield* makeDomainEvent(input, {
484-
type: "run.background-work-cancelled",
485-
threadId,
486-
runId: run.id,
487-
payload: {
465+
const lostBackgroundWorkEvents = Effect.fn("ProviderEventIngestor.lostBackgroundWorkEvents")(
466+
function* (
467+
input: ProviderEventIngestInput,
468+
event: Extract<
469+
ProviderAdapter.ProviderAdapterV2Event,
470+
{ readonly type: "background_work.lost" }
471+
>,
472+
) {
473+
const threadId = event.threadId;
474+
const run = latestStartedRun(
475+
(yield* projections.getThreadRecords(threadId, ["runs"])).runs,
476+
event.providerThreadId,
477+
);
478+
if (run === undefined) return [];
479+
const work = event.tasks.map((task) => ({
480+
...cancelledRosterTaskWork(task),
481+
cause: "provider_exit" as const,
482+
}));
483+
return [
484+
yield* makeDomainEvent(input, {
485+
type: "run.background-work-cancelled",
486+
threadId,
488487
runId: run.id,
489-
restartCancelledBackgroundWork: mergeRestartCancelledBackgroundWork(
490-
run.restartCancelledBackgroundWork ?? [],
491-
work,
492-
),
493-
},
494-
}),
495-
];
496-
});
488+
payload: {
489+
runId: run.id,
490+
restartCancelledBackgroundWork: mergeRestartCancelledBackgroundWork(
491+
run.restartCancelledBackgroundWork ?? [],
492+
work,
493+
),
494+
},
495+
}),
496+
];
497+
},
498+
);
497499

498500
const normalize: ProviderEventIngestorV2Shape["normalize"] =
499501
/* This helper runs for individual orchestration events; the enclosing operation owns the span. */

0 commit comments

Comments
 (0)