Skip to content

Commit b30c3a1

Browse files
t3dotggclaude
andcommitted
fix: drop switch stamps from wakes, skip pending queues, trust the catalog
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a43c3ac commit b30c3a1

6 files changed

Lines changed: 23 additions & 16 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,15 +2057,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
20572057
startedAt: now,
20582058
completedAt: now,
20592059
updatedAt: now,
2060-
...(activeHandoff === null
2061-
? modelSwitchSince(
2062-
{
2063-
runs: projection.runs.filter((run) => run.id !== queuedRun.id),
2064-
turnItems: projection.turnItems,
2065-
},
2066-
queuedRun.modelSelection,
2067-
)
2068-
: {}),
2060+
...(activeHandoff === null ? modelSwitchSince(projection, queuedRun.modelSelection) : {}),
20692061
};
20702062
const handoffTurnItem: OrchestrationV2TurnItem | null =
20712063
activeHandoff === null

‎apps/server/src/orchestration-v2/modelSwitch.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe("modelSwitchSince", () => {
4040
run("queued", 3, "c", "queued"),
4141
run("undone", 4, "d", "rolled_back"),
4242
],
43-
turnItems: shown("first", "failed", "undone"),
43+
// A legacy pending queued message is in the items but has not run.
44+
turnItems: shown("first", "failed", "queued", "undone"),
4445
},
4546
selection("a"),
4647
),

‎apps/server/src/orchestration-v2/modelSwitch.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export function modelSwitchSince(
2222
);
2323
let previous: OrchestrationV2ThreadProjection["runs"][number] | undefined;
2424
for (const run of projection.runs) {
25-
if (run.status === "rolled_back" || !shown.has(run.userMessageId)) continue;
25+
// Pending queued messages are hidden until their run starts.
26+
if (run.status === "rolled_back" || run.status === "queued" || !shown.has(run.userMessageId)) {
27+
continue;
28+
}
2629
if (previous === undefined || runRanAfter(run, previous)) previous = run;
2730
}
2831
const from = previous?.modelSelection ?? baseline;

‎packages/client-runtime/src/handoff.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ describe("model switch change", () => {
231231
providers,
232232
),
233233
).toBeNull();
234+
// A cataloged model without an effort control ignores stale effort options.
235+
expect(
236+
resolveModelSwitchChange(
237+
{
238+
from: selection("plain", { reasoningEffort: "low" }),
239+
to: selection("plain", { reasoningEffort: "high" }),
240+
},
241+
[{ instanceId: from, models: [{ slug: "plain" }] }] as unknown as ServerProvider[],
242+
),
243+
).toBeNull();
234244
});
235245

236246
it("falls back to stated efforts without a catalog", () => {

‎packages/client-runtime/src/handoff.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,20 @@ export function resolveModelSwitchChange(
115115
return modelChanged || effort ? { modelChanged, effort } : null;
116116
}
117117

118-
/** The composer's reasoning control for the model; stated values only without a catalog. */
118+
/** The composer's reasoning control for the model; stated values only when the catalog lacks it. */
119119
function resolveEffort(
120120
selection: ModelSelection,
121121
models: ReadonlyArray<ServerProviderModel> | undefined,
122122
): { readonly value: string; readonly label: string } | undefined {
123-
const descriptor = models
124-
?.find((model) => model.slug === selection.model)
125-
?.capabilities?.optionDescriptors?.find(isReasoningSelect);
126-
if (descriptor === undefined) {
123+
const model = models?.find((candidate) => candidate.slug === selection.model);
124+
if (model === undefined) {
127125
const value = REASONING_EFFORT_OPTION_IDS.map((id) =>
128126
getModelSelectionStringOptionValue(selection, id),
129127
).find((candidate) => candidate !== undefined);
130128
return value === undefined ? undefined : { value, label: value };
131129
}
130+
const descriptor = model.capabilities?.optionDescriptors?.find(isReasoningSelect);
131+
if (descriptor === undefined) return undefined;
132132
const value =
133133
getModelSelectionStringOptionValue(selection, descriptor.id) ??
134134
getProviderOptionCurrentValue(descriptor, selection);

‎packages/provider-core/src/server/notification.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export function notificationTurnItem(
217217
createdBy: _createdBy,
218218
creationSource: _creationSource,
219219
scheduledTaskId: _scheduledTaskId,
220+
modelSwitch: _modelSwitch,
220221
...base
221222
} = item;
222223
return { ...base, type: "notification", ...notification };

0 commit comments

Comments
 (0)