Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/mobile/src/features/threads/thread-handoff-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Dialog from "../../components/ui/Dialog";
import { useAtomValue } from "@effect/atom-react";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
isRecoveryHandoff,
resolveHandoffEndpoints,
resolveModelSwitchChange,
type HandoffEndpoints,
Expand Down Expand Up @@ -100,7 +101,7 @@ export function ThreadHandoffRow(props: {
endpoints={endpoints}
iconColor={color}
surfaceColor={props.surfaceColor}
label={gt("Context handoff")}
label={isRecoveryHandoff(item) ? gt("Recovered context") : gt("Context handoff")}
failed={item.status === "failed"}
/>
);
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4694,6 +4694,7 @@
"97ad838fc2717591": "Ausgabe wird geladen…",
"b2de62817c6ab53d": "Keine Ausgabe.",
"346e42415ac6d374": "Frühere Ausgabe nicht angezeigt",
"b5a8acfa085f459a": "Wiederhergestellter Kontext",
"4d765811334b8edf": "Kontextübergabe",
"0e7207133e1d9277": "Anbieterkonto anzeigen",
"3747414e652cca55": "Thread maximieren",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4695,6 +4695,7 @@
"97ad838fc2717591": "Loading output…",
"b2de62817c6ab53d": "No output.",
"346e42415ac6d374": "Earlier output not shown",
"b5a8acfa085f459a": "Recovered context",
"4d765811334b8edf": "Context handoff",
"0e7207133e1d9277": "Show provider account",
"3747414e652cca55": "Maximize thread",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -4687,6 +4687,7 @@
"97ad838fc2717591": "Cargando la salida…",
"b2de62817c6ab53d": "Sin salida.",
"346e42415ac6d374": "No se muestra la salida anterior",
"b5a8acfa085f459a": "Contexto recuperado",
"4d765811334b8edf": "Traspaso de contexto",
"0e7207133e1d9277": "Mostrar cuenta del proveedor",
"3747414e652cca55": "Maximizar hilo",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,7 @@
"97ad838fc2717591": "Chargement de la sortie…",
"b2de62817c6ab53d": "Aucune sortie.",
"346e42415ac6d374": "Sortie antérieure non affichée",
"b5a8acfa085f459a": "Contexte récupéré",
"4d765811334b8edf": "Transfert de contexte",
"0e7207133e1d9277": "Afficher le compte du fournisseur",
"3747414e652cca55": "Agrandir le fil",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4669,6 +4669,7 @@
"97ad838fc2717591": "出力を読み込んでいます…",
"b2de62817c6ab53d": "出力はありません。",
"346e42415ac6d374": "以前の出力は表示されていません",
"b5a8acfa085f459a": "復元されたコンテキスト",
"4d765811334b8edf": "コンテキストの引き継ぎ",
"0e7207133e1d9277": "プロバイダーのアカウントを表示",
"3747414e652cca55": "スレッドを最大化",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -4674,6 +4674,7 @@
"97ad838fc2717591": "출력을 불러오는 중…",
"b2de62817c6ab53d": "출력이 없습니다.",
"346e42415ac6d374": "이전 출력은 표시되지 않음",
"b5a8acfa085f459a": "복구된 컨텍스트",
"4d765811334b8edf": "컨텍스트 인계",
"0e7207133e1d9277": "제공자 계정 표시",
"3747414e652cca55": "스레드 최대화",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,7 @@
"97ad838fc2717591": "Carregando a saída…",
"b2de62817c6ab53d": "Sem saída.",
"346e42415ac6d374": "Saída anterior não mostrada",
"b5a8acfa085f459a": "Contexto recuperado",
"4d765811334b8edf": "Transferência de contexto",
"0e7207133e1d9277": "Mostrar conta do provedor",
"3747414e652cca55": "Maximizar thread",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4766,6 +4766,7 @@
"97ad838fc2717591": "Загрузка вывода…",
"b2de62817c6ab53d": "Нет вывода.",
"346e42415ac6d374": "Более ранний вывод не показан",
"b5a8acfa085f459a": "Контекст восстановлен",
"4d765811334b8edf": "Передача контекста",
"0e7207133e1d9277": "Показать аккаунт провайдера",
"3747414e652cca55": "Развернуть тред",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -4694,6 +4694,7 @@
"97ad838fc2717591": "Läser in utdata…",
"b2de62817c6ab53d": "Inga utdata.",
"346e42415ac6d374": "Tidigare utdata visas inte",
"b5a8acfa085f459a": "Återställd kontext",
"4d765811334b8edf": "Kontextöverlämning",
"0e7207133e1d9277": "Visa leverantörskonto",
"3747414e652cca55": "Maximera tråden",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,7 @@
"97ad838fc2717591": "正在加载输出…",
"b2de62817c6ab53d": "没有输出。",
"346e42415ac6d374": "更早的输出未显示",
"b5a8acfa085f459a": "已恢复上下文",
"4d765811334b8edf": "上下文交接",
"0e7207133e1d9277": "显示提供方账户",
"3747414e652cca55": "最大化会话",
Expand Down
12 changes: 11 additions & 1 deletion apps/web/src/components/chat/V2LifecycleRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MiddleTruncate } from "../ui/middle-truncate";
import * as DateTime from "effect/DateTime";
import { WorkLogRow } from "./WorkLog";
import {
isRecoveryHandoff,
resolveHandoffEndpoints,
type HandoffEndpoints,
type HandoffTimelineRun,
Expand Down Expand Up @@ -96,6 +97,7 @@ export function V2LifecycleRow(props: {
<EnvironmentHandoffRow
environmentId={props.environmentId}
endpoints={resolveHandoffEndpoints(item, props.runs)}
recovery={isRecoveryHandoff(item)}
failed={item.status === "failed"}
/>
);
Expand Down Expand Up @@ -624,6 +626,7 @@ function EnvironmentHandoffRow({
}: {
readonly environmentId: EnvironmentId;
readonly endpoints: HandoffEndpoints;
readonly recovery: boolean;
readonly failed: boolean;
}) {
const providers =
Expand Down Expand Up @@ -666,6 +669,7 @@ export function HandoffRow(props: {
readonly endpoints: HandoffEndpoints;
readonly providers: ReadonlyArray<ServerProvider>;
readonly pending?: boolean;
readonly recovery?: boolean;
readonly failed?: boolean;
}) {
const gt = useGT();
Expand All @@ -675,7 +679,13 @@ export function HandoffRow(props: {
const entries = settings ? applyProviderInstanceSettings(derived, settings, null) : derived;
return (
<TimelineSystemDivider
label={props.pending ? gt("Context handoff pending") : gt("Context handoff")}
label={
props.pending
? gt("Context handoff pending")
: props.recovery
? gt("Recovered context")
: gt("Context handoff")
}
icon={ArrowRightLeftIcon}
showDetailSeparator={false}
tone={props.failed ? "danger" : "neutral"}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,7 @@
"c026ded437a942ee": "auf {environment}",
"29b99b6828ed8295": "Neue Sitzung",
"42606de8b5a5e786": "Kontextübergabe ausstehend",
"b5a8acfa085f459a": "Wiederhergestellter Kontext",
"4d765811334b8edf": "Kontextübergabe",
"54915723f9384a19": [
"Thread erstellt · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4479,6 +4479,7 @@
"c026ded437a942ee": "on {environment}",
"29b99b6828ed8295": "New session",
"42606de8b5a5e786": "Context handoff pending",
"b5a8acfa085f459a": "Recovered context",
"4d765811334b8edf": "Context handoff",
"54915723f9384a19": [
"Created thread · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,7 @@
"c026ded437a942ee": "en {environment}",
"29b99b6828ed8295": "Sesión nueva",
"42606de8b5a5e786": "Traspaso de contexto pendiente",
"b5a8acfa085f459a": "Contexto recuperado",
"4d765811334b8edf": "Traspaso de contexto",
"54915723f9384a19": [
"Hilo creado · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -4478,6 +4478,7 @@
"c026ded437a942ee": "sur {environment}",
"29b99b6828ed8295": "Nouvelle session",
"42606de8b5a5e786": "Transfert de contexte en attente",
"b5a8acfa085f459a": "Contexte récupéré",
"4d765811334b8edf": "Transfert de contexte",
"54915723f9384a19": [
"Fil créé · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -4468,6 +4468,7 @@
"c026ded437a942ee": "{environment} 上",
"29b99b6828ed8295": "新しいセッション",
"42606de8b5a5e786": "コンテキストの引き継ぎを保留中",
"b5a8acfa085f459a": "復元されたコンテキスト",
"4d765811334b8edf": "コンテキストの引き継ぎ",
"54915723f9384a19": [
"スレッドを作成しました · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -4465,6 +4465,7 @@
"c026ded437a942ee": "{environment}에서",
"29b99b6828ed8295": "새 세션",
"42606de8b5a5e786": "컨텍스트 인계 대기 중",
"b5a8acfa085f459a": "복구된 컨텍스트",
"4d765811334b8edf": "컨텍스트 인계",
"54915723f9384a19": [
"스레드 만듦 · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,7 @@
"c026ded437a942ee": "em {environment}",
"29b99b6828ed8295": "Nova sessão",
"42606de8b5a5e786": "Transferência de contexto pendente",
"b5a8acfa085f459a": "Contexto recuperado",
"4d765811334b8edf": "Transferência de contexto",
"54915723f9384a19": [
"Thread criada · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,7 @@
"c026ded437a942ee": "на {environment}",
"29b99b6828ed8295": "Новый сеанс",
"42606de8b5a5e786": "Ожидается передача контекста",
"b5a8acfa085f459a": "Контекст восстановлен",
"4d765811334b8edf": "Передача контекста",
"54915723f9384a19": [
"Тред создан · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -4478,6 +4478,7 @@
"c026ded437a942ee": "på {environment}",
"29b99b6828ed8295": "Ny session",
"42606de8b5a5e786": "Kontextöverlämning väntar",
"b5a8acfa085f459a": "Återställd kontext",
"4d765811334b8edf": "Kontextöverlämning",
"54915723f9384a19": [
"Skapade tråd · ",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4484,6 +4484,7 @@
"c026ded437a942ee": "位于 {environment}",
"29b99b6828ed8295": "全新上下文",
"42606de8b5a5e786": "上下文交接待处理",
"b5a8acfa085f459a": "已恢复上下文",
"4d765811334b8edf": "上下文交接",
"54915723f9384a19": [
"已创建会话 · ",
Expand Down
15 changes: 15 additions & 0 deletions packages/client-runtime/src/handoff.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
ContextHandoffId,
ProviderInstanceId,
ProviderThreadId,
RunId,
type OrchestrationV2ThreadProjection,
type ServerProvider,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import {
isRecoveryHandoff,
resolveHandoffEndpoints,
resolveModelSwitchChange,
resolvePendingHandoff,
Expand All @@ -17,6 +19,8 @@ const from = ProviderInstanceId.make("codex_personal");
const to = ProviderInstanceId.make("claudeAgent");
const item = {
runId: RunId.make("target"),
fromProviderThreadIds: [ProviderThreadId.make("source-thread")],
toProviderThreadId: ProviderThreadId.make("target-thread"),
fromProviderInstanceIds: [from],
toProviderInstanceId: to,
};
Expand Down Expand Up @@ -73,6 +77,17 @@ describe("handoff endpoints shared by web and mobile", () => {
resolveHandoffEndpoints(item, [run("target", 2, from, "wrong-model")]).to.model,
).toBeUndefined();
});

it("treats a provider conversation restarted in a fresh session of itself as a recovery", () => {
const sameModel = { fromModelSelections: [{ instanceId: to, model: "same" }], toModel: "same" };
const recovery = { ...item, ...sameModel, fromProviderThreadIds: [item.toProviderThreadId] };
expect(isRecoveryHandoff(recovery)).toBe(true);
expect(resolveHandoffEndpoints(recovery, []).from).toEqual([]);
// A fork or merge-back between two conversations on one model is still a handoff.
const fork = { ...item, ...sameModel };
expect(isRecoveryHandoff(fork)).toBe(false);
expect(resolveHandoffEndpoints(fork, []).from).toEqual(sameModel.fromModelSelections);
});
});

const projection = {
Expand Down
31 changes: 29 additions & 2 deletions packages/client-runtime/src/handoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ export function resolvePendingHandoff(
export function resolveHandoffEndpoints(
item: Pick<
Extract<OrchestrationV2TurnItem, { type: "handoff" }>,
"runId" | "fromModelSelections" | "fromProviderInstanceIds" | "toModel" | "toProviderInstanceId"
| "runId"
| "fromProviderThreadIds"
| "toProviderThreadId"
| "fromModelSelections"
| "fromProviderInstanceIds"
| "toModel"
| "toProviderInstanceId"
>,
runs: ReadonlyArray<HandoffTimelineRun>,
) {
Expand All @@ -72,7 +78,28 @@ export function resolveHandoffEndpoints(
instanceId,
model: latestRunModelBefore(runs, instanceId, handoffRun?.ordinal),
}));
return { from: fromEndpoints, to: { instanceId: item.toProviderInstanceId, model: toModel } };
return {
from: isRecoveryHandoff(item) ? [] : fromEndpoints,
to: { instanceId: item.toProviderInstanceId, model: toModel },
};
}

/**
* Whether every source of the handoff is its own target conversation, as when a provider
* conversation restarts in a fresh session of itself after a failed resume or a rollback it
* cannot truncate. Nothing changed hands, so it has no source. Matching on the model instead
* would also catch a fork or a merge-back between two conversations that happen to share one.
*/
export function isRecoveryHandoff(
item: Pick<
Extract<OrchestrationV2TurnItem, { type: "handoff" }>,
"fromProviderThreadIds" | "toProviderThreadId"
>,
): boolean {
return (
item.fromProviderThreadIds.length > 0 &&
item.fromProviderThreadIds.every((id) => id === item.toProviderThreadId)
);
}

function latestRunModelBefore(
Expand Down
Loading