The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 03:00 UTC
fix(provider-grok): report model windows for handoff budgets (#20180)
Scott Norteman committed
Oct 18, 2026 at 16:03 UTC
ab89a5956bcf8aec319556b6959fca926d6dae6a
4 files changed
+123
-3
apps/server/scripts/acp-mock-agent.ts
+4
-3
@@ -427,10 +427,11 @@ function modeState(): AcpCompat.SessionModeState {
427
// "grok-build" product name.
428
const grokAcpModels: ReadonlyArray<AcpCompat.ModelInfo> = [
429
{
430
- modelId: "grok-4.6",
430
+ modelId: process.env.T3_ACP_GROK_MODEL ?? "grok-4.6",
431
name: "Grok 4.6",
432
_meta: {
433
- totalContextTokens: 500_000,
433
+ totalContextTokens: Number(process.env.T3_ACP_GROK_CONTEXT_TOKENS ?? 500_000),
434
+ contextWindows: [256_000, 500_000],
435
supportsReasoningEffort: true,
436
reasoningEffort: initialGrokReasoningEffort ?? "high",
437
reasoningEfforts: [
@@ -449,7 +450,7 @@ function modelState(): AcpCompat.SessionModelState {
450
}
451
const modelId = grokAcpModels.some((model) => model.modelId === currentModelId)
452
? currentModelId
452
- : "grok-4.6";
453
+ : (process.env.T3_ACP_GROK_MODEL ?? "grok-4.6");
454
return {
455
currentModelId: modelId,
456
availableModels: grokAcpModels,
apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts
+91
@@ -26,6 +26,7 @@ import * as Path from "effect/Path";
26
import * as Stream from "effect/Stream";
27
import * as Layer from "effect/Layer";
28
import * as PlatformError from "effect/PlatformError";
29
+import * as Path from "effect/Path";
30
import * as Schema from "effect/Schema";
31
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
32
import type * as EffectAcpSchema from "effect-acp/compat";
@@ -37,6 +38,8 @@ import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
38
import * as ProviderInstanceRegistry from "../../provider/ProviderInstanceRegistry.ts";
39
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
40
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
41
+import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
42
+import { handoffBudget } from "@t3tools/provider-core/server/handoffBudget";
43
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
44
import * as RuntimePolicy from "../RuntimePolicy.ts";
45
import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPolicy";
@@ -328,6 +331,94 @@ describe("Grok permission prompts", () => {
331
});
332
});
333
334
+describe("Grok model context windows", () => {
335
+ const layerHost = TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer));
336
+ const layerTest = Layer.mergeAll(
337
+ NodeServices.layer,
338
+ IdAllocator.layer,
339
+ McpProviderSessions.layer,
340
+ layerHost,
341
+ );
342
+
343
+ it.effect("budgets handoffs with the selected Grok model's window", () =>
344
+ Effect.gen(function* () {
345
+ const instanceId = ProviderInstanceId.make("grok-window-test");
346
+ const threadId = ThreadId.make("grok-window-test");
347
+ const modelSelection = { instanceId, model: "grok-build" };
348
+ const policy = runtimePolicy({ runtimeMode: "full-access" });
349
+ const path = yield* Path.Path;
350
+ const mockAgentPath = yield* path.fromFileUrl(
351
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
352
+ );
353
+ const adapter = yield* makeGrokAdapterV2({
354
+ instanceId,
355
+ settings: LAUNCH_TEST_GROK_SETTINGS,
356
+ environment: {},
357
+ hostPlatform: "linux",
358
+ selfInvocation: yield* resolveSelfInvocation(),
359
+ makeRuntime: (input) =>
360
+ Effect.gen(function* () {
361
+ const context = yield* Layer.build(
362
+ AcpSessionRuntime.layer({
363
+ ...input,
364
+ spawn: {
365
+ command: process.execPath,
366
+ args: [mockAgentPath],
367
+ cwd: process.cwd(),
368
+ env: {
369
+ T3_ACP_SESSION_LIFECYCLE: "1",
370
+ T3_ACP_GROK_MODEL: "grok-4.7",
371
+ T3_ACP_GROK_CONTEXT_TOKENS: "256000",
372
+ },
373
+ },
374
+ authMethodId: "test",
375
+ }),
376
+ );
377
+ return yield* AcpSessionRuntime.AcpSessionRuntime.pipe(Effect.provide(context));
378
+ }),
379
+ });
380
+ const runtime = yield* adapter.openSession({
381
+ threadId,
382
+ providerSessionId: ProviderSessionId.make("grok-window-test"),
383
+ modelSelection,
384
+ runtimePolicy: policy,
385
+ });
386
+ const providerThread = yield* runtime.ensureThread({
387
+ threadId,
388
+ modelSelection,
389
+ runtimePolicy: policy,
390
+ });
391
+ const budgetInput = {
392
+ tokenCap: 16_000,
393
+ userText: "Continue",
394
+ attachments: [],
395
+ providerThread,
396
+ nativeContextEstimate: 160_684,
397
+ };
398
+ assert.isNull(providerThread.contextUsage);
399
+ assert.equal(handoffBudget(budgetInput), 0);
400
+ assert.equal(
401
+ handoffBudget({
402
+ ...budgetInput,
403
+ modelContextWindow: runtime.getModelContextWindow?.({ instanceId, model: "grok-4.7" }),
404
+ }),
405
+ 16_000,
406
+ );
407
+ assert.equal(runtime.getModelContextWindow?.({ instanceId, model: "grok-4.7" }), 256_000);
408
+ assert.equal(runtime.getModelContextWindow?.({ instanceId, model: " grok-4.7 " }), 256_000);
409
+ for (const model of ["custom-model", "grok-build", "toString"]) {
410
+ assert.isUndefined(runtime.getModelContextWindow?.({ instanceId, model }));
411
+ }
412
+ assert.isUndefined(
413
+ runtime.getModelContextWindow?.({
414
+ instanceId: ProviderInstanceId.make("another-grok"),
415
+ model: "grok-4.7",
416
+ }),
417
+ );
418
+ }).pipe(Effect.scoped, Effect.provide(layerTest)),
419
+ );
420
+});
421
+
422
describe("Grok launch permission mode", () => {
423
const layerHost = TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer));
424
const layerTest = Layer.mergeAll(
packages/provider-acp/src/server/adapter.ts
+14
@@ -222,6 +222,10 @@ export interface AcpAdapterV2Flavor {
222
ChildProcessSpawner.ChildProcessSpawner | Crypto.Crypto | Scope.Scope
223
>;
224
readonly resolveModelId?: (selection: ModelSelection) => string | undefined;
225
+ readonly getModelContextWindow?: (
226
+ selection: ModelSelection,
227
+ session: AcpSessionRuntime.AcpSessionRuntimeStartResult,
228
+ ) => number | undefined;
229
readonly applyModelSelection?: (input: {
230
readonly runtime: AcpSessionRuntime.AcpSessionRuntime["Service"];
231
readonly startResult: AcpSessionRuntime.AcpSessionRuntimeStartResult;
@@ -6811,6 +6815,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6815
providerSessionId: input.providerSessionId,
6816
providerSession,
6817
events: Stream.fromEffectRepeat(Queue.take(events)),
6818
+ ...(flavor.getModelContextWindow === undefined
6819
+ ? {}
6820
+ : {
6821
+ getModelContextWindow: (selection) => {
6822
+ const session = Ref.getUnsafe(activeSessionSetup);
6823
+ return session === null
6824
+ ? undefined
6825
+ : flavor.getModelContextWindow?.(selection, session);
6826
+ },
6827
+ }),
6828
...(postSettleContinuationEnabled
6829
? {
6830
hasPendingBackgroundWork: Effect.gen(function* () {
packages/provider-grok/src/server/adapter.ts
+14
@@ -56,6 +56,7 @@ import {
56
} from "./xaiAcpExtension.ts";
57
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
58
import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPolicy";
59
+import { sessionModelStateFromInitialize } from "@t3tools/provider-acp/server/runtimeModel";
60
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
61
import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
62
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
@@ -247,6 +248,19 @@ export function makeGrokAcpAdapterFlavor(
248
supportsImagePrompts: true,
249
supportsCompaction: true,
250
resolveModelId: (selection) => resolveGrokAcpBaseModelId(selection.model),
251
+ getModelContextWindow: (selection, session) => {
252
+ if (selection.instanceId !== options.instanceId) return undefined;
253
+ const modelId = resolveGrokAcpBaseModelId(selection.model);
254
+ const models =
255
+ session.sessionSetupResult.models ??
256
+ sessionModelStateFromInitialize(session.initializeResult);
257
+ const window = models?.availableModels.find((model) => model.modelId === modelId)?._meta
258
+ ?.totalContextTokens;
259
+ // contextWindows includes selectable larger windows; totalContextTokens is the default.
260
+ return typeof window === "number" && Number.isSafeInteger(window) && window > 0
261
+ ? window
262
+ : undefined;
263
+ },
264
applyModelSelection: ({ runtime, startResult, modelSelection }) =>
265
Effect.gen(function* () {
266
const legacy = startResult.initializeResult.protocolVersion === 1;