GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(grok): harden advertised reasoning metadata · pingdotgg/t3code@e0fc12b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/provider
    • Layers
      • GrokAdapter.test.ts
      • GrokAdapter.ts
      • GrokProvider.test.ts
      • GrokProvider.ts
    • acp
      • GrokAcpSupport.test.ts
      • GrokAcpSupport.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/provider/Layers/GrokAdapter.test.ts
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,60 @@ it.layer(grokAdapterTestLayer)("GrokAdapterLive", (it) => {
237237
}),
238238
);
239239

240+
it.effect("clears and reapplies reasoning effort on the same model", () =>
241+
Effect.gen(function* () {
242+
const threadId = ThreadId.make("grok-same-model-effort-clear");
243+
const tempDir = yield* Effect.promise(() =>
244+
NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "grok-same-model-effort-clear-")),
245+
);
246+
const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
247+
const wrapperPath = yield* Effect.promise(() =>
248+
makeMockGrokWrapper({ T3_ACP_REQUEST_LOG_PATH: requestLogPath }),
249+
);
250+
const adapter = yield* makeTestAdapter(wrapperPath);
251+
const selection = (effort?: string) => ({
252+
instanceId: ProviderInstanceId.make("grok"),
253+
model: "grok-build",
254+
...(effort ? { options: [{ id: "reasoningEffort", value: effort }] } : {}),
255+
});
256+
257+
yield* adapter.startSession({
258+
threadId,
259+
provider: ProviderDriverKind.make("grok"),
260+
cwd: process.cwd(),
261+
runtimeMode: "full-access",
262+
modelSelection: selection(),
263+
});
264+
yield* adapter.sendTurn({
265+
threadId,
266+
input: "use high effort",
267+
attachments: [],
268+
modelSelection: selection("high"),
269+
});
270+
yield* adapter.sendTurn({
271+
threadId,
272+
input: "use the model default",
273+
attachments: [],
274+
modelSelection: selection(),
275+
});
276+
yield* adapter.sendTurn({
277+
threadId,
278+
input: "use high effort again",
279+
attachments: [],
280+
modelSelection: selection("high"),
281+
});
282+
283+
const requests = yield* Effect.promise(() => readJsonLines(requestLogPath));
284+
const setModelRequests = requests.filter((entry) => entry.method === "session/set_model");
285+
assert.lengthOf(setModelRequests, 3);
286+
assert.nestedPropertyVal(setModelRequests[0], "params._meta.reasoningEffort", "high");
287+
assert.notNestedProperty(setModelRequests[1], "params._meta");
288+
assert.nestedPropertyVal(setModelRequests[2], "params._meta.reasoningEffort", "high");
289+
290+
yield* adapter.stopSession(threadId);
291+
}),
292+
);
293+
240294
it.effect("closes the ACP child process when a session stops", () =>
241295
Effect.gen(function* () {
242296
const threadId = ThreadId.make("grok-stop-session-close");
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/provider/Layers/GrokAdapter.ts
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
currentGrokModelIdFromSessionSetup,
6060
currentGrokReasoningEffortFromSessionSetup,
6161
makeGrokAcpRuntime,
62+
normalizeGrokReasoningEffort,
6263
resolveGrokAcpBaseModelId,
6364
} from "../acp/GrokAcpSupport.ts";
6465
import {
@@ -751,8 +752,6 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
751752
grokModelSelection,
752753
"reasoningEffort",
753754
);
754-
const startModelChanged =
755-
requestedStartModelId !== undefined && requestedStartModelId !== currentStartModelId;
756755
const boundModelId = yield* applyGrokAcpModelSelection({
757756
runtime: acp,
758757
currentModelId: currentStartModelId,
@@ -796,8 +795,9 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
796795
promptsInFlight: 0,
797796
currentModelId: boundModelId,
798797
currentReasoningEffort:
799-
requestedStartReasoningEffort ??
800-
(startModelChanged ? undefined : currentStartReasoningEffort),
798+
requestedStartModelId !== undefined
799+
? normalizeGrokReasoningEffort(requestedStartReasoningEffort)
800+
: currentStartReasoningEffort,
801801
stopped: false,
802802
};
803803

@@ -966,9 +966,6 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
966966
turnModelSelection,
967967
"reasoningEffort",
968968
);
969-
const modelChanged =
970-
requestedTurnModelId !== undefined && requestedTurnModelId !== ctx.currentModelId;
971-
972969
const text = input.input?.trim();
973970
const imagePromptParts = yield* Effect.forEach(
974971
input.attachments ?? [],
@@ -1026,10 +1023,10 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
10261023
mapAcpToAdapterError(PROVIDER, input.threadId, "session/set_model", cause),
10271024
});
10281025
ctx.currentModelId = currentModelId;
1029-
if (requestedTurnReasoningEffort !== undefined) {
1030-
ctx.currentReasoningEffort = requestedTurnReasoningEffort;
1031-
} else if (modelChanged) {
1032-
ctx.currentReasoningEffort = undefined;
1026+
if (requestedTurnModelId !== undefined) {
1027+
ctx.currentReasoningEffort = normalizeGrokReasoningEffort(
1028+
requestedTurnReasoningEffort,
1029+
);
10331030
}
10341031
const displayModel = currentModelId
10351032
? resolveGrokAcpBaseModelId(currentModelId)
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/provider/Layers/GrokProvider.test.ts
+95-1Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,107 @@ describe("buildGrokModelCapabilities", () => {
6565
type: "select",
6666
currentValue: "xhigh",
6767
options: [
68-
{ id: "xhigh", label: "xhigh", isDefault: true },
68+
{ id: "xhigh", label: "xhigh" },
6969
{ id: "medium", label: "medium" },
7070
],
7171
},
7272
]);
7373
});
7474

75+
it("keeps ACP current effort separate from its collapsed advertised default", () => {
76+
const capabilities = buildGrokModelCapabilities({
77+
modelId: "grok-4.6",
78+
name: "Grok 4.6",
79+
_meta: {
80+
supportsReasoningEffort: true,
81+
reasoningEffort: "medium",
82+
reasoningEfforts: [
83+
{ value: "xhigh", label: "Extra High Effort", default: true },
84+
{ value: "high", label: "High Effort", default: true },
85+
{ value: "medium", label: "Medium Effort" },
86+
],
87+
},
88+
});
89+
90+
expect(capabilities.optionDescriptors).toEqual([
91+
{
92+
id: "reasoningEffort",
93+
label: "Reasoning",
94+
type: "select",
95+
currentValue: "medium",
96+
options: [
97+
{ id: "xhigh", label: "Extra High Effort", isDefault: true },
98+
{ id: "high", label: "High Effort" },
99+
{ id: "medium", label: "Medium Effort" },
100+
],
101+
},
102+
]);
103+
});
104+
105+
it("preserves ACP descriptions and falls back from invalid values to valid ids", () => {
106+
const capabilities = buildGrokModelCapabilities({
107+
modelId: "grok-4.6",
108+
name: "Grok 4.6",
109+
_meta: {
110+
supportsReasoningEffort: true,
111+
reasoningEffort: "high",
112+
reasoningEfforts: [
113+
{
114+
id: "high",
115+
value: "not a token",
116+
label: "High Effort",
117+
description: "Higher implementation quality",
118+
default: true,
119+
},
120+
{ id: "bad id", value: "also invalid", label: "Invalid" },
121+
],
122+
},
123+
});
124+
125+
expect(capabilities.optionDescriptors).toEqual([
126+
{
127+
id: "reasoningEffort",
128+
label: "Reasoning",
129+
type: "select",
130+
currentValue: "high",
131+
options: [
132+
{
133+
id: "high",
134+
label: "High Effort",
135+
description: "Higher implementation quality",
136+
isDefault: true,
137+
},
138+
],
139+
},
140+
]);
141+
});
142+
143+
it("accepts an advertised ACP menu when the support flag is omitted", () => {
144+
const capabilities = buildGrokModelCapabilities({
145+
modelId: "grok-4.6",
146+
name: "Grok 4.6",
147+
_meta: {
148+
reasoningEffort: "high",
149+
reasoningEfforts: [{ value: "high", label: "High Effort", default: true }],
150+
},
151+
});
152+
153+
expect(capabilities.optionDescriptors).toHaveLength(1);
154+
});
155+
156+
it("honors an explicit ACP opt-out even when a menu is present", () => {
157+
const capabilities = buildGrokModelCapabilities({
158+
modelId: "grok-4.6",
159+
name: "Grok 4.6",
160+
_meta: {
161+
supportsReasoningEffort: false,
162+
reasoningEfforts: [{ value: "high", label: "High Effort", default: true }],
163+
},
164+
});
165+
166+
expect(capabilities.optionDescriptors).toEqual([]);
167+
});
168+
75169
it("does not synthesize a reasoning menu when ACP omits it", () => {
76170
expect(
77171
buildGrokModelCapabilities({
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/provider/Layers/GrokProvider.ts
+67-24Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { createModelCapabilities } from "@t3tools/shared/model";
1818
import { resolveSpawnCommand } from "@t3tools/shared/shell";
1919

2020
import {
21-
buildSelectOptionDescriptor,
2221
buildServerProvider,
2322
isCommandMissingCause,
2423
parseGenericCliVersion,
@@ -30,7 +29,11 @@ import {
3029
enrichProviderSnapshotWithVersionAdvisory,
3130
type ProviderMaintenanceCapabilities,
3231
} from "../providerMaintenance.ts";
33-
import { makeGrokAcpRuntime, resolveGrokAcpBaseModelId } from "../acp/GrokAcpSupport.ts";
32+
import {
33+
isValidGrokReasoningEffortToken,
34+
makeGrokAcpRuntime,
35+
resolveGrokAcpBaseModelId,
36+
} from "../acp/GrokAcpSupport.ts";
3437

3538
const GROK_PRESENTATION = {
3639
displayName: "Grok",
@@ -108,51 +111,91 @@ function isRecord(value: unknown): value is Record<string, unknown> {
108111
return typeof value === "object" && value !== null && !Array.isArray(value);
109112
}
110113

111-
function grokReasoningOptionsFromModel(
112-
model: EffectAcpSchema.ModelInfo,
113-
): ReadonlyArray<{ value: string; label: string; isDefault?: boolean }> {
114+
function grokReasoningOptionsFromModel(model: EffectAcpSchema.ModelInfo): {
115+
readonly options: ReadonlyArray<{
116+
value: string;
117+
label: string;
118+
description?: string;
119+
isDefault?: boolean;
120+
}>;
121+
readonly currentValue: string | undefined;
122+
} {
114123
const meta = model._meta;
115-
if (!meta || meta.supportsReasoningEffort !== true) {
116-
return [];
124+
if (!meta || meta.supportsReasoningEffort === false) {
125+
return { options: [], currentValue: undefined };
117126
}
118127

119-
const defaultEffort = nonEmptyString(meta.reasoningEffort);
128+
const currentEffort = nonEmptyString(meta.reasoningEffort);
120129
const advertisedOptions = Array.isArray(meta.reasoningEfforts) ? meta.reasoningEfforts : [];
121130
const seen = new Set<string>();
122-
const options: Array<{ value: string; label: string; advertisedDefault: boolean }> = [];
131+
const options: Array<{
132+
value: string;
133+
label: string;
134+
description?: string;
135+
advertisedDefault: boolean;
136+
}> = [];
123137

124138
for (const entry of advertisedOptions) {
125-
const value = nonEmptyString(isRecord(entry) ? (entry.value ?? entry.id) : entry);
126-
if (!value || seen.has(value)) {
139+
if (!isRecord(entry)) {
140+
continue;
141+
}
142+
const rawValue = nonEmptyString(entry.value);
143+
const rawId = nonEmptyString(entry.id);
144+
const value =
145+
rawValue && isValidGrokReasoningEffortToken(rawValue)
146+
? rawValue
147+
: rawId && isValidGrokReasoningEffortToken(rawId)
148+
? rawId
149+
: undefined;
150+
if (value === undefined || seen.has(value)) {
127151
continue;
128152
}
129153
seen.add(value);
154+
const description = nonEmptyString(entry.description);
130155
options.push({
131156
value,
132-
label: nonEmptyString(isRecord(entry) ? entry.label : undefined) ?? value,
133-
advertisedDefault: isRecord(entry) && entry.default === true,
157+
label: nonEmptyString(entry.label) ?? value,
158+
...(description ? { description } : {}),
159+
advertisedDefault: entry.default === true || entry.isDefault === true,
134160
});
135161
}
136162

163+
const currentValue =
164+
currentEffort && options.some((option) => option.value === currentEffort)
165+
? currentEffort
166+
: undefined;
167+
const advertisedDefaults = options.filter((option) => option.advertisedDefault);
137168
const selectedDefault =
138-
(defaultEffort && options.some((option) => option.value === defaultEffort)
139-
? defaultEffort
140-
: undefined) ?? options.find((option) => option.advertisedDefault)?.value;
141-
return options.map(({ value, label }) =>
142-
value === selectedDefault ? { value, label, isDefault: true } : { value, label },
143-
);
169+
advertisedDefaults.find((option) => option.value === currentValue)?.value ??
170+
advertisedDefaults[0]?.value;
171+
return {
172+
options: options.map(({ value, label, description }) => ({
173+
value,
174+
label,
175+
...(description ? { description } : {}),
176+
...(value === selectedDefault ? { isDefault: true } : {}),
177+
})),
178+
currentValue: currentValue ?? selectedDefault,
179+
};
144180
}
145181

146182
export function buildGrokModelCapabilities(model: EffectAcpSchema.ModelInfo): ModelCapabilities {
147-
const reasoningOptions = grokReasoningOptionsFromModel(model);
148-
return reasoningOptions.length > 0
183+
const reasoning = grokReasoningOptionsFromModel(model);
184+
return reasoning.options.length > 0
149185
? createModelCapabilities({
150186
optionDescriptors: [
151-
buildSelectOptionDescriptor({
187+
{
152188
id: "reasoningEffort",
153189
label: "Reasoning",
154-
options: reasoningOptions,
155-
}),
190+
type: "select",
191+
options: reasoning.options.map((option) => ({
192+
id: option.value,
193+
label: option.label,
194+
...(option.description ? { description: option.description } : {}),
195+
...(option.isDefault ? { isDefault: true } : {}),
196+
})),
197+
...(reasoning.currentValue ? { currentValue: reasoning.currentValue } : {}),
198+
},
156199
],
157200
})
158201
: EMPTY_CAPABILITIES;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.