Skip to content

Commit 53b1848

Browse files
fix(cursor): a steer keeps the prompt it interrupted
Cursor steers by cancelling the running turn and starting a new one, and Cursor drops a cancelled run from the agent's conversation. The new run saw only the steer text, and lost the T3 orchestration instructions the interrupted run had delivered. When T3 interrupts a Cursor run, the adapter now remembers the user text that run sent and puts it ahead of the next message on the same agent, framed as an interrupted request the new message may continue or change. It is cleared once a real message is sent and ignored for a different agent. Fixes #32568 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f3db164 commit 53b1848

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

‎packages/provider-cursor/src/server/adapter.test.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ describe("CursorAdapterV2", () => {
818818
const fileSystem = yield* FileSystem.FileSystem;
819819
const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-steer-" });
820820
const sentMessages: Array<string> = [];
821+
const runEnds: Array<Deferred.Deferred<"finished" | "cancelled">> = [];
821822
const instanceId = ProviderInstanceId.make("cursor");
822823
const threadId = ThreadId.make("cursor-steer-thread");
823824
const modelSelection = { instanceId, model: "composer-2.5" };
@@ -843,21 +844,22 @@ describe("CursorAdapterV2", () => {
843844
typeof input.message === "string" ? input.message : input.message.text,
844845
);
845846
const runId = `native-cursor-run-${sentMessages.length}`;
846-
const cancelled = yield* Deferred.make<void>();
847+
const ended = yield* Deferred.make<"finished" | "cancelled">();
848+
runEnds.push(ended);
847849
return {
848850
agentId: "native-cursor-steer",
849851
runId,
850852
// Cursor drops a cancelled run's prompt from the agent's conversation.
851-
wait: Deferred.await(cancelled).pipe(
852-
Effect.as({
853+
wait: Deferred.await(ended).pipe(
854+
Effect.map((status) => ({
853855
id: runId,
854856
requestId: `native-request-${sentMessages.length}`,
855-
status: "cancelled" as const,
857+
status,
856858
model: { id: "composer-2.5" },
857859
durationMs: 1,
858-
}),
860+
})),
859861
),
860-
cancel: Deferred.succeed(cancelled, undefined),
862+
cancel: Deferred.succeed(ended, "cancelled"),
861863
};
862864
}),
863865
}),
@@ -940,6 +942,14 @@ describe("CursorAdapterV2", () => {
940942
firstPrompt,
941943
"the interrupted prompt is missing from the run that replaces it",
942944
);
945+
946+
yield* Deferred.succeed(runEnds[1]!, "finished");
947+
yield* runtime.events.pipe(
948+
Stream.filter((event) => event.type === "turn.terminal" && event.status === "completed"),
949+
Stream.runHead,
950+
);
951+
yield* runtime.startTurn(turnInput(3, "Now a cow."));
952+
assert.notInclude(sentMessages[2]!, firstPrompt, "a finished turn carries nothing forward");
943953
}).pipe(
944954
Effect.scoped,
945955
Effect.provide(

‎packages/provider-cursor/src/server/adapter.ts‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ interface ActiveCursorTurn {
946946
readonly assistant: ActiveCursorTextStream;
947947
assistantReply: CursorTransportFailure;
948948
readonly reasoning: ActiveCursorTextStream;
949+
/** The user text this run sent, before runtime instructions; absent for /compress. */
950+
readonly prompt: string | undefined;
949951
interrupted: boolean;
950952
finalized: boolean;
951953
/** The agent's latest turn ended and no new work has started since. */
@@ -1004,6 +1006,11 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
10041006
readonly orchestration: boolean;
10051007
readonly device: boolean;
10061008
} | null>(null);
1009+
// Cursor drops a cancelled run from the conversation, so the next message carries its prompt.
1010+
const interruptedPrompt = yield* Ref.make<{
1011+
readonly agent: string;
1012+
readonly text: string;
1013+
} | null>(null);
10071014
const warnedUnsupportedSandbox = yield* Ref.make(false);
10081015
const activeTurn = yield* Ref.make<ActiveCursorTurn | null>(null);
10091016
const planIds = yield* Ref.make(new Map<string, OrchestrationV2PlanArtifact["id"]>());
@@ -2192,6 +2199,12 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
21922199
threadDisposition,
21932200
},
21942201
);
2202+
if (input.status === "interrupted" && input.context.prompt !== undefined) {
2203+
yield* Ref.set(interruptedPrompt, {
2204+
agent: input.context.run.agentId,
2205+
text: input.context.prompt,
2206+
});
2207+
}
21952208
yield* Ref.update(activeTurn, (current) =>
21962209
current?.providerTurnId === input.context.providerTurnId ? null : current,
21972210
);
@@ -2284,10 +2297,11 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
22842297
mcpServers: Record<string, McpServerConfig> | undefined,
22852298
hasDeviceTools: boolean,
22862299
delivered: { readonly orchestration: boolean; readonly device: boolean },
2300+
interrupted: string | undefined,
22872301
) {
22882302
const rawText = turnInput.message.text;
22892303
if (rawText.trim() === "/compress" && turnInput.message.attachments.length === 0) {
2290-
return "/compress";
2304+
return { message: "/compress", prompt: undefined };
22912305
}
22922306
if (hasCursorSkillMention(rawText) && cursorSkillNames === undefined) {
22932307
const skills = yield* discoverCursorSkills(
@@ -2303,7 +2317,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
23032317
.map((skill) => skill.name),
23042318
);
23052319
}
2306-
const userText = t3OrchestrationPrompt({
2320+
const newText = t3OrchestrationPrompt({
23072321
prompt: yield* providerMessageTextWithAttachmentPaths({
23082322
text:
23092323
cursorSkillNames === undefined
@@ -2318,6 +2332,10 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
23182332
orchestrationDelivered: delivered.orchestration,
23192333
deviceInstructionsDelivered: delivered.device,
23202334
});
2335+
const userText =
2336+
interrupted === undefined
2337+
? newText
2338+
: `Your previous turn was interrupted and is missing from your history. Some of its work may already be done. Its request was:\n\n${interrupted}\n\nThe new message, which may continue or change that request:\n\n${newText}`;
23212339
const images = yield* Effect.forEach(
23222340
turnInput.message.attachments.filter(isProviderNativeImageAttachment),
23232341
(attachment: ChatAttachment) =>
@@ -2354,12 +2372,10 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
23542372
});
23552373
}
23562374
const text = `${userText}\n\n${buildRuntimeInstructions({ harness: "Cursor", model: turnInput.modelSelection.model })}`;
2357-
return images.length === 0
2358-
? text
2359-
: ({
2360-
text,
2361-
images,
2362-
} satisfies SDKUserMessage);
2375+
return {
2376+
message: images.length === 0 ? text : ({ text, images } satisfies SDKUserMessage),
2377+
prompt: userText,
2378+
};
23632379
});
23642380

23652381
const startTurn = Effect.fn("CursorAdapterV2.startTurn")(
@@ -2390,13 +2406,15 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
23902406
known?.agent === agent.nativeThreadId
23912407
? known
23922408
: { orchestration: turnInput.runOrdinal > 1, device: false };
2393-
const message = yield* resolveUserMessage(
2409+
const interrupted = yield* Ref.get(interruptedPrompt);
2410+
const { message, prompt } = yield* resolveUserMessage(
23942411
turnInput,
23952412
mcpServers,
23962413
hasDeviceTools,
23972414
delivered,
2415+
interrupted?.agent === agent.nativeThreadId ? interrupted.text : undefined,
23982416
);
2399-
const compacted = message === "/compress";
2417+
const compacted = prompt === undefined;
24002418
const pendingUpdates: Array<InteractionUpdate> = [];
24012419
let context: ActiveCursorTurn | null = null;
24022420
// Create-time and send-time mcpServers merge with settingSources (SDK >= 1.0.39).
@@ -2424,6 +2442,9 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
24242442
orchestration: !compacted && (delivered.orchestration || mcpServers !== undefined),
24252443
device: !compacted && hasDeviceTools,
24262444
});
2445+
if (!compacted) {
2446+
yield* Ref.set(interruptedPrompt, null);
2447+
}
24272448
const startedAt = yield* DateTime.now;
24282449
const completed = yield* Deferred.make<void, never>();
24292450
const providerTurnId = idAllocator.derive.providerTurn({
@@ -2448,6 +2469,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
24482469
current: null,
24492470
nextSegment: 0,
24502471
},
2472+
prompt,
24512473
interrupted: false,
24522474
finalized: false,
24532475
turnEnded: false,

0 commit comments

Comments
 (0)