Skip to content

Commit e9e0aa1

Browse files
fix(server): a failed lookup no longer drops a delegated task's analytics event
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0055bd7 commit e9e0aa1

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎apps/server/src/telemetry/DelegatedTaskAnalytics.test.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ const subagentEvent = (status: string, origin = "app_owned") =>
3131

3232
it.effect("records each delegated task's final outcome once, without ids or prompts", () => {
3333
const recorded: Array<{ event: string; properties: unknown }> = [];
34+
let shellLookups = 0;
3435
return Effect.gen(function* () {
3536
const analytics = yield* DelegatedTaskAnalytics.DelegatedTaskAnalytics;
3637
yield* analytics.onSubagent(subagentEvent("running"));
3738
yield* analytics.onSubagent(subagentEvent("completed", "provider_native"));
39+
// The first parent lookup fails; the next final update still reports the task.
40+
yield* analytics.onSubagent(subagentEvent("completed"));
3841
yield* analytics.onSubagent(subagentEvent("completed"));
3942
yield* analytics.onSubagent(subagentEvent("completed"));
4043
expect(recorded).toEqual([
@@ -60,12 +63,14 @@ it.effect("records each delegated task's final outcome once, without ids or prom
6063
Layer.mock(Orchestrator.OrchestratorV2)({
6164
streamDomainEvents: Stream.empty,
6265
getThreadShell: () =>
63-
Effect.succeed({
64-
modelSelection: {
65-
instanceId: ProviderInstanceId.make("codex"),
66-
model: "gpt-5.5",
67-
},
68-
} as never),
66+
++shellLookups === 1
67+
? Effect.die("thread store unavailable")
68+
: Effect.succeed({
69+
modelSelection: {
70+
instanceId: ProviderInstanceId.make("codex"),
71+
model: "gpt-5.5",
72+
},
73+
} as never),
6974
}),
7075
Layer.mock(ProviderRegistry.ProviderRegistry)({
7176
getProviders: Effect.succeed([

‎apps/server/src/telemetry/DelegatedTaskAnalytics.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const make = Effect.gen(function* () {
4545
const task = event.payload;
4646
if (task.origin !== "app_owned" || !FINAL_STATUSES.has(task.status)) return;
4747
if (reported.has(task.id)) return;
48-
reported.add(task.id);
4948
const parent = yield* orchestrator.getThreadShell(task.threadId);
5049
const providers = yield* registry.getProviders;
5150
const parentDimensions =
@@ -78,6 +77,8 @@ const make = Effect.gen(function* () {
7877
...(task.completionWake === undefined ? {} : { completionWake: task.completionWake }),
7978
...(durationSeconds === undefined ? {} : { durationSeconds }),
8079
});
80+
// Only after recording: a failed lookup leaves the next final update to report it.
81+
reported.add(task.id);
8182
}).pipe(Effect.ignoreCause);
8283

8384
yield* forkParked(

0 commit comments

Comments
 (0)