GeezerVison is showing github.com — fix(grok): expose advertised reasoning levels by SunkenInTime · Pull Request #6386 · pingdotgg/t3code
fix(grok): expose advertised reasoning levels
#6386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ts
(6)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
fix(grok): harden advertised reasoning metadata
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit e0fc12bdb2ce62ec2091ed2ab084d61ea092c1b7
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -237,6 +237,60 @@ it.layer(grokAdapterTestLayer)("GrokAdapterLive", (it) => {
}),
);
it.effect("clears and reapplies reasoning effort on the same model", () =>
Effect.gen(function* () {
const threadId = ThreadId.make("grok-same-model-effort-clear");
const tempDir = yield* Effect.promise(() =>
NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "grok-same-model-effort-clear-")),
);
const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
const wrapperPath = yield* Effect.promise(() =>
makeMockGrokWrapper({ T3_ACP_REQUEST_LOG_PATH: requestLogPath }),
);
const adapter = yield* makeTestAdapter(wrapperPath);
const selection = (effort?: string) => ({
instanceId: ProviderInstanceId.make("grok"),
model: "grok-build",
...(effort ? { options: [{ id: "reasoningEffort", value: effort }] } : {}),
});
yield* adapter.startSession({
threadId,
provider: ProviderDriverKind.make("grok"),
cwd: process.cwd(),
runtimeMode: "full-access",
modelSelection: selection(),
});
yield* adapter.sendTurn({
threadId,
input: "use high effort",
attachments: [],
modelSelection: selection("high"),
});
yield* adapter.sendTurn({
threadId,
input: "use the model default",
attachments: [],
modelSelection: selection(),
});
yield* adapter.sendTurn({
threadId,
input: "use high effort again",
attachments: [],
modelSelection: selection("high"),
});
const requests = yield* Effect.promise(() => readJsonLines(requestLogPath));
const setModelRequests = requests.filter((entry) => entry.method === "session/set_model");
assert.lengthOf(setModelRequests, 3);
assert.nestedPropertyVal(setModelRequests[0], "params._meta.reasoningEffort", "high");
assert.notNestedProperty(setModelRequests[1], "params._meta");
assert.nestedPropertyVal(setModelRequests[2], "params._meta.reasoningEffort", "high");
yield* adapter.stopSession(threadId);
}),
);
it.effect("closes the ACP child process when a session stops", () =>
Effect.gen(function* () {
const threadId = ThreadId.make("grok-stop-session-close");
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -59,6 +59,7 @@ import {
currentGrokModelIdFromSessionSetup,
currentGrokReasoningEffortFromSessionSetup,
makeGrokAcpRuntime,
normalizeGrokReasoningEffort,
resolveGrokAcpBaseModelId,
} from "../acp/GrokAcpSupport.ts";
import {
Expand Down
Expand Up
@@ -751,8 +752,6 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
grokModelSelection,
"reasoningEffort",
);
const startModelChanged =
requestedStartModelId !== undefined && requestedStartModelId !== currentStartModelId;
const boundModelId = yield* applyGrokAcpModelSelection({
runtime: acp,
currentModelId: currentStartModelId,
Expand Down
Expand Up
@@ -796,8 +795,9 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
promptsInFlight: 0,
currentModelId: boundModelId,
currentReasoningEffort:
requestedStartReasoningEffort ??
(startModelChanged ? undefined : currentStartReasoningEffort),
requestedStartModelId !== undefined
? normalizeGrokReasoningEffort(requestedStartReasoningEffort)
: currentStartReasoningEffort,
stopped: false,
};
Expand Down
Expand Up
@@ -966,9 +966,6 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
turnModelSelection,
"reasoningEffort",
);
const modelChanged =
requestedTurnModelId !== undefined && requestedTurnModelId !== ctx.currentModelId;
const text = input.input?.trim();
const imagePromptParts = yield* Effect.forEach(
input.attachments ?? [],
Expand Down
Expand Up
@@ -1026,10 +1023,10 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
mapAcpToAdapterError(PROVIDER, input.threadId, "session/set_model", cause),
});
ctx.currentModelId = currentModelId;
if (requestedTurnReasoningEffort !== undefined) {
ctx.currentReasoningEffort = requestedTurnReasoningEffort;
} else if (modelChanged) {
ctx.currentReasoningEffort = undefined ;
if (requestedTurnModelId !== undefined) {
ctx.currentReasoningEffort = normalizeGrokReasoningEffort(
requestedTurnReasoningEffort,
) ;
}
const displayModel = currentModelId
? resolveGrokAcpBaseModelId(currentModelId)
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -65,13 +65,107 @@ describe("buildGrokModelCapabilities", () => {
type: "select",
currentValue: "xhigh",
options: [
{ id: "xhigh", label: "xhigh", isDefault: true },
{ id: "xhigh", label: "xhigh" },
{ id: "medium", label: "medium" },
],
},
]);
});
it("keeps ACP current effort separate from its collapsed advertised default", () => {
const capabilities = buildGrokModelCapabilities({
modelId: "grok-4.6",
name: "Grok 4.6",
_meta: {
supportsReasoningEffort: true,
reasoningEffort: "medium",
reasoningEfforts: [
{ value: "xhigh", label: "Extra High Effort", default: true },
{ value: "high", label: "High Effort", default: true },
{ value: "medium", label: "Medium Effort" },
],
},
});
expect(capabilities.optionDescriptors).toEqual([
{
id: "reasoningEffort",
label: "Reasoning",
type: "select",
currentValue: "medium",
options: [
{ id: "xhigh", label: "Extra High Effort", isDefault: true },
{ id: "high", label: "High Effort" },
{ id: "medium", label: "Medium Effort" },
],
},
]);
});
it("preserves ACP descriptions and falls back from invalid values to valid ids", () => {
const capabilities = buildGrokModelCapabilities({
modelId: "grok-4.6",
name: "Grok 4.6",
_meta: {
supportsReasoningEffort: true,
reasoningEffort: "high",
reasoningEfforts: [
{
id: "high",
value: "not a token",
label: "High Effort",
description: "Higher implementation quality",
default: true,
},
{ id: "bad id", value: "also invalid", label: "Invalid" },
],
},
});
expect(capabilities.optionDescriptors).toEqual([
{
id: "reasoningEffort",
label: "Reasoning",
type: "select",
currentValue: "high",
options: [
{
id: "high",
label: "High Effort",
description: "Higher implementation quality",
isDefault: true,
},
],
},
]);
});
it("accepts an advertised ACP menu when the support flag is omitted", () => {
const capabilities = buildGrokModelCapabilities({
modelId: "grok-4.6",
name: "Grok 4.6",
_meta: {
reasoningEffort: "high",
reasoningEfforts: [{ value: "high", label: "High Effort", default: true }],
},
});
expect(capabilities.optionDescriptors).toHaveLength(1);
});
it("honors an explicit ACP opt-out even when a menu is present", () => {
const capabilities = buildGrokModelCapabilities({
modelId: "grok-4.6",
name: "Grok 4.6",
_meta: {
supportsReasoningEffort: false,
reasoningEfforts: [{ value: "high", label: "High Effort", default: true }],
},
});
expect(capabilities.optionDescriptors).toEqual([]);
});
it("does not synthesize a reasoning menu when ACP omits it", () => {
expect(
buildGrokModelCapabilities({
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -18,7 +18,6 @@ import { createModelCapabilities } from "@t3tools/shared/model";
import { resolveSpawnCommand } from "@t3tools/shared/shell";
import {
buildSelectOptionDescriptor,
buildServerProvider,
isCommandMissingCause,
parseGenericCliVersion,
Expand All
@@ -30,7 +29,11 @@ import {
enrichProviderSnapshotWithVersionAdvisory,
type ProviderMaintenanceCapabilities,
} from "../providerMaintenance.ts";
import { makeGrokAcpRuntime, resolveGrokAcpBaseModelId } from "../acp/GrokAcpSupport.ts";
import {
isValidGrokReasoningEffortToken,
makeGrokAcpRuntime,
resolveGrokAcpBaseModelId,
} from "../acp/GrokAcpSupport.ts";
const GROK_PRESENTATION = {
displayName: "Grok",
Expand Down
Expand Up
@@ -108,51 +111,91 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function grokReasoningOptionsFromModel(
model: EffectAcpSchema.ModelInfo,
): ReadonlyArray<{ value: string; label: string; isDefault?: boolean }> {
function grokReasoningOptionsFromModel(model: EffectAcpSchema.ModelInfo): {
readonly options: ReadonlyArray<{
value: string;
label: string;
description?: string;
isDefault?: boolean;
}>;
readonly currentValue: string | undefined;
} {
const meta = model._meta;
if (!meta || meta.supportsReasoningEffort !== true ) {
return [] ;
if (!meta || meta.supportsReasoningEffort === false ) {
return { options: [], currentValue: undefined } ;
}
const defaultEffort = nonEmptyString(meta.reasoningEffort);
const currentEffort = nonEmptyString(meta.reasoningEffort);
const advertisedOptions = Array.isArray(meta.reasoningEfforts) ? meta.reasoningEfforts : [];
const seen = new Set<string>();
const options: Array<{ value: string; label: string; advertisedDefault: boolean }> = [];
const options: Array<{
value: string;
label: string;
description?: string;
advertisedDefault: boolean;
}> = [];
for (const entry of advertisedOptions) {
const value = nonEmptyString(isRecord(entry) ? (entry.value ?? entry.id) : entry);
if (!value || seen.has(value)) {
if (!isRecord(entry)) {
continue;
}
const rawValue = nonEmptyString(entry.value);
const rawId = nonEmptyString(entry.id);
const value =
rawValue && isValidGrokReasoningEffortToken(rawValue)
? rawValue
: rawId && isValidGrokReasoningEffortToken(rawId)
? rawId
: undefined;
if (value === undefined || seen.has(value)) {
continue;
}
seen.add(value);
const description = nonEmptyString(entry.description);
options.push({
value,
label: nonEmptyString(isRecord(entry) ? entry.label : undefined) ?? value,
advertisedDefault: isRecord(entry) && entry.default === true,
label: nonEmptyString(entry.label) ?? value,
...(description ? { description } : {}),
advertisedDefault: entry.default === true || entry.isDefault === true,
});
}
const currentValue =
currentEffort && options.some((option) => option.value === currentEffort)
? currentEffort
: undefined;
const advertisedDefaults = options.filter((option) => option.advertisedDefault);
const selectedDefault =
(defaultEffort && options.some((option) => option.value === defaultEffort)
? defaultEffort
: undefined) ?? options.find((option) => option.advertisedDefault)?.value;
return options.map(({ value, label }) =>
value === selectedDefault ? { value, label, isDefault: true } : { value, label },
);
advertisedDefaults.find((option) => option.value === currentValue)?.value ??
advertisedDefaults[0]?.value;
return {
options: options.map(({ value, label, description }) => ({
value,
label,
...(description ? { description } : {}),
...(value === selectedDefault ? { isDefault: true } : {}),
})),
currentValue: currentValue ?? selectedDefault,
};
}
export function buildGrokModelCapabilities(model: EffectAcpSchema.ModelInfo): ModelCapabilities {
const reasoningOptions = grokReasoningOptionsFromModel(model);
return reasoningOptions .length > 0
const reasoning = grokReasoningOptionsFromModel(model);
return reasoning.options .length > 0
? createModelCapabilities({
optionDescriptors: [
buildSelectOptionDescriptor( {
{
id: "reasoningEffort",
label: "Reasoning",
options: reasoningOptions,
}),
type: "select",
options: reasoning.options.map((option) => ({
id: option.value,
label: option.label,
...(option.description ? { description: option.description } : {}),
...(option.isDefault ? { isDefault: true } : {}),
})),
...(reasoning.currentValue ? { currentValue: reasoning.currentValue } : {}),
},
],
})
: EMPTY_CAPABILITIES;
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.