Skip to content

Commit d313b2a

Browse files
fix(cursor): a steer keeps the prompt it interrupted (pingdotgg#32583)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 57d5e98 commit d313b2a

3 files changed

Lines changed: 179 additions & 11 deletions

File tree

‎apps/server/src/orchestration-v2/testkit/fixtures/message_steering/cursor_transcript.ndjson‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282","update":{"type":"thinking-delta","text":"The user requested the"}}}
77
{"type":"expect_outbound","label":"run.cancel:1","frame":{"type":"run.cancel","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282"}}
88
{"type":"emit_inbound","label":"run.completed:1","frame":{"type":"run.completed","result":{"id":"run-046488f0-f621-4d59-976c-c4c935ad1282","requestId":"d3b97820-1cf3-448d-a4b1-5fa7edc21460","status":"cancelled","model":{"id":"composer-2.5"},"durationMs":3177}}}
9-
{"type":"expect_outbound","label":"run.start:2","frame":{"type":"run.start","message":"Actually, respond with exactly: steering fixture observed","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
9+
{"type":"expect_outbound","label":"run.start:2","frame":{"type":"run.start","message":"Your previous turn was interrupted and is missing from your history. Some of its work may already be done. Its request was:\n\nRespond with exactly: steering fixture initial response\n\nThe new message, which may continue or change that request:\n\nActually, respond with exactly: steering fixture observed","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
1010
{"type":"emit_inbound","label":"run.started:2","frame":{"type":"run.started","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
1111
{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":"The response will be"}}}
1212
{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}

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

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ThreadId,
1515
} from "@t3tools/contracts";
1616
import * as DateTime from "effect/DateTime";
17+
import * as Deferred from "effect/Deferred";
1718
import * as Effect from "effect/Effect";
1819
import * as FileSystem from "effect/FileSystem";
1920
import * as Layer from "effect/Layer";
@@ -812,6 +813,151 @@ describe("CursorAdapterV2", () => {
812813
),
813814
);
814815

816+
it.effect("carries an interrupted prompt into the steer that restarts the turn", () =>
817+
Effect.gen(function* () {
818+
const fileSystem = yield* FileSystem.FileSystem;
819+
const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-steer-" });
820+
const sentMessages: Array<string> = [];
821+
const runEnds: Array<Deferred.Deferred<"finished" | "cancelled">> = [];
822+
const instanceId = ProviderInstanceId.make("cursor");
823+
const threadId = ThreadId.make("cursor-steer-thread");
824+
const modelSelection = { instanceId, model: "composer-2.5" };
825+
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
826+
runtimeMode: "full-access",
827+
interactionMode: "default",
828+
cwd: workspace,
829+
});
830+
const adapter = yield* makeCursorAdapterV2({
831+
instanceId,
832+
environment: { HOME: workspace },
833+
}).pipe(
834+
Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {
835+
assertComplete: Effect.void,
836+
open: () =>
837+
Effect.succeed({
838+
agentId: "native-cursor-steer",
839+
listMessages: Effect.succeed([]),
840+
close: Effect.void,
841+
send: (input) =>
842+
Effect.gen(function* () {
843+
sentMessages.push(
844+
typeof input.message === "string" ? input.message : input.message.text,
845+
);
846+
const runId = `native-cursor-run-${sentMessages.length}`;
847+
const ended = yield* Deferred.make<"finished" | "cancelled">();
848+
runEnds.push(ended);
849+
return {
850+
agentId: "native-cursor-steer",
851+
runId,
852+
// Cursor drops a cancelled run's prompt from the agent's conversation.
853+
wait: Deferred.await(ended).pipe(
854+
Effect.map((status) => ({
855+
id: runId,
856+
requestId: `native-request-${sentMessages.length}`,
857+
status,
858+
model: { id: "composer-2.5" },
859+
durationMs: 1,
860+
})),
861+
),
862+
cancel: Deferred.succeed(ended, "cancelled"),
863+
};
864+
}),
865+
}),
866+
}),
867+
Effect.provide(TestProviderHost.layer({ cwd: workspace })),
868+
);
869+
const runtime = yield* adapter.openSession({
870+
threadId,
871+
providerSessionId: ProviderSessionId.make("cursor-steer-session"),
872+
modelSelection,
873+
runtimePolicy,
874+
});
875+
const providerThread = yield* runtime.ensureThread({
876+
threadId,
877+
modelSelection,
878+
runtimePolicy,
879+
});
880+
const now = yield* DateTime.now;
881+
const appThread = {
882+
id: threadId,
883+
projectId: ProjectId.make("cursor-steer-project"),
884+
createdBy: "user" as const,
885+
creationSource: "web" as const,
886+
title: "Cursor steer",
887+
providerInstanceId: instanceId,
888+
modelSelection,
889+
runtimeMode: "full-access" as const,
890+
interactionMode: "default" as const,
891+
branch: null,
892+
worktreePath: null,
893+
activeProviderThreadId: providerThread.id,
894+
lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
895+
forkedFrom: null,
896+
createdAt: now,
897+
updatedAt: now,
898+
archivedAt: null,
899+
settledOverride: null,
900+
settledAt: null,
901+
lastVisitedAt: null,
902+
deletedAt: null,
903+
};
904+
const turnInput = (runOrdinal: number, text: string) => ({
905+
threadId,
906+
providerThread,
907+
modelSelection,
908+
runtimePolicy,
909+
runId: RunId.make(`cursor-steer-run-${runOrdinal}`),
910+
runOrdinal,
911+
providerTurnOrdinal: runOrdinal,
912+
attemptId: RunAttemptId.make(`cursor-steer-attempt-${runOrdinal}`),
913+
rootNodeId: NodeId.make(`cursor-steer-root-${runOrdinal}`),
914+
appThread,
915+
message: {
916+
messageId: MessageId.make(`cursor-steer-message-${runOrdinal}`),
917+
createdBy: "user" as const,
918+
creationSource: "web" as const,
919+
text,
920+
attachments: [],
921+
},
922+
});
923+
const firstPrompt = "Write me a 1000 word story about a dog.";
924+
const steerText = "No wait, a pig please.";
925+
926+
yield* runtime.startTurn(turnInput(1, firstPrompt));
927+
const started = Option.getOrThrow(
928+
yield* runtime.events.pipe(
929+
Stream.filter((event) => event.type === "provider_turn.updated"),
930+
Stream.runHead,
931+
),
932+
);
933+
assert(started.type === "provider_turn.updated");
934+
yield* runtime.interruptTurn({ providerThread, providerTurnId: started.providerTurn.id });
935+
yield* runtime.startTurn(turnInput(2, steerText));
936+
937+
assert.lengthOf(sentMessages, 2);
938+
const steered = sentMessages[1]!;
939+
assert.include(steered, steerText);
940+
assert.include(
941+
steered,
942+
firstPrompt,
943+
"the interrupted prompt is missing from the run that replaces it",
944+
);
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");
953+
}).pipe(
954+
Effect.scoped,
955+
Effect.provide(
956+
Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
957+
),
958+
),
959+
);
960+
815961
it.effect("projects Cursor directory trees and lint diagnostics as file search results", () =>
816962
Effect.gen(function* () {
817963
const fileSystem = yield* FileSystem.FileSystem;

‎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)