The best way to control Claude Code, Codex and more from any computer or phone
fix(grok): preserve native question multi-select (#20881)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com>
Yannic Charlon committed
Oct 19, 2026 at 03:28 UTC
69f4042aa8dc7b35ad5d94b858caa7ee6a77c04e
2 files changed
+247
-3
apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts
+246
@@ -1,6 +1,12 @@
1
import * as NodeServices from "@effect/platform-node/NodeServices";
2
import {
3
ProjectId,
4
+ MessageId,
5
+ NodeId,
6
+ RunAttemptId,
7
+ RunId,
8
+ type OrchestrationV2UserInputQuestion,
9
+ type OrchestrationV2RuntimeRequest,
10
ProviderInstanceId,
11
ProviderSessionId,
12
type RuntimeMode,
@@ -14,6 +20,10 @@ import { xAiRateLimitedErrorCode } from "@t3tools/provider-grok/testing";
20
import { assert, describe, it } from "@effect/vitest";
21
import * as DateTime from "effect/DateTime";
22
import * as Effect from "effect/Effect";
23
+import * as Deferred from "effect/Deferred";
24
+import * as FileSystem from "effect/FileSystem";
25
+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 Schema from "effect/Schema";
@@ -40,8 +50,12 @@ import {
50
makeGrokAcpAdapterFlavor,
51
makeGrokAdapterV2,
52
GrokProviderCapabilitiesV2,
53
+ GROK_PROVIDER,
54
+ GROK_ACP_INITIALIZE_META,
55
} from "@t3tools/provider-grok/testing";
56
57
+import { makeAcpReplayRuntime, type AcpReplayTranscript } from "./AcpAdapterV2.testkit.ts";
58
+
59
const LAUNCH_TEST_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({
60
binaryPath: "grok-launch-test",
61
});
@@ -460,3 +474,235 @@ describe("Grok launch permission mode", () => {
474
}),
475
);
476
});
477
+
478
+describe("Grok native questions", () => {
479
+ const layerHost = TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer));
480
+ const layerTest = Layer.mergeAll(
481
+ NodeServices.layer,
482
+ IdAllocator.layer,
483
+ McpProviderSessions.layer,
484
+ layerHost,
485
+ );
486
+
487
+ it.live("keeps x.ai multi-select questions live and returns all selected answers", () =>
488
+ Effect.gen(function* () {
489
+ const fs = yield* FileSystem.FileSystem;
490
+ const path = yield* Path.Path;
491
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
492
+ const workspace = yield* fs.makeTempDirectoryScoped({ prefix: "grok-multi-select-" });
493
+ const questionText = "Which changes should be included?";
494
+ const transcript: AcpReplayTranscript = {
495
+ provider: GROK_PROVIDER,
496
+ protocol: "acp.ndjson-jsonrpc",
497
+ version: "1",
498
+ scenario: "grok-multi-select",
499
+ entries: [
500
+ {
501
+ type: "expect_outbound",
502
+ label: "initialize",
503
+ frame: { kind: "request", method: "initialize", params: "<any>" },
504
+ },
505
+ {
506
+ type: "emit_inbound",
507
+ label: "initialized",
508
+ frame: {
509
+ kind: "response",
510
+ method: "initialize",
511
+ result: {
512
+ protocolVersion: 1,
513
+ agentCapabilities: { loadSession: true, promptCapabilities: { image: false } },
514
+ authMethods: [{ id: "replay", name: "Replay" }],
515
+ },
516
+ },
517
+ },
518
+ {
519
+ type: "expect_outbound",
520
+ label: "session.new",
521
+ frame: { kind: "request", method: "session/new", params: "<any>" },
522
+ },
523
+ {
524
+ type: "emit_inbound",
525
+ label: "session.created",
526
+ frame: {
527
+ kind: "response",
528
+ method: "session/new",
529
+ result: {
530
+ sessionId: "grok-multi-select-session",
531
+ models: {
532
+ currentModelId: "grok-build",
533
+ availableModels: [{ modelId: "grok-build", name: "Grok Build" }],
534
+ },
535
+ },
536
+ },
537
+ },
538
+ {
539
+ type: "expect_outbound",
540
+ label: "prompt",
541
+ frame: { kind: "request", method: "session/prompt", params: "<any>" },
542
+ },
543
+ {
544
+ type: "emit_inbound",
545
+ label: "question",
546
+ frame: {
547
+ kind: "request",
548
+ method: "_x.ai/ask_user_question",
549
+ params: {
550
+ method: "x.ai/ask_user_question",
551
+ params: {
552
+ sessionId: "grok-multi-select-session",
553
+ toolCallId: "grok-question",
554
+ mode: "default",
555
+ questions: [
556
+ {
557
+ id: "changes",
558
+ question: questionText,
559
+ multiSelect: true,
560
+ options: [
561
+ { label: "Tests", description: "Cover behavior" },
562
+ { label: "Docs", description: "Explain usage" },
563
+ ],
564
+ },
565
+ ],
566
+ },
567
+ },
568
+ },
569
+ },
570
+ {
571
+ type: "expect_outbound",
572
+ label: "selected answers",
573
+ frame: {
574
+ kind: "response",
575
+ method: "_x.ai/ask_user_question",
576
+ result: { outcome: "accepted", answers: { [questionText]: ["Tests", "Docs"] } },
577
+ },
578
+ },
579
+ {
580
+ type: "emit_inbound",
581
+ label: "complete",
582
+ frame: {
583
+ kind: "response",
584
+ method: "session/prompt",
585
+ result: { stopReason: "end_turn" },
586
+ },
587
+ },
588
+ ],
589
+ };
590
+ const statusPath = path.join(workspace, "status.json");
591
+ const scriptPath = yield* path.fromFileUrl(
592
+ new URL("../../../scripts/acp-replay-agent.ts", import.meta.url),
593
+ );
594
+ const instanceId = ProviderInstanceId.make("grok-multi-select");
595
+ const threadId = ThreadId.make("grok-multi-select-thread");
596
+ const adapter = yield* makeGrokAdapterV2({
597
+ instanceId,
598
+ settings: LAUNCH_TEST_GROK_SETTINGS,
599
+ environment: {},
600
+ hostPlatform: "darwin",
601
+ selfInvocation: yield* resolveSelfInvocation(),
602
+ makeRuntime: makeAcpReplayRuntime({
603
+ transcript,
604
+ statusPath,
605
+ scriptPath,
606
+ childProcessSpawner,
607
+ fileSystem: fs,
608
+ initializeMeta: GROK_ACP_INITIALIZE_META,
609
+ }),
610
+ });
611
+ const policy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
612
+ runtimeMode: "approval-required",
613
+ interactionMode: "default",
614
+ cwd: workspace,
615
+ });
616
+ const modelSelection = { instanceId, model: "grok-build" };
617
+ const runtime = yield* adapter.openSession({
618
+ threadId,
619
+ providerSessionId: ProviderSessionId.make("grok-multi-select-session"),
620
+ modelSelection,
621
+ runtimePolicy: policy,
622
+ });
623
+ const providerThread = yield* runtime.ensureThread({
624
+ threadId,
625
+ modelSelection,
626
+ runtimePolicy: policy,
627
+ });
628
+ const question = yield* Deferred.make<OrchestrationV2UserInputQuestion>();
629
+ const request = yield* Deferred.make<OrchestrationV2RuntimeRequest>();
630
+ const terminal = yield* Deferred.make<void>();
631
+ yield* runtime.events.pipe(
632
+ Stream.runForEach((event) => {
633
+ if (
634
+ event.type === "turn_item.updated" &&
635
+ event.turnItem.type === "user_input_request" &&
636
+ event.turnItem.questions[0]
637
+ )
638
+ return Deferred.succeed(question, event.turnItem.questions[0]);
639
+ if (event.type === "runtime_request.updated")
640
+ return Deferred.succeed(request, event.runtimeRequest);
641
+ if (event.type === "turn.terminal") return Deferred.succeed(terminal, undefined);
642
+ return Effect.void;
643
+ }),
644
+ Effect.forkScoped,
645
+ );
646
+ const now = yield* DateTime.now;
647
+ yield* runtime.startTurn({
648
+ appThread: {
649
+ createdBy: "user",
650
+ creationSource: "web",
651
+ id: threadId,
652
+ projectId: ProjectId.make("grok-multi-select-project"),
653
+ title: "Grok multi-select",
654
+ providerInstanceId: instanceId,
655
+ modelSelection,
656
+ runtimeMode: "approval-required",
657
+ interactionMode: "default",
658
+ branch: null,
659
+ worktreePath: workspace,
660
+ activeProviderThreadId: providerThread.id,
661
+ lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
662
+ forkedFrom: null,
663
+ createdAt: now,
664
+ updatedAt: now,
665
+ archivedAt: null,
666
+ settledOverride: null,
667
+ settledAt: null,
668
+ lastVisitedAt: null,
669
+ deletedAt: null,
670
+ },
671
+ threadId,
672
+ runId: RunId.make("grok-multi-select-run"),
673
+ runOrdinal: 1,
674
+ providerTurnOrdinal: 1,
675
+ attemptId: RunAttemptId.make("grok-multi-select-attempt"),
676
+ rootNodeId: NodeId.make("grok-multi-select-root"),
677
+ providerThread,
678
+ message: {
679
+ createdBy: "user",
680
+ creationSource: "web",
681
+ messageId: MessageId.make("grok-multi-select-message"),
682
+ text: "Ask which changes to include.",
683
+ attachments: [],
684
+ },
685
+ modelSelection,
686
+ runtimePolicy: policy,
687
+ });
688
+ assert.deepEqual(yield* Deferred.await(question), {
689
+ id: "changes",
690
+ header: "Question",
691
+ question: questionText,
692
+ multiSelect: true,
693
+ options: [
694
+ { label: "Tests", description: "Cover behavior" },
695
+ { label: "Docs", description: "Explain usage" },
696
+ ],
697
+ });
698
+ const pending = yield* Deferred.await(request);
699
+ assert.equal(pending.kind, "user_input");
700
+ assert.equal(pending.responseCapability.type, "live");
701
+ yield* runtime.respondToRuntimeRequest({
702
+ requestId: pending.id,
703
+ answers: { changes: ["Tests", "Docs"] },
704
+ });
705
+ yield* Deferred.await(terminal);
706
+ }).pipe(Effect.scoped, Effect.provide(layerTest)),
707
+ );
708
+});
packages/provider-grok/src/server/adapter.ts
+1
-3
@@ -186,9 +186,7 @@ const registerGrokAskUserQuestionExtensions = ({
186
runtime.handleExtRequest(method, XAiAskUserQuestionRequest, (params, requestContext) => {
187
const identity = extractXAiAskUserQuestionIdentity(params);
188
const questions = extractXAiAskUserQuestions(params).map((question) => ({
189
- id: question.id,
190
- header: question.header,
191
- question: question.question,
189
+ ...question,
190
options: [...question.options],
191
}));
192
return requestUserInput(