Skip to content

Commit 79ca042

Browse files
committed
fix(claude): delegated tasks and effort labels read a saved Ultracode effort
Delegated task options and the thread effort label read effort directly, so a saved effort "ultracode" was rejected for agents, dropped Ultracode when a child overrode only effort, and showed no label. Both now apply the same legacy reading as the picker: xhigh with Ultracode on.
1 parent ba9d7b9 commit 79ca042

5 files changed

Lines changed: 147 additions & 11 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.test.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,101 @@ describe("OrchestratorMcpService provider resolution", () => {
25632563
}),
25642564
);
25652565

2566+
it.effect("reads a saved Ultracode effort as xhigh with Ultracode on for delegated options", () =>
2567+
Effect.gen(function* () {
2568+
const model = "claude-opus-5-5";
2569+
const inherited = {
2570+
instanceId: codexInstanceId,
2571+
model,
2572+
options: [{ id: "effort", value: "ultracode" }],
2573+
};
2574+
const capabilities = {
2575+
optionDescriptors: [
2576+
{
2577+
id: "effort",
2578+
label: "Reasoning",
2579+
type: "select" as const,
2580+
options: [
2581+
{ id: "high", label: "High", isDefault: true },
2582+
{ id: "xhigh", label: "Extra High" },
2583+
{ id: "max", label: "Max" },
2584+
],
2585+
},
2586+
{ id: "ultracode", label: "Ultracode", type: "boolean" as const },
2587+
],
2588+
};
2589+
const cases = [
2590+
{ effort: "max", expected: "max" },
2591+
{ effort: "ultracode", expected: "xhigh" },
2592+
];
2593+
for (const testCase of cases) {
2594+
const commands: Array<unknown> = [];
2595+
const task = {
2596+
id: taskId,
2597+
threadId: parentThreadId,
2598+
origin: "app_owned",
2599+
childThreadId,
2600+
providerInstanceId: codexInstanceId,
2601+
model,
2602+
status: "running",
2603+
result: null,
2604+
};
2605+
const dependencies = Layer.mergeAll(
2606+
NodeServices.layer,
2607+
Layer.mock(ThreadManagementService.ThreadManagementService)({
2608+
hasReceipt: () => Effect.succeed(false),
2609+
assertProviderInstanceEnabled: () => Effect.void,
2610+
getThreadRecords: (threadId) =>
2611+
Effect.succeed(
2612+
threadId === parentThreadId
2613+
? parentProjection(commands.length > 0 ? [task] : [], inherited)
2614+
: childProjection,
2615+
),
2616+
dispatch: (command) =>
2617+
Effect.sync(() => {
2618+
commands.push(command);
2619+
return {
2620+
sequence: 1,
2621+
storedEvents: [{ event: { type: "subagent.updated", payload: task } }],
2622+
} as never;
2623+
}),
2624+
}),
2625+
ServerSettings.layerTest(),
2626+
providerRegistryLayer([
2627+
{
2628+
...providerSnapshot({
2629+
instanceId: codexInstanceId,
2630+
driver: ProviderDriverKind.make("codex"),
2631+
}),
2632+
models: [{ slug: model, name: model, isCustom: false, capabilities }],
2633+
},
2634+
]),
2635+
adapterRegistryLayer([codexInstanceId]),
2636+
Layer.mock(ProjectService.ProjectService)({}),
2637+
Layer.mock(SecretRequests.SecretRequests)({}),
2638+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
2639+
);
2640+
yield* Effect.gen(function* () {
2641+
const service = yield* OrchestratorMcpService.OrchestratorMcpService;
2642+
yield* service.delegateTask(scope, {
2643+
task: "Review the change.",
2644+
target: yield* decodeTarget({ options: { effort: testCase.effort } }),
2645+
mode: "async",
2646+
clientRequestId: testCase.effort,
2647+
});
2648+
assert.deepEqual((commands[0] as { modelSelection: unknown }).modelSelection, {
2649+
instanceId: codexInstanceId,
2650+
model,
2651+
options: [
2652+
{ id: "effort", value: testCase.expected },
2653+
{ id: "ultracode", value: true },
2654+
],
2655+
});
2656+
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies))));
2657+
}
2658+
}),
2659+
);
2660+
25662661
describe("resolveRuntimeMode", () => {
25672662
const muse = {
25682663
modelSelection: { instanceId: ProviderInstanceId.make("muse"), model: "muse-model" },

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import {
6666
ThreadId,
6767
isOrchestrationV2WorkActive,
6868
} from "@t3tools/contracts";
69-
import { getProviderOptionCurrentValue } from "@t3tools/shared/model";
69+
import { getProviderOptionCurrentValue, withLegacyUltracodeEffort } from "@t3tools/shared/model";
7070
import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError";
7171
import { formatThreadLink } from "@t3tools/shared/threadLinks";
7272
import {
@@ -1433,10 +1433,10 @@ const make = Effect.gen(function* () {
14331433
);
14341434
}
14351435

1436-
const requestedOptions = input.target?.options;
1436+
const descriptors = provider.models.find((candidate) => candidate.slug === model)?.capabilities
1437+
?.optionDescriptors;
1438+
const requestedOptions = withLegacyUltracodeEffort(descriptors ?? [], input.target?.options);
14371439
if (requestedOptions !== undefined) {
1438-
const descriptors = provider.models.find((candidate) => candidate.slug === model)
1439-
?.capabilities?.optionDescriptors;
14401440
const invalid = invalidOptionSelections(requestedOptions, descriptors);
14411441
if (invalid.length > 0) {
14421442
return yield* failure(
@@ -1448,7 +1448,9 @@ const make = Effect.gen(function* () {
14481448

14491449
const inheritsOptions =
14501450
instanceId === inheritedSelection.instanceId && model === inheritedSelection.model;
1451-
let options = inheritsOptions ? inheritedSelection.options : undefined;
1451+
let options = inheritsOptions
1452+
? withLegacyUltracodeEffort(descriptors ?? [], inheritedSelection.options)
1453+
: undefined;
14521454
if (requestedOptions !== undefined) {
14531455
const selections = new Map(
14541456
(requestedOptions.length === 0 ? [] : (options ?? [])).map((selection) => [

‎packages/client-runtime/src/state/threadExecution.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
deriveRunlessWorkStartedAt,
2626
deriveThreadActivityRun,
2727
deriveThreadRuntime,
28+
formatModelSelectionEffort,
2829
threadRuntimeHasInterruptibleRun,
2930
} from "./threadExecution.ts";
3031

@@ -393,3 +394,33 @@ describe("provider-reported model selection", () => {
393394
).toBeNull();
394395
});
395396
});
397+
398+
describe("formatModelSelectionEffort", () => {
399+
it("labels a saved Ultracode effort as Extra High", () => {
400+
const model = {
401+
slug: "claude-opus-5-5",
402+
name: "Claude Opus 5.5",
403+
isCustom: false,
404+
capabilities: {
405+
optionDescriptors: [
406+
{
407+
id: "effort",
408+
label: "Reasoning",
409+
type: "select" as const,
410+
options: [
411+
{ id: "high", label: "High", isDefault: true },
412+
{ id: "xhigh", label: "Extra High" },
413+
],
414+
},
415+
{ id: "ultracode", label: "Ultracode", type: "boolean" as const },
416+
],
417+
},
418+
};
419+
const selection = {
420+
instanceId: ProviderInstanceId.make("claudeAgent"),
421+
model: model.slug,
422+
options: [{ id: "effort", value: "ultracode" }],
423+
};
424+
expect(formatModelSelectionEffort(selection, [model])).toBe("Extra High");
425+
});
426+
});

‎packages/client-runtime/src/state/threadExecution.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import {
2222
backgroundWorkHoldsCompletion,
2323
derivePendingBackgroundWork,
2424
} from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
25-
import { getProviderOptionCurrentLabel, getProviderOptionStatedValue } from "@t3tools/shared/model";
25+
import {
26+
getProviderOptionCurrentLabel,
27+
getProviderOptionStatedValue,
28+
withLegacyUltracodeEffort,
29+
} from "@t3tools/shared/model";
2630
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
2731
import * as DateTime from "effect/DateTime";
2832

@@ -154,12 +158,14 @@ export const REASONING_EFFORT_OPTION_IDS: ReadonlyArray<string> = [
154158
];
155159

156160
export function formatModelSelectionEffort(
157-
selection: ModelSelection,
161+
savedSelection: ModelSelection,
158162
models: ReadonlyArray<ServerProviderModel> = [],
159163
reportedSelection?: ModelSelection | null,
160164
): string | null {
161-
const caps = models.find((model) => model.slug === selection.model)?.capabilities;
165+
const caps = models.find((model) => model.slug === savedSelection.model)?.capabilities;
162166
if (!caps) return null;
167+
const options = withLegacyUltracodeEffort(caps.optionDescriptors ?? [], savedSelection.options);
168+
const selection = options ? { ...savedSelection, options } : savedSelection;
163169
for (const id of REASONING_EFFORT_OPTION_IDS) {
164170
const descriptor = caps.optionDescriptors?.find((candidate) => candidate.id === id);
165171
if (descriptor?.type !== "select") continue;

‎packages/shared/src/model.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ function withDescriptorCurrentValue(
197197
}
198198

199199
// Saved selections from when Ultracode was a Claude effort choice that ran at xhigh.
200-
function withLegacyUltracodeEffort(
200+
export function withLegacyUltracodeEffort<
201+
T extends ReadonlyArray<ProviderOptionSelection> | null | undefined,
202+
>(
201203
descriptors: ReadonlyArray<ProviderOptionDescriptor>,
202-
selections: ReadonlyArray<ProviderOptionSelection> | null | undefined,
203-
): ReadonlyArray<ProviderOptionSelection> | null | undefined {
204+
selections: T,
205+
): T | Array<ProviderOptionSelection> {
204206
if (getRawSelectionValueById(selections, "effort") !== "ultracode") return selections;
205207
const effort = descriptors.find((descriptor) => descriptor.id === "effort");
206208
if (

0 commit comments

Comments
 (0)