diff --git a/apps/mobile/src/features/threads/thread-handoff-row.tsx b/apps/mobile/src/features/threads/thread-handoff-row.tsx
index 7158a9968bcc..a6ac68ed7535 100644
--- a/apps/mobile/src/features/threads/thread-handoff-row.tsx
+++ b/apps/mobile/src/features/threads/thread-handoff-row.tsx
@@ -94,13 +94,14 @@ export function ThreadHandoffRow(props: {
const endpoints = useAtomValue(endpointsAtom);
if (item.type !== "handoff" || endpoints === null) return null;
const color = item.status === "failed" ? "#e11d48" : props.iconColor;
+ const label = endpoints.isRecoveredContext ? gt("Recovered context") : gt("Context handoff");
return (
);
@@ -116,6 +117,7 @@ export function ThreadHandoffDivider(props: {
}) {
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
const { endpoints } = props;
+ const showFromEndpoints = !endpoints.isRecoveredContext && endpoints.from.length > 0;
const endpointProps = {
providers: (config?.providers ?? []).map((provider) => {
const rawConfig = config?.settings.providerInstances[provider.instanceId]?.config;
@@ -141,20 +143,22 @@ export function ThreadHandoffDivider(props: {
failed={props.failed}
>
- {endpoints.from.map((endpoint, index) => (
-
-
- {index < endpoints.from.length - 1 ? (
-
- ,
-
- ) : null}
-
- ))}
- {endpoints.from.length > 0 ? (
+ {showFromEndpoints
+ ? endpoints.from.map((endpoint, index) => (
+
+
+ {index < endpoints.from.length - 1 ? (
+
+ ,
+
+ ) : null}
+
+ ))
+ : null}
+ {showFromEndpoints ? (
) : null}
diff --git a/apps/web/src/components/chat/V2LifecycleRow.tsx b/apps/web/src/components/chat/V2LifecycleRow.tsx
index 940e741b9c48..1b2621a2f5c8 100644
--- a/apps/web/src/components/chat/V2LifecycleRow.tsx
+++ b/apps/web/src/components/chat/V2LifecycleRow.tsx
@@ -669,36 +669,45 @@ export function HandoffRow(props: {
readonly failed?: boolean;
}) {
const gt = useGT();
- const { from: fromEndpoints, to } = props.endpoints;
+ const { from: fromEndpoints, to, isRecoveredContext } = props.endpoints;
const settings = useAtomValue(serverEnvironment.settingsValueAtom(props.environmentId));
const derived = deriveProviderInstanceEntries(props.providers);
const entries = settings ? applyProviderInstanceSettings(derived, settings, null) : derived;
+ const showFromEndpoints = !isRecoveredContext && fromEndpoints.length > 0;
return (
- {fromEndpoints.map((endpoint, index) => (
-
-
- {index < fromEndpoints.length - 1 ? (
-
- ,
+ {showFromEndpoints
+ ? fromEndpoints.map((endpoint, index) => (
+
+
+ {index < fromEndpoints.length - 1 ? (
+
+ ,
+
+ ) : null}
- ) : null}
-
- ))}
- {fromEndpoints.length > 0 ? (
+ ))
+ : null}
+ {showFromEndpoints ? (
) : null}
diff --git a/packages/client-runtime/src/handoff.test.ts b/packages/client-runtime/src/handoff.test.ts
index d2f5fb4e7890..77e30106b119 100644
--- a/packages/client-runtime/src/handoff.test.ts
+++ b/packages/client-runtime/src/handoff.test.ts
@@ -1,6 +1,7 @@
import {
ContextHandoffId,
ProviderInstanceId,
+ ProviderThreadId,
RunId,
type OrchestrationV2ThreadProjection,
type ServerProvider,
@@ -73,6 +74,42 @@ describe("handoff endpoints shared by web and mobile", () => {
resolveHandoffEndpoints(item, [run("target", 2, from, "wrong-model")]).to.model,
).toBeUndefined();
});
+
+ it("recognizes recovered context from same provider thread and omits self-handoff arrow", () => {
+ const threadId = ProviderThreadId.make("session-1");
+ const sameInstance = ProviderInstanceId.make("antigravity");
+ const recoveryItem = {
+ runId: RunId.make("target"),
+ title: "Recovered context",
+ fromProviderThreadIds: [threadId],
+ toProviderThreadId: threadId,
+ fromProviderInstanceIds: [sameInstance],
+ toProviderInstanceId: sameInstance,
+ fromModelSelections: [{ instanceId: sameInstance, model: "4 Neon" }],
+ toModel: "4 Neon",
+ };
+ expect(resolveHandoffEndpoints(recoveryItem, [])).toEqual({
+ from: [],
+ to: { instanceId: sameInstance, model: "4 Neon" },
+ isRecoveredContext: true,
+ });
+ });
+
+ it("treats same origin and destination model and provider as recovered context", () => {
+ const sameInstance = ProviderInstanceId.make("devReplay");
+ const selfHandoffItem = {
+ runId: RunId.make("target"),
+ fromProviderInstanceIds: [sameInstance],
+ toProviderInstanceId: sameInstance,
+ fromModelSelections: [{ instanceId: sameInstance, model: "Multi turn" }],
+ toModel: "Multi turn",
+ };
+ expect(resolveHandoffEndpoints(selfHandoffItem, [])).toEqual({
+ from: [],
+ to: { instanceId: sameInstance, model: "Multi turn" },
+ isRecoveredContext: true,
+ });
+ });
});
const projection = {
diff --git a/packages/client-runtime/src/handoff.ts b/packages/client-runtime/src/handoff.ts
index 48a122742931..fe25317a08a4 100644
--- a/packages/client-runtime/src/handoff.ts
+++ b/packages/client-runtime/src/handoff.ts
@@ -4,6 +4,7 @@ import type {
OrchestrationV2Run,
OrchestrationV2TurnItem,
ProviderInstanceId,
+ ProviderThreadId,
ServerProvider,
ServerProviderModel,
} from "@t3tools/contracts";
@@ -21,7 +22,17 @@ export type HandoffTimelineRun = Pick<
"id" | "ordinal" | "providerInstanceId" | "modelSelection"
>;
-export type HandoffEndpoints = ReturnType;
+export type HandoffEndpoints = {
+ readonly from: ReadonlyArray<{
+ readonly instanceId: ProviderInstanceId;
+ readonly model?: string | undefined;
+ }>;
+ readonly to: {
+ readonly instanceId: ProviderInstanceId;
+ readonly model?: string | undefined;
+ };
+ readonly isRecoveredContext?: boolean | undefined;
+};
export function resolvePendingHandoff(
projection: Pick | null | undefined,
@@ -53,9 +64,13 @@ export function resolveHandoffEndpoints(
item: Pick<
Extract,
"runId" | "fromModelSelections" | "fromProviderInstanceIds" | "toModel" | "toProviderInstanceId"
- >,
+ > & {
+ readonly title?: string | null | undefined;
+ readonly fromProviderThreadIds?: ReadonlyArray | undefined;
+ readonly toProviderThreadId?: ProviderThreadId | undefined;
+ },
runs: ReadonlyArray,
-) {
+): HandoffEndpoints {
const handoffRun = item.runId === null ? undefined : runs.find((run) => run.id === item.runId);
const toModel =
item.toModel ??
@@ -72,7 +87,23 @@ export function resolveHandoffEndpoints(
instanceId,
model: latestRunModelBefore(runs, instanceId, handoffRun?.ordinal),
}));
- return { from: fromEndpoints, to: { instanceId: item.toProviderInstanceId, model: toModel } };
+ const isRecoveredContext = Boolean(
+ item.title === "Recovered context" ||
+ (item.fromProviderThreadIds !== undefined &&
+ item.toProviderThreadId !== undefined &&
+ item.fromProviderThreadIds.length === 1 &&
+ item.fromProviderThreadIds[0] === item.toProviderThreadId) ||
+ (fromEndpoints.length === 1 &&
+ fromEndpoints[0]!.instanceId === item.toProviderInstanceId &&
+ (fromEndpoints[0]!.model === toModel ||
+ fromEndpoints[0]!.model === undefined ||
+ toModel === undefined)),
+ );
+ return {
+ from: isRecoveredContext ? [] : fromEndpoints,
+ to: { instanceId: item.toProviderInstanceId, model: toModel },
+ ...(isRecoveredContext ? { isRecoveredContext: true } : {}),
+ };
}
function latestRunModelBefore(