@devries-cameron20 / t3code Mirror · read-only / commits / f82162f033
Fork 0

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 21, 11:00 UTC

fix(provider-grok): steer queued messages into a running Grok turn (#37335)

Julius Marminge committed Nov 15, 2026 at 12:34 UTC f82162f0336c226ae1f2927f781a0fb660869a51
4 files changed +150 -39
apps/server/src/orchestration-v2/CommandPolicy.test.ts
+17
@@ -234,6 +234,23 @@ it("does not steer a Grok follow-up by interrupting its running turn", () => {
234 }
235 });
236
237 +// regression: #37326 a steered Grok follow-up waits for the turn to end instead of interjecting
238 +it("steers a Grok follow-up into its running turn without restarting it", () => {
239 + const grok = makeGrokAcpAdapterFlavor(
240 + { makeRuntime: () => Effect.never } as unknown as Parameters<
241 + typeof makeGrokAcpAdapterFlavor
242 + >[0],
243 + "/home/ada",
244 + ).capabilities;
245 + const mode = CommandPolicy.resolveMessageDispatchIntent(
246 + dispatchProjection(grok),
247 + { type: "start_immediately" },
248 + "steer",
249 + );
250 + assert.strictEqual(mode.type, "steer_active");
251 + assert.isTrue(grok.turns.supportsActiveSteering);
252 +});
253 +
254 it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) => {
255 const projection = dispatchProjection(baseCapabilities);
256 const maintenance = {
packages/provider-acp/src/server/adapter.ts
+59 -36
@@ -501,14 +501,16 @@ export interface AcpAdapterV2Flavor {
501 /**
502 * Native steering: `send` queues a message into the running turn and returns the
503 * agent's id for it, which `injectedSteerId` reads from the update that delivers it.
504 + * No id means the running turn reads the message once the agent accepts it.
505 */
506 readonly steering?: {
507 readonly send: (
508 runtime: AcpSessionRuntime.AcpSessionRuntime["Service"],
509 sessionId: string,
510 text: string,
510 - ) => Effect.Effect<string, EffectAcpErrors.AcpError>;
511 - readonly injectedSteerId: (
511 + images: ReadonlyArray<EffectAcpSchema.ContentBlock>,
512 + ) => Effect.Effect<string | undefined, EffectAcpErrors.AcpError>;
513 + readonly injectedSteerId?: (
514 notification: EffectAcpSchema.SessionNotification,
515 ) => string | undefined;
516 };
@@ -6638,7 +6640,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6640 context.nativePromptId ??= nativePromptId;
6641 }
6642 }
6641 - const injectedSteerId = flavor.steering?.injectedSteerId(rawNotification);
6643 + const injectedSteerId = flavor.steering?.injectedSteerId?.(rawNotification);
6644 if (injectedSteerId !== undefined) {
6645 yield* Deferred.succeed(steerInjection(injectedSteerId), undefined);
6646 }
@@ -8321,6 +8323,38 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8323 }
8324 });
8325
8326 + const imageAttachmentBlocks = Effect.fnUntraced(function* (
8327 + attachments: ReadonlyArray<ChatAttachment>,
8328 + ) {
8329 + const blocks: Array<EffectAcpSchema.ContentBlock> = [];
8330 + for (const attachment of attachments.filter(isProviderNativeImageAttachment)) {
8331 + const path = host.resolveAttachmentPath(attachment as ChatAttachment);
8332 + if (path === null) {
8333 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
8334 + driver,
8335 + detail: `Invalid attachment id '${attachment.id}'`,
8336 + });
8337 + }
8338 + const bytes = yield* fileSystem.readFile(path).pipe(
8339 + Effect.mapError(
8340 + (cause) =>
8341 + new ProviderAdapter.ProviderAdapterProtocolError({
8342 + driver,
8343 + detail: `Failed to read attachment '${attachment.id}'`,
8344 + reason: "attachment_unreadable",
8345 + payload: cause,
8346 + }),
8347 + ),
8348 + );
8349 + blocks.push({
8350 + type: "image",
8351 + data: Buffer.from(bytes).toString("base64"),
8352 + mimeType: attachment.mimeType,
8353 + });
8354 + }
8355 + return blocks;
8356 + });
8357 +
8358 const resolvePromptParts = Effect.fnUntraced(function* (
8359 turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
8360 sessionId: string,
@@ -8349,41 +8383,18 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8383 resolveExtractedTextPath: host.resolveExtractedTextPath,
8384 });
8385 const isNativeSlashCommand = userText.trimStart().startsWith("/");
8352 - const imageAttachments = turnInput.message.attachments.filter(
8353 - isProviderNativeImageAttachment,
8354 - );
8355 - if (imageAttachments.length > 0 && !supportsImagePrompts) {
8386 + if (
8387 + !supportsImagePrompts &&
8388 + turnInput.message.attachments.some(isProviderNativeImageAttachment)
8389 + ) {
8390 return yield* new ProviderAdapter.ProviderAdapterProtocolError({
8391 driver,
8392 detail: "ACP driver did not negotiate image prompt support",
8393 });
8394 }
8361 - const attachmentBlocks: Array<EffectAcpSchema.ContentBlock> = [];
8362 - for (const attachment of flavor.buildAttachmentPrompt ? [] : imageAttachments) {
8363 - const path = host.resolveAttachmentPath(attachment as ChatAttachment);
8364 - if (path === null) {
8365 - return yield* new ProviderAdapter.ProviderAdapterProtocolError({
8366 - driver,
8367 - detail: `Invalid attachment id '${attachment.id}'`,
8368 - });
8369 - }
8370 - const bytes = yield* fileSystem.readFile(path).pipe(
8371 - Effect.mapError(
8372 - (cause) =>
8373 - new ProviderAdapter.ProviderAdapterProtocolError({
8374 - driver,
8375 - detail: `Failed to read attachment '${attachment.id}'`,
8376 - reason: "attachment_unreadable",
8377 - payload: cause,
8378 - }),
8379 - ),
8380 - );
8381 - attachmentBlocks.push({
8382 - type: "image",
8383 - data: Buffer.from(bytes).toString("base64"),
8384 - mimeType: attachment.mimeType,
8385 - });
8386 - }
8395 + const attachmentBlocks = flavor.buildAttachmentPrompt
8396 + ? []
8397 + : yield* imageAttachmentBlocks(turnInput.message.attachments);
8398 if (flavor.buildAttachmentPrompt) {
8399 const setup = yield* Ref.get(activeSessionSetup);
8400 const modelOption = findModelConfigOption(yield* runtime.getConfigOptions);
@@ -9262,8 +9273,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9273 steerTurn: Effect.fn("AcpAdapterV2.steerTurn")(
9274 function* (turnInput) {
9275 const steering = flavor.steering;
9265 - // The agent takes text only, so a steer with attachments waits for the next turn.
9266 - if (steering === undefined || turnInput.message.attachments.length > 0) {
9276 + // A text-only steer leaves attachments to the orchestrator's restart.
9277 + if (
9278 + steering === undefined ||
9279 + (turnInput.message.attachments.length > 0 &&
9280 + flavor.capabilities.turns.activeSteeringAcceptsAttachments === false)
9281 + ) {
9282 return yield* new ProviderAdapter.ProviderAdapterSteerRunUnsupportedError({
9283 driver,
9284 providerThreadId: turnInput.providerThread.id,
@@ -9287,11 +9302,19 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9302 Effect.timeoutOption(startHold.bound),
9303 );
9304 }
9305 + const text = yield* providerMessageTextWithAttachmentPaths({
9306 + text: turnInput.message.text,
9307 + attachments: turnInput.message.attachments,
9308 + resolveAttachmentPath: host.resolveAttachmentPath,
9309 + resolveExtractedTextPath: host.resolveExtractedTextPath,
9310 + });
9311 const steerId = yield* steering.send(
9312 runtime,
9313 context.nativeThreadId,
9293 - turnInput.message.text,
9314 + text,
9315 + yield* imageAttachmentBlocks(turnInput.message.attachments),
9316 );
9317 + if (steerId === undefined) return;
9318 const injected = steerInjection(steerId);
9319 // The agent reads a steer at its next step. One that lands after the last
9320 // step is dropped, and the turn settles right after; the orchestrator then
packages/provider-grok/src/server/adapter.test.ts
+35 -1
@@ -31,7 +31,7 @@ import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderS
31 import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
32 import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
33 import { GrokSettings } from "../settings.ts";
34 -import { makeGrokAdapterV2 } from "./adapter.ts";
34 +import { makeGrokAcpAdapterFlavor, makeGrokAdapterV2 } from "./adapter.ts";
35
36 const layerTest = Layer.mergeAll(
37 NodeServices.layer,
@@ -263,3 +263,37 @@ describe("Grok reasoning effort", () => {
263 }),
264 );
265 });
266 +
267 +it.effect("a steer reaches Grok as an interjection that carries its images", () =>
268 + Effect.gen(function* () {
269 + const requests: Array<{ readonly method: string; readonly params: unknown }> = [];
270 + let reply: unknown = { result: { status: "queued" } };
271 + const runtime = {
272 + request: (method: string, params: unknown) => {
273 + requests.push({ method, params });
274 + return Effect.succeed(reply);
275 + },
276 + } as unknown as AcpSessionRuntime.AcpSessionRuntime["Service"];
277 + const steering = makeGrokAcpAdapterFlavor(
278 + { makeRuntime: () => Effect.never } as unknown as Parameters<
279 + typeof makeGrokAcpAdapterFlavor
280 + >[0],
281 + "/home/ada",
282 + ).steering!;
283 + const image = { type: "image", data: "aGk=", mimeType: "image/png" } as const;
284 +
285 + assert.isUndefined(yield* steering.send(runtime, "session-1", "Look at this", [image]));
286 + yield* steering.send(runtime, "session-1", "Text only", []);
287 + assert.deepEqual(requests, [
288 + {
289 + method: "_x.ai/interject",
290 + params: { sessionId: "session-1", text: "Look at this", content: [image] },
291 + },
292 + { method: "_x.ai/interject", params: { sessionId: "session-1", text: "Text only" } },
293 + ]);
294 +
295 + reply = { result: { status: "rejected" } };
296 + const refused = yield* steering.send(runtime, "session-1", "Late", []).pipe(Effect.flip);
297 + assert.strictEqual(refused._tag, "AcpRequestError");
298 + }),
299 +);
packages/provider-grok/src/server/adapter.ts
+39 -2
@@ -117,10 +117,46 @@ const GrokProviderCapabilitiesV2 = {
117 ...AcpProviderCapabilitiesV2.checkpointing,
118 providerCanReadConversationSnapshot: true,
119 },
120 - // Cancelling a Grok prompt kills its running foreground tool.
121 - turns: { ...AcpProviderCapabilitiesV2.turns, supportsSteeringByInterruptRestart: false },
120 + turns: {
121 + ...AcpProviderCapabilitiesV2.turns,
122 + // `_x.ai/interject` lets the running tool finish; the model reads the message at its next step.
123 + supportsActiveSteering: true,
124 + activeSteeringInterruptsTools: false,
125 + // Cancelling a Grok prompt kills its running foreground tool.
126 + supportsSteeringByInterruptRestart: false,
127 + },
128 } satisfies OrchestrationV2ProviderCapabilities;
129
130 +const XAI_INTERJECT_METHOD = "_x.ai/interject";
131 +const isXAiInterjectQueued = Schema.is(
132 + Schema.Struct({ result: Schema.Struct({ status: Schema.Literal("queued") }) }),
133 +);
134 +
135 +/** A queued interjection joins the running prompt, so its acceptance is the delivery. */
136 +const grokSteering: NonNullable<AcpAdapterV2Flavor["steering"]> = {
137 + send: (runtime, sessionId, text, images) =>
138 + runtime
139 + .request(XAI_INTERJECT_METHOD, {
140 + sessionId,
141 + text,
142 + ...(images.length === 0 ? {} : { content: images }),
143 + })
144 + .pipe(
145 + Effect.flatMap((result) =>
146 + isXAiInterjectQueued(result)
147 + ? Effect.undefined
148 + : Effect.fail(
149 + new EffectAcpErrors.AcpRequestError({
150 + code: -32603,
151 + errorMessage: "Grok did not queue the interjection.",
152 + method: XAI_INTERJECT_METHOD,
153 + data: result,
154 + }),
155 + ),
156 + ),
157 + ),
158 +};
159 +
160 export interface GrokAdapterV2Options {
161 readonly instanceId: Parameters<typeof makeAcpAdapterV2>[0]["instanceId"];
162 readonly settings: GrokSettings;
@@ -330,6 +366,7 @@ export function makeGrokAcpAdapterFlavor(
366 // Grok accepts image blocks despite advertising promptCapabilities.image:false.
367 supportsImagePrompts: true,
368 supportsCompaction: true,
369 + steering: grokSteering,
370 // Grok expands only a leading `/name`, while the `$` picker inserts `$name` from the
371 // `grok inspect` catalog. Ask that catalog again so other `$` text is left alone.
372 rewriteUserText: (text, turnInput) => {