Skip to content

Commit d92dca7

Browse files
fix(web): resume imported custom-provider threads (pingdotgg#10184)
1 parent 4ca7146 commit d92dca7

3 files changed

Lines changed: 128 additions & 24 deletions

File tree

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
buildThreadTurnInterruptInput,
2929
createLocalDispatchSnapshot,
3030
deriveComposerSendState,
31+
deriveLockedProvider,
3132
dismissBranchMismatchForSession,
3233
ENVIRONMENT_RECONNECT_WARNING_GRACE_MS,
3334
getAntigravitySendBlockReason,
@@ -792,6 +793,113 @@ describe("resolveComposerProviderSelection", () => {
792793
])[0]!;
793794
}
794795

796+
function importedThread(instanceId: ProviderInstanceId) {
797+
return makeThread({
798+
modelSelection: { instanceId, model: "default" },
799+
messages: [
800+
{
801+
id: MessageId.make(`import:${instanceId}:session:000000`),
802+
role: "user",
803+
text: "Continue the imported conversation",
804+
turnId: null,
805+
createdAt: now,
806+
updatedAt: now,
807+
streaming: false,
808+
},
809+
],
810+
});
811+
}
812+
813+
it.each([
814+
["claudeAgent", "claude_work"],
815+
["codex", "codex_work"],
816+
["ollama", "local_models"],
817+
])("keeps imported %s history selectable through its custom instance", (driver, instanceId) => {
818+
const importedEntry = entry(driver, instanceId);
819+
const entries = [entry(driver === "codex" ? "claudeAgent" : "codex"), importedEntry];
820+
const thread = importedThread(importedEntry.instanceId);
821+
const lockedProvider = deriveLockedProvider({
822+
thread,
823+
selectedProvider: entries[0]!.instanceId,
824+
threadProvider: thread.modelSelection.instanceId,
825+
providers: entries.map((entry) => entry.snapshot),
826+
});
827+
828+
expect(thread.session).toBeNull();
829+
expect(lockedProvider).toBe(driver);
830+
expect(
831+
resolveComposerProviderSelection({
832+
entries,
833+
candidateInstanceIds: [thread.modelSelection.instanceId],
834+
lockedProvider,
835+
lockedInstanceId: thread.modelSelection.instanceId,
836+
}).selectedProviderEntry?.instanceId,
837+
).toBe(importedEntry.instanceId);
838+
});
839+
840+
it("keeps the session driver authoritative over instance and draft selections", () => {
841+
const selected = entry("claudeAgent", "claude_work");
842+
const sessionEntry = entry("ollama", "local_models");
843+
const thread = importedThread(selected.instanceId);
844+
845+
expect(
846+
deriveLockedProvider({
847+
thread: {
848+
...thread,
849+
session: {
850+
...readySession,
851+
providerName: sessionEntry.driverKind,
852+
providerInstanceId: sessionEntry.instanceId,
853+
},
854+
},
855+
selectedProvider: selected.instanceId,
856+
threadProvider: thread.modelSelection.instanceId,
857+
providers: [selected.snapshot, sessionEntry.snapshot],
858+
}),
859+
).toBe(sessionEntry.driverKind);
860+
});
861+
862+
it.each(["missing", "disabled"] as const)(
863+
"does not move imported history to another driver when its instance is %s",
864+
(state) => {
865+
const imported = entry("claudeAgent", "claude_work", { enabled: false });
866+
const other = entry("codex");
867+
const entries = state === "missing" ? [other] : [other, imported];
868+
const thread = importedThread(imported.instanceId);
869+
const lockedProvider = deriveLockedProvider({
870+
thread,
871+
selectedProvider: other.instanceId,
872+
threadProvider: thread.modelSelection.instanceId,
873+
providers: entries.map((entry) => entry.snapshot),
874+
});
875+
876+
expect(lockedProvider).not.toBeNull();
877+
expect(
878+
resolveComposerProviderSelection({
879+
entries,
880+
candidateInstanceIds: [other.instanceId, imported.instanceId],
881+
lockedProvider,
882+
lockedInstanceId: imported.instanceId,
883+
}).selectedProviderEntry,
884+
).toBeUndefined();
885+
},
886+
);
887+
888+
it("leaves a new draft free to select a different driver", () => {
889+
const original = entry("claudeAgent", "claude_work");
890+
const selected = entry("codex", "codex_work");
891+
expect(
892+
deriveLockedProvider({
893+
thread: makeThread({
894+
modelSelection: { instanceId: original.instanceId, model: "default" },
895+
}),
896+
selectedProvider: selected.instanceId,
897+
threadProvider: original.instanceId,
898+
providers: [original.snapshot, selected.snapshot],
899+
}),
900+
).toBeNull();
901+
});
902+
795903
it("uses the custom instance's capability instead of the default instance", () => {
796904
const defaultEntry = entry("antigravity", "antigravity", {
797905
showInteractionModeToggle: true,

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -795,22 +795,13 @@ export function threadHasStarted(thread: Thread | null | undefined): boolean {
795795
);
796796
}
797797

798-
// `threadProvider` is the open branded driver kind carried by the session.
799-
// Unknown driver kinds degrade to `null` (i.e. "unlocked"), which is the safe
800-
// rollback / fork behavior — the routing layer is the right place to surface
801-
// "driver not installed" errors, not the lock state.
802-
//
803-
// `selectedProvider` takes the same open-string shape because the composer
804-
// now tracks the picker selection as a `ProviderInstanceId` (e.g.
805-
// `codex_personal`). Custom instance ids that don't directly match a
806-
// registered driver resolve to `null` here, which matches the existing
807-
// "unknown driver -> unlocked" semantics. Callers that want the lock to track
808-
// a custom instance's underlying driver kind should resolve the instance id
809-
// upstream and pass the correlated kind.
798+
// Imported history has no session until its first prompt. Resolve its instance
799+
// through the environment's provider catalog before locking to a driver.
810800
export function deriveLockedProvider(input: {
811801
thread: Thread | null | undefined;
812802
selectedProvider: string | null;
813803
threadProvider: string | null;
804+
providers: ReadonlyArray<Pick<ServerProvider, "instanceId" | "driver">>;
814805
}): ProviderDriverKind | null {
815806
if (!threadHasStarted(input.thread)) {
816807
return null;
@@ -819,14 +810,18 @@ export function deriveLockedProvider(input: {
819810
if (sessionProvider && isProviderDriverKind(sessionProvider)) {
820811
return sessionProvider;
821812
}
813+
// Preserve the existing lock while an instance is missing from the catalog;
814+
// a started thread must not silently fall back to a different driver.
815+
const threadProvider =
816+
input.providers.find((provider) => provider.instanceId === input.threadProvider)?.driver ??
817+
input.threadProvider;
818+
const selectedProvider =
819+
input.providers.find((provider) => provider.instanceId === input.selectedProvider)?.driver ??
820+
input.selectedProvider;
822821
const narrowedThreadProvider =
823-
input.threadProvider && isProviderDriverKind(input.threadProvider)
824-
? input.threadProvider
825-
: null;
822+
threadProvider && isProviderDriverKind(threadProvider) ? threadProvider : null;
826823
const narrowedSelectedProvider =
827-
input.selectedProvider && isProviderDriverKind(input.selectedProvider)
828-
? input.selectedProvider
829-
: null;
824+
selectedProvider && isProviderDriverKind(selectedProvider) ? selectedProvider : null;
830825
return narrowedThreadProvider ?? narrowedSelectedProvider ?? null;
831826
}
832827

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,12 @@ export default function ChatView(props: ChatViewProps) {
22582258
[openOrReuseProjectDraftThread],
22592259
);
22602260

2261+
// Once a thread selects an environment, never substitute the primary
2262+
// environment's config while the selected environment is still loading.
2263+
const serverConfig = activeThread
2264+
? (activeEnvironment?.serverConfig ?? null)
2265+
: (primaryEnvironment?.serverConfig ?? null);
2266+
const providerStatuses = serverConfig?.providers ?? EMPTY_PROVIDERS;
22612267
const selectedProviderByThreadId = composerActiveProvider ?? null;
22622268
const threadProvider =
22632269
activeThread?.modelSelection.instanceId ??
@@ -2267,12 +2273,8 @@ export default function ChatView(props: ChatViewProps) {
22672273
thread: activeThread,
22682274
selectedProvider: selectedProviderByThreadId,
22692275
threadProvider,
2276+
providers: providerStatuses,
22702277
});
2271-
// Once a thread selects an environment, never substitute the primary
2272-
// environment's config while the selected environment is still loading.
2273-
const serverConfig = activeThread
2274-
? (activeEnvironment?.serverConfig ?? null)
2275-
: (primaryEnvironment?.serverConfig ?? null);
22762278
const pullRequestsCapabilityKnown = serverConfig !== null;
22772279
const supportsPullRequests = serverConfig?.environment.capabilities.pullRequests === true;
22782280
const attachmentEnvironmentConfig = environmentById.get(environmentId)?.serverConfig ?? null;
@@ -2484,7 +2486,6 @@ export default function ChatView(props: ChatViewProps) {
24842486
versionMismatchThreadContinuation,
24852487
versionMismatchServerLabel,
24862488
]);
2487-
const providerStatuses = serverConfig?.providers ?? EMPTY_PROVIDERS;
24882489
const providerInstanceEntries = useMemo(
24892490
() =>
24902491
sortProviderInstanceEntries(

0 commit comments

Comments
 (0)