Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions apps/server/src/orchestration-v2/CommandPolicy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as Effect from "effect/Effect";
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
import { CursorProviderCapabilitiesV2 } from "@t3tools/provider-cursor/testing";
import * as CommandPolicy from "./CommandPolicy.ts";
import { makeGrokAcpAdapterFlavor } from "@t3tools/provider-grok/testing";

const commandId = CommandId.make("command-policy-test");
const threadId = ThreadId.make("command-policy-thread");
Expand Down Expand Up @@ -164,9 +165,15 @@ it.each([
);
});

// regression: #26695 an interrupt-restart steer cancels Copilot's background agents
it("queues a steer for a provider that cannot steer either way", () => {
const projection = dispatchProjection(
const grokCapabilities = makeGrokAcpAdapterFlavor(
{ makeRuntime: () => Effect.never } as unknown as Parameters<typeof makeGrokAcpAdapterFlavor>[0],
"/home/ada",
).capabilities;

// Interrupt-and-restart cancels running tools and native background agents.
it.each([
[
"generic",
capabilities((current) => ({
...current,
turns: {
Expand All @@ -176,7 +183,10 @@ it("queues a steer for a provider that cannot steer either way", () => {
supportsQueuedMessages: true,
},
})),
);
],
["Grok", grokCapabilities],
])("queues a steer for %s when it cannot steer either way", (_, providerCapabilities) => {
const projection = dispatchProjection(providerCapabilities);
for (const deliveryIntent of ["auto", "steer"] as const) {
assert.deepEqual(
CommandPolicy.resolveMessageDispatchIntent(
Expand Down Expand Up @@ -247,6 +257,23 @@ it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) =
const layer = it.layer(CommandPolicy.layer);

layer("CommandPolicyV2", (it) => {
it.effect("allows Grok Stop but rejects explicit Restart", () =>
Effect.gen(function* () {
const policy = yield* CommandPolicy.CommandPolicyV2;
const input = {
commandId,
threadId,
providerInstanceId: ProviderInstanceId.make("grok"),
capabilities: grokCapabilities,
};
yield* policy.ensureInterrupt(input);
const error = yield* policy
.decideSteeringExecution({ ...input, forceRestart: true })
.pipe(Effect.flip);
assert.equal(error.capability, "interrupt_restart_steering");
}),
);

it.effect("falls back to portable context when Cursor cannot fork natively", () =>
Effect.gen(function* () {
const policy = yield* CommandPolicy.CommandPolicyV2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ThreadId,
TurnItemId,
type ModelSelection,
type ChatAttachment,
type OrchestrationV2ProviderCapabilities,
type OrchestrationV2DomainEvent,
} from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
Expand All @@ -28,6 +30,7 @@ import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts";
import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace";
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
import { makeGrokAcpAdapterFlavor } from "@t3tools/provider-grok/testing";

const driver = ProviderDriverKind.make("codex");
const instanceId = ProviderInstanceId.make("codex");
Expand Down Expand Up @@ -448,13 +451,14 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
name: string,
canRestart = false,
canSteer = true,
providerCapabilities?: OrchestrationV2ProviderCapabilities,
) {
const cwd = yield* checkpointWorkspace(name);
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = [];
const steered: string[] = [];
const interrupted: ProviderTurnId[] = [];
const capabilities = {
const capabilities = providerCapabilities ?? {
...CodexProviderCapabilitiesV2,
turns: {
...CodexProviderCapabilitiesV2.turns,
Expand Down Expand Up @@ -943,25 +947,52 @@ it.effect("starts a steer that missed the turn on the saved next-turn selection"
),
);

// regression: #26695 cancelling a Copilot prompt to steer it kills its background agents
it.effect("queues a steer until the turn ends when the provider cannot steer it", () =>
// Interrupt-and-restart cancels running tools and native background agents.
it.effect("queues a Grok steer with attachments until the turn ends without cancellation", () =>
Effect.scoped(
Effect.gen(function* () {
const { events, started, steered, interrupted, layer, startFirstTurn } =
yield* nextTurnSelectionHarness("steering-unsupported", false, false);
yield* nextTurnSelectionHarness(
"steering-unsupported",
false,
false,
makeGrokAcpAdapterFlavor(
{ makeRuntime: () => Effect.never } as unknown as Parameters<
typeof makeGrokAcpAdapterFlavor
>[0],
"/home/ada",
).capabilities,
);
yield* Effect.gen(function* () {
const orchestrator = yield* Orchestrator.OrchestratorV2;
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
const threadId = yield* startFirstTurn;
const first = started[0]!;
const messageId = MessageId.make("message:steer");
const attachments: ChatAttachment[] = [
{
type: "image",
id: "queued-image",
name: "image.png",
mimeType: "image/png",
sizeBytes: 10,
},
{
type: "file",
id: "queued-file",
name: "notes.txt",
mimeType: "text/plain",
sizeBytes: 20,
source: { _tag: "pasted-text" },
},
];
yield* orchestrator.dispatch({
type: "message.dispatch",
commandId: CommandId.make("steer"),
threadId,
messageId,
text: "follow up",
attachments: [],
attachments,
modelSelection: runSelection,
dispatchMode: { type: "start_immediately" },
deliveryIntent: "steer",
Expand All @@ -977,6 +1008,10 @@ it.effect("queues a steer until the turn ends when the provider cannot steer it"
assert.equal(held.runs.find((run) => run.id === first.runId)?.status, "running");
const queued = held.runs.find((run) => run.userMessageId === messageId);
assert.equal(queued?.status, "queued");
assert.deepEqual(
held.messages.find((message) => message.id === messageId)?.attachments,
attachments,
);

const settled = yield* orchestrator.streamDomainEvents.pipe(
Stream.filter(
Expand Down Expand Up @@ -1014,6 +1049,9 @@ it.effect("queues a steer until the turn ends when the provider cannot steer it"
assert.equal(started.length, 2);
assert.equal(started[1]?.runId, queued?.id);
assert.equal(started[1]?.message.text, "follow up");
assert.equal(started[1]?.message.messageId, messageId);
assert.deepEqual(started[1]?.message.attachments, attachments);
assert.deepEqual(steered, []);
}).pipe(Effect.provide(layer));
}),
),
Expand Down
4 changes: 4 additions & 0 deletions docs/user/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ On web and desktop, choose **Settings → Chat → Follow-up behavior** to queue
new messages for a later turn or steer the running turn immediately. The setting
applies to this client; already queued messages keep their place. Queued messages
are saved on the server and can be edited or removed before they send.
Grok follow-ups wait for the current turn to finish, even when Steer is selected,
so running tools are not cancelled. To cancel the current work, use Stop and then
send a new message. Explicit Restart is not supported for Grok.

When Enter sends, `Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux uses
the opposite action: it steers when your default is Queue and queues when your
default is Steer.
Expand Down
7 changes: 6 additions & 1 deletion packages/provider-grok/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);

const GrokProviderCapabilitiesV2 = {
...AcpProviderCapabilitiesV2,
turns: {
...AcpProviderCapabilitiesV2.turns,
// Cancelling a Grok prompt interrupts its running tools; queue follow-ups instead.
supportsSteeringByInterruptRestart: false,
},
sessions: {
...AcpProviderCapabilitiesV2.sessions,
supportsModelSwitchInSession: true,
Expand Down Expand Up @@ -228,7 +233,7 @@ export function makeGrokAcpAdapterFlavor(
runtimeHarness: "Grok",
capabilities: GrokProviderCapabilitiesV2,
interruptPromptOnCancel: false,
// User Stop restarts the process group; steering cancels softly to preserve background work.
// User Stop restarts the process group; follow-ups wait in the app-owned queue.
restartRuntimeAfterInterrupt: true,
terminateRuntimeProcessGroupOnInterrupt: true,
// Settled Grok sessions accept concurrent prompts; skip cancel to preserve background subagents.
Expand Down
Loading