Skip to content

Commit f6f6b9c

Browse files
fix(server): decode legacy restart model selections
1 parent 26b2636 commit f6f6b9c

4 files changed

Lines changed: 42 additions & 10 deletions

File tree

‎apps/server/src/provider/Layers/ProviderService.test.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,17 +2809,35 @@ routing.layer("ProviderServiceLive routing", (it) => {
28092809
}),
28102810
);
28112811

2812-
it.effect("recovers stale sessions for sendTurn using persisted cwd", () =>
2812+
it.effect("recovers stale sessions using persisted cwd and legacy model selection", () =>
28132813
Effect.gen(function* () {
28142814
const provider = yield* ProviderService.ProviderService;
2815+
const directory = yield* ProviderSessionDirectory.ProviderSessionDirectory;
2816+
const cwd = fixtureCwd("project-send-turn");
2817+
const modelSelection = createModelSelection(codexInstanceId, "gpt-5.4", [
2818+
{ id: "reasoningEffort", value: "high" },
2819+
]);
28152820

28162821
const initial = yield* provider.startSession(asThreadId("thread-1"), {
28172822
provider: ProviderDriverKind.make("codex"),
28182823
providerInstanceId: codexInstanceId,
28192824
threadId: asThreadId("thread-1"),
2820-
cwd: fixtureCwd("project-send-turn"),
2825+
cwd,
2826+
modelSelection,
28212827
runtimeMode: "full-access",
28222828
});
2829+
const binding = Option.getOrThrow(yield* directory.getBinding(initial.threadId));
2830+
yield* directory.upsert({
2831+
...binding,
2832+
runtimePayload: {
2833+
...(binding.runtimePayload as Record<string, unknown>),
2834+
modelSelection: {
2835+
provider: "codex",
2836+
model: modelSelection.model,
2837+
options: modelSelection.options,
2838+
},
2839+
},
2840+
});
28232841

28242842
yield* routing.codex.stopAll();
28252843
routing.codex.startSession.mockClear();
@@ -2838,11 +2856,13 @@ routing.layer("ProviderServiceLive routing", (it) => {
28382856
const startPayload = resumedStartInput as {
28392857
provider?: string;
28402858
cwd?: string;
2859+
modelSelection?: unknown;
28412860
resumeCursor?: unknown;
28422861
threadId?: string;
28432862
};
28442863
assert.equal(startPayload.provider, "codex");
2845-
assert.equal(startPayload.cwd, fixtureCwd("project-send-turn"));
2864+
assert.equal(startPayload.cwd, cwd);
2865+
assert.deepEqual(startPayload.modelSelection, modelSelection);
28462866
assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
28472867
assert.equal(startPayload.threadId, initial.threadId);
28482868
}

‎apps/server/src/provider/Layers/ProviderService.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
8686
import * as McpSessionRegistry from "../../mcp/McpSessionRegistry.ts";
8787
import * as ServerSettings from "../../serverSettings.ts";
8888
import * as ProjectionSnapshotQuery from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
89-
const isModelSelection = Schema.is(ModelSelection);
89+
const decodeModelSelectionOption = Schema.decodeUnknownOption(ModelSelection);
9090
const encodePromptJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
9191

9292
interface SnapShotPromptAccessibilityNode {
@@ -412,7 +412,7 @@ function readPersistedModelSelection(
412412
return undefined;
413413
}
414414
const raw = "modelSelection" in runtimePayload ? runtimePayload.modelSelection : undefined;
415-
return isModelSelection(raw) ? raw : undefined;
415+
return Option.getOrUndefined(decodeModelSelectionOption(raw));
416416
}
417417

418418
function readPersistedCwd(

‎apps/server/src/serverRuntimeStartup.reconcile.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const makeThread = (
5050
session: {
5151
threadId: ThreadId.make(id),
5252
status,
53-
providerName: "codex" as const,
53+
providerName: ProviderDriverKind.make("codex"),
5454
providerInstanceId,
5555
runtimeMode: "full-access" as const,
5656
activeTurnId,
@@ -198,6 +198,13 @@ it.effect.each(
198198
recovery === "marked update" ? null : fallbackContinuationTurnId,
199199
);
200200
const fallbackProviderInstanceId = ProviderInstanceId.make("claudeAgent");
201+
fallback.modelSelection = {
202+
instanceId: fallbackProviderInstanceId,
203+
model: "claude-opus-4-6",
204+
options: [{ id: "effort", value: "high" }],
205+
};
206+
fallback.session.providerName = ProviderDriverKind.make("claudeAgent");
207+
fallback.session.providerInstanceId = fallbackProviderInstanceId;
201208
const continuationSent = yield* Deferred.make<void>();
202209
const continuationCleared = yield* Deferred.make<void>();
203210
const sends: ProviderSendTurnInput[] = [];
@@ -384,6 +391,11 @@ it.effect("continues with the interrupted turn selection after thread metadata c
384391
const turnId = TurnId.make("turn-selection-changed");
385392
const thread = makeThread("thread-selection-changed", "running", turnId);
386393
const interruptedTurnSelection = thread.modelSelection;
394+
const legacyInterruptedTurnSelection = {
395+
provider: "codex",
396+
model: interruptedTurnSelection.model,
397+
options: interruptedTurnSelection.options,
398+
};
387399
thread.modelSelection = {
388400
instanceId: ProviderInstanceId.make("opencode"),
389401
model: "openai/gpt-5",
@@ -399,7 +411,7 @@ it.effect("continues with the interrupted turn selection after thread metadata c
399411
resumeCursor: { threadId: thread.id },
400412
runtimePayload: {
401413
activeTurnId: turnId,
402-
modelSelection: interruptedTurnSelection,
414+
modelSelection: legacyInterruptedTurnSelection,
403415
},
404416
};
405417

@@ -454,7 +466,7 @@ it.effect("continues with the interrupted turn selection after thread metadata c
454466
yield* Deferred.await(cleared);
455467
assert.deepStrictEqual(binding.runtimePayload, {
456468
activeTurnId: null,
457-
modelSelection: interruptedTurnSelection,
469+
modelSelection: legacyInterruptedTurnSelection,
458470
continueAfterServerUpdate: null,
459471
continueAfterServerUpdatePrepared: null,
460472
});

‎apps/server/src/serverRuntimeStartup.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ function readRuntimePayload(runtimePayload: unknown): Record<string, unknown> {
388388
: {};
389389
}
390390

391-
const isModelSelection = Schema.is(ModelSelection);
391+
const decodeModelSelectionOption = Schema.decodeUnknownOption(ModelSelection);
392392

393393
function readRuntimeModelSelection(runtimePayload: unknown): ModelSelection | undefined {
394394
const value = readRuntimePayload(runtimePayload).modelSelection;
395-
return isModelSelection(value) ? value : undefined;
395+
return Option.getOrUndefined(decodeModelSelectionOption(value));
396396
}
397397

398398
const isServerUpdateThreadContinuationError = Schema.is(ServerUpdateThreadContinuationError);

0 commit comments

Comments
 (0)