@devries-cameron20 / t3code-1 / commits / 71aa1173b0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(cursor): explain model rejections from the account catalog (#19678)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Wout Stiens committed Oct 18, 2026 at 21:14 UTC 71aa1173b07960885d38346e77648de890aa7d61
4 files changed +187 -27
packages/provider-core/src/server/failure.ts
+1
@@ -45,6 +45,7 @@ function causeMessage(cause: unknown): string | undefined {
45 case "ContextHandoffBudgetError":
46 return new ContextHandoffBudgetError().message;
47 case "ClaudeBackgroundWorkBlocksQueryReplacementError":
48 + case "CursorModelUnavailableError":
49 return stringField(cause, "message");
50 case "ContextHandoffDeliveryUncertainError":
51 return "T3 could not confirm whether conversation history reached the provider. Retry the turn to recover the session.";
packages/provider-cursor/src/server/adapter.test.ts
+124
@@ -26,6 +26,7 @@ import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
26 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
27 import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
28 import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
29 +import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
30 import {
31 cursorMcpServers,
32 cursorRuntimeAgentPolicy,
@@ -35,6 +36,7 @@ import {
36 nestedToolCallFromEnvelope,
37 } from "./adapter.ts";
38 import * as CursorAgentSdk from "./CursorAgentSdk.ts";
39 +import { ConfigurationError } from "./sdk.ts";
40
41 const decodeCursorSettings = Schema.decodeEffect(CursorSettings);
42
@@ -777,6 +779,128 @@ describe("CursorAdapterV2", () => {
779 ),
780 );
781
782 + it.effect("names a custom model Cursor's account catalog rejects", () =>
783 + Effect.gen(function* () {
784 + const fileSystem = yield* FileSystem.FileSystem;
785 + const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-model-" });
786 + const instanceId = ProviderInstanceId.make("cursor");
787 + const threadId = ThreadId.make("cursor-custom-model-thread");
788 + const catalogModel = { instanceId, model: "composer-2.5" };
789 + const customModel = { instanceId, model: "deepseek/deepseek-v4.1-flash" };
790 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
791 + runtimeMode: "full-access",
792 + interactionMode: "default",
793 + cwd: workspace,
794 + });
795 + // The SDK checks every create, resume, and send model against the account catalog.
796 + const checkModel = (method: string, model: { readonly id: string } | undefined) =>
797 + model === undefined || model.id === "composer-2.5"
798 + ? Effect.void
799 + : Effect.fail(
800 + new CursorAgentSdk.CursorAgentSdkRunnerError({
801 + method,
802 + cause: new ConfigurationError(
803 + `Cannot use this model: ${model.id}. Available models: default, composer-2.5. Use Cursor.models.list() to discover valid selections.`,
804 + { isRetryable: false },
805 + ),
806 + }),
807 + );
808 + const adapter = yield* makeCursorAdapterV2({
809 + instanceId,
810 + settings: yield* decodeCursorSettings({}),
811 + environment: { HOME: workspace },
812 + }).pipe(
813 + Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {
814 + assertComplete: Effect.void,
815 + open: (input) =>
816 + checkModel(`agent.${input.operation}`, input.options.model).pipe(
817 + Effect.as({
818 + agentId: "native-cursor-custom-model",
819 + listMessages: Effect.succeed([]),
820 + close: Effect.void,
821 + send: (sendInput) =>
822 + checkModel("run.start", sendInput.options?.model).pipe(
823 + Effect.andThen(Effect.die("unexpected Cursor run")),
824 + ),
825 + }),
826 + ),
827 + }),
828 + Effect.provide(TestProviderHost.layer({ cwd: workspace })),
829 + );
830 + const runtime = yield* adapter.openSession({
831 + threadId,
832 + providerSessionId: ProviderSessionId.make("cursor-custom-model-session"),
833 + modelSelection: catalogModel,
834 + runtimePolicy,
835 + });
836 + const expected =
837 + 'Cursor cannot run the model "deepseek/deepseek-v4.1-flash". Cursor only runs models from your Cursor account. Choose one of those, or use OpenCode for OpenRouter and other API-key models.';
838 +
839 + // A new thread created with the custom model.
840 + const createFailure = yield* runtime
841 + .ensureThread({ threadId, modelSelection: customModel, runtimePolicy })
842 + .pipe(Effect.flip);
843 + assert.equal(makeProviderFailure({ cause: createFailure }).message, expected);
844 +
845 + // An existing thread switched to the custom model.
846 + const providerThread = yield* runtime.ensureThread({
847 + threadId,
848 + modelSelection: catalogModel,
849 + runtimePolicy,
850 + });
851 + const now = yield* DateTime.now;
852 + const sendFailure = yield* runtime
853 + .startTurn({
854 + threadId,
855 + providerThread,
856 + modelSelection: customModel,
857 + runtimePolicy,
858 + runId: RunId.make("cursor-custom-model-run"),
859 + runOrdinal: 1,
860 + providerTurnOrdinal: 1,
861 + attemptId: RunAttemptId.make("cursor-custom-model-attempt"),
862 + rootNodeId: NodeId.make("cursor-custom-model-root"),
863 + appThread: {
864 + id: threadId,
865 + projectId: ProjectId.make("cursor-custom-model-project"),
866 + createdBy: "user",
867 + creationSource: "web",
868 + title: "Cursor custom model",
869 + providerInstanceId: instanceId,
870 + modelSelection: customModel,
871 + runtimeMode: "full-access",
872 + interactionMode: "default",
873 + branch: null,
874 + worktreePath: null,
875 + activeProviderThreadId: providerThread.id,
876 + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
877 + forkedFrom: null,
878 + createdAt: now,
879 + updatedAt: now,
880 + archivedAt: null,
881 + settledOverride: null,
882 + settledAt: null,
883 + lastVisitedAt: null,
884 + deletedAt: null,
885 + },
886 + message: {
887 + messageId: MessageId.make("cursor-custom-model-message"),
888 + createdBy: "user",
889 + creationSource: "web",
890 + text: "Hello.",
891 + attachments: [],
892 + },
893 + })
894 + .pipe(Effect.flip);
895 + assert.equal(makeProviderFailure({ cause: sendFailure }).message, expected);
896 + }).pipe(
897 + Effect.scoped,
898 + Effect.provide(
899 + Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
900 + ),
901 + ),
902 + );
903 +
904 it("maps Cursor auto and model parameters to SDK selections", () => {
905 assert.deepEqual(
906 cursorSdkModelSelection({
packages/provider-cursor/src/server/adapter.ts
+61 -27
@@ -74,6 +74,7 @@ import {
74 subagentThreadTitle,
75 } from "@t3tools/provider-core/server/subagentProjection";
76 import * as CursorAgentSdk from "./CursorAgentSdk.ts";
77 +import { ConfigurationError } from "./sdk.ts";
78 export { cursorSdkModelSelection } from "./sdkModel.ts";
79
80 export const CURSOR_DRIVER_KIND = CursorAgentSdk.CURSOR_PROVIDER;
@@ -326,6 +327,35 @@ export function makeCursorAgentOptions(input: {
327 };
328 }
329
330 +/**
331 + * Raised when Cursor rejects the selected model, usually a custom model outside
332 + * the account catalog. `makeProviderFailure` shows its message to the user.
333 + */
334 +class CursorModelUnavailableError extends Schema.TaggedError<CursorModelUnavailableError>()(
335 + "CursorModelUnavailableError",
336 + {
337 + model: Schema.String,
338 + cause: Schema.Defect(),
339 + },
340 +) {
341 + override get message(): string {
342 + return `Cursor cannot run the model "${this.model}". Cursor only runs models from your Cursor account. Choose one of those, or use OpenCode for OpenRouter and other API-key models.`;
343 + }
344 +}
345 +
346 +/**
347 + * Maps runner failures from opening or sending to an agent. The SDK checks the
348 + * model against the account catalog before either and rejects it with an
349 + * uncoded ConfigurationError listing every account model, so its message
350 + * prefix is the only signal.
351 + */
352 +const classifyCursorModelRejection =
353 + (modelSelection: ModelSelection) => (error: CursorAgentSdk.CursorAgentSdkRunnerError) =>
354 + error.cause instanceof ConfigurationError &&
355 + error.cause.message.startsWith("Cannot use this model:")
356 + ? new CursorModelUnavailableError({ model: modelSelection.model, cause: error.cause })
357 + : error;
358 +
359 function stableJson(value: unknown): string {
360 try {
361 return JSON.stringify(value, null, 2);
@@ -2094,19 +2124,21 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2124 yield* existing.session.close.pipe(Effect.ignore);
2125 yield* Ref.set(liveAgent, null);
2126 }
2097 - const sdkSession = yield* runner.open({
2098 - operation: openInput.operation,
2099 - ...(openInput.agentId === undefined ? {} : { agentId: openInput.agentId }),
2100 - options: makeCursorAgentOptions({
2101 - ...(apiKey === undefined ? {} : { apiKey }),
2102 - modelSelection: openInput.modelSelection,
2103 - runtimePolicy: openInput.runtimePolicy,
2127 + const sdkSession = yield* runner
2128 + .open({
2129 + operation: openInput.operation,
2130 + ...(openInput.agentId === undefined ? {} : { agentId: openInput.agentId }),
2131 + options: makeCursorAgentOptions({
2132 + ...(apiKey === undefined ? {} : { apiKey }),
2133 + modelSelection: openInput.modelSelection,
2134 + runtimePolicy: openInput.runtimePolicy,
2135 + threadId: openInput.threadId,
2136 + mcpSession: yield* mcpSessions.read(openInput.threadId),
2137 + }),
2138 threadId: openInput.threadId,
2105 - mcpSession: yield* mcpSessions.read(openInput.threadId),
2106 - }),
2107 - threadId: openInput.threadId,
2108 - providerSessionId: input.providerSessionId,
2109 - });
2139 + providerSessionId: input.providerSessionId,
2140 + })
2141 + .pipe(Effect.mapError(classifyCursorModelRejection(openInput.modelSelection)));
2142 const next = {
2143 nativeThreadId: sdkSession.agentId,
2144 session: sdkSession,
@@ -2215,21 +2247,23 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2247 const pendingUpdates: Array<InteractionUpdate> = [];
2248 let context: ActiveCursorTurn | null = null;
2249 // MCP send overrides replace the ambient servers loaded when the agent opens.
2218 - const sdkRun = yield* agent.session.send({
2219 - message,
2220 - options: {
2221 - model: cursorSdkModelSelection(turnInput.modelSelection),
2222 - mode: turnInput.runtimePolicy.interactionMode === "plan" ? "plan" : "agent",
2223 - },
2224 - onDelta: (update) => {
2225 - if (context === null) {
2226 - return Effect.sync(() => {
2227 - pendingUpdates.push(update);
2228 - });
2229 - }
2230 - return handleInteractionUpdate(context, update);
2231 - },
2232 - });
2250 + const sdkRun = yield* agent.session
2251 + .send({
2252 + message,
2253 + options: {
2254 + model: cursorSdkModelSelection(turnInput.modelSelection),
2255 + mode: turnInput.runtimePolicy.interactionMode === "plan" ? "plan" : "agent",
2256 + },
2257 + onDelta: (update) => {
2258 + if (context === null) {
2259 + return Effect.sync(() => {
2260 + pendingUpdates.push(update);
2261 + });
2262 + }
2263 + return handleInteractionUpdate(context, update);
2264 + },
2265 + })
2266 + .pipe(Effect.mapError(classifyCursorModelRejection(turnInput.modelSelection)));
2267 const startedAt = yield* DateTime.now;
2268 const completed = yield* Deferred.make<void, never>();
2269 const providerTurnId = idAllocator.derive.providerTurn({
packages/provider-cursor/src/server/sdk.ts
+1
@@ -7,6 +7,7 @@ const requireCursorSdk = NodeModule.createRequire(import.meta.url);
7 export const {
8 Agent,
9 AuthenticationError,
10 + ConfigurationError,
11 createAgentPlatform,
12 Cursor,
13 CursorSdkError,