fix(server): record retried legacy handoffs

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-07-27 19:39:05 +02:00
1 parent 4600a83e98
commit 67ab204c23
2 files changed
+27 -1

No files matched your search

@@ -1,6 +1,7 @@
import { assert, it } from "@effect/vitest";
import { ContextHandoffId } from "@t3tools/contracts";
import { shouldPrepareLegacyImportHandoff } from "./Orchestrator.ts";
import { appendContextHandoffId, shouldPrepareLegacyImportHandoff } from "./Orchestrator.ts";
it("reissues imported context until the provider thread is materialized", () => {
assert.isTrue(
@@ -32,3 +33,17 @@ it("reissues imported context until the provider thread is materialized", () =>
}),
);
});
it("records a reissued legacy handoff on an existing provider thread", () => {
const existingHandoffId = ContextHandoffId.make("handoff:legacy-import:existing");
const retryHandoffId = ContextHandoffId.make("handoff:legacy-import:retry");
assert.deepEqual(appendContextHandoffId([existingHandoffId], retryHandoffId), [
existingHandoffId,
retryHandoffId,
]);
assert.deepEqual(appendContextHandoffId([existingHandoffId], existingHandoffId), [
existingHandoffId,
]);
assert.deepEqual(appendContextHandoffId([existingHandoffId], null), [existingHandoffId]);
});
@@ -459,6 +459,13 @@ export function shouldPrepareLegacyImportHandoff(input: {
);
}
export function appendContextHandoffId(
handoffIds: OrchestrationV2ProviderThread["handoffIds"],
handoffId: OrchestrationV2ContextHandoff["id"] | null,
): OrchestrationV2ProviderThread["handoffIds"] {
return handoffId === null ? handoffIds : Array.from(new Set([...handoffIds, handoffId]));
}
function rootProviderThreadsForProvider(
projection: OrchestrationV2ThreadProjection,
providerInstanceId: ModelSelection["instanceId"],
@@ -2626,6 +2633,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
...activeProviderThread,
providerSessionId,
lastRunOrdinal: ordinal,
handoffIds: appendContextHandoffId(
activeProviderThread.handoffIds,
legacyImportHandoff?.id ?? null,
),
updatedAt: now,
};
const attemptId = idAllocator.derive.runAttempt({ runId, attemptOrdinal: 1 });