fix(cursor): cache successful model discovery between refreshes (#9918)
This commit is contained in:
1 parent
6349a0e68a
commit
0d8a91a25a
3 files changed
+68
-4
No files matched your search
@@ -29,6 +29,7 @@ import { makeCursorAdapter } from "../Layers/CursorAdapter.ts";
|
||||
import {
|
||||
buildInitialCursorProviderSnapshot,
|
||||
checkCursorProviderStatus,
|
||||
makeCursorModelDiscovery,
|
||||
enrichCursorSnapshot,
|
||||
} from "../Layers/CursorProvider.ts";
|
||||
import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
|
||||
@@ -136,7 +137,12 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
|
||||
});
|
||||
const textGeneration = yield* makeCursorTextGeneration(effectiveConfig, processEnv);
|
||||
|
||||
const checkProvider = checkCursorProviderStatus(effectiveConfig, processEnv).pipe(
|
||||
const discoverModels = yield* makeCursorModelDiscovery(effectiveConfig, processEnv);
|
||||
const checkProvider = checkCursorProviderStatus(
|
||||
effectiveConfig,
|
||||
processEnv,
|
||||
discoverModels,
|
||||
).pipe(
|
||||
Effect.map(stampIdentity),
|
||||
Effect.provideService(Crypto.Crypto, crypto),
|
||||
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
buildCursorCapabilitiesFromConfigOptions,
|
||||
checkCursorProviderStatus,
|
||||
discoverCursorModelsViaAcp,
|
||||
makeCursorModelDiscovery,
|
||||
getCursorParameterizedModelPickerUnsupportedMessage,
|
||||
parseCursorAboutOutput,
|
||||
parseCursorCliConfigChannel,
|
||||
@@ -627,6 +628,42 @@ describe("checkCursorProviderStatus", () => {
|
||||
});
|
||||
|
||||
describe("discoverCursorModelsViaAcp", () => {
|
||||
it("reuses successful discovery until the CLI version or account changes", async () => {
|
||||
await runNode(
|
||||
Effect.gen(function* () {
|
||||
const { requestLogPath, wrapperPath } = yield* makeProviderStatusEnvFixture();
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const settings = {
|
||||
enabled: true,
|
||||
binaryPath: wrapperPath,
|
||||
apiEndpoint: "",
|
||||
customModels: [],
|
||||
};
|
||||
const discover = yield* makeCursorModelDiscovery(settings, {
|
||||
...process.env,
|
||||
T3_ACP_REQUEST_LOG_PATH: requestLogPath,
|
||||
});
|
||||
const about = {
|
||||
version: "2026.08.11",
|
||||
auth: { status: "authenticated" as const, label: "[email protected]" },
|
||||
};
|
||||
const first = yield* discover(about);
|
||||
expect(first.length).toBeGreaterThan(0);
|
||||
yield* fileSystem.writeFileString(requestLogPath, "");
|
||||
expect(yield* discover(about)).toEqual(first);
|
||||
expect(yield* fileSystem.readFileString(requestLogPath)).toBe("");
|
||||
yield* discover({ ...about, version: "2026.08.12" });
|
||||
expect(yield* fileSystem.readFileString(requestLogPath)).toContain("initialize");
|
||||
yield* fileSystem.writeFileString(requestLogPath, "");
|
||||
yield* discover({
|
||||
version: "2026.08.12",
|
||||
auth: { ...about.auth, label: "[email protected]" },
|
||||
});
|
||||
expect(yield* fileSystem.readFileString(requestLogPath)).toContain("initialize");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the ACP probe runtime alive long enough to discover models", async () => {
|
||||
const wrapperPath = await runNode(makeMockAgentWrapper());
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import type {
|
||||
} from "@t3tools/contracts";
|
||||
import type * as EffectAcpSchema from "effect-acp/schema";
|
||||
import { causeErrorTag } from "@t3tools/shared/observability";
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
@@ -572,6 +574,23 @@ export const discoverCursorModelsViaAcp = (
|
||||
environment?: NodeJS.ProcessEnv,
|
||||
) => discoverCursorModelsViaListAvailableModels(cursorSettings, environment);
|
||||
|
||||
// Each driver instance owns its cache; version and account changes invalidate it.
|
||||
export const makeCursorModelDiscovery = Effect.fn("makeCursorModelDiscovery")(function* (
|
||||
cursorSettings: CursorSettings,
|
||||
environment?: NodeJS.ProcessEnv,
|
||||
) {
|
||||
const cache = yield* Cache.makeWith(
|
||||
(_key: string) => discoverCursorModelsViaAcp(cursorSettings, environment),
|
||||
{
|
||||
capacity: 1,
|
||||
timeToLive: (exit) =>
|
||||
Exit.isSuccess(exit) && exit.value.length > 0 ? Duration.minutes(30) : Duration.zero,
|
||||
},
|
||||
);
|
||||
return (about: Pick<CursorAboutResult, "version" | "auth">) =>
|
||||
Cache.get(cache, JSON.stringify([about.version, about.auth]));
|
||||
});
|
||||
|
||||
function getCursorFallbackModels(
|
||||
cursorSettings: Pick<CursorSettings, "customModels">,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
@@ -989,6 +1008,7 @@ const runCursorAboutCommand = (cursorSettings: CursorSettings, environment?: Nod
|
||||
export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(function* (
|
||||
cursorSettings: CursorSettings,
|
||||
environment?: NodeJS.ProcessEnv,
|
||||
discoverModels?: (about: CursorAboutResult) => ReturnType<typeof discoverCursorModelsViaAcp>,
|
||||
): Effect.fn.Return<
|
||||
ServerProviderDraft,
|
||||
never,
|
||||
@@ -1086,9 +1106,10 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
let discoveryWarning: string | undefined;
|
||||
if (parsed.auth.status !== "unauthenticated") {
|
||||
const discoveryExit = yield* Effect.exit(
|
||||
discoverCursorModelsViaAcp(cursorSettings, environment).pipe(
|
||||
Effect.timeoutOption(CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS),
|
||||
),
|
||||
(discoverModels
|
||||
? discoverModels(parsed)
|
||||
: discoverCursorModelsViaAcp(cursorSettings, environment)
|
||||
).pipe(Effect.timeoutOption(CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS)),
|
||||
);
|
||||
if (Exit.isFailure(discoveryExit)) {
|
||||
yield* Effect.logWarning("Cursor ACP model discovery failed", {
|
||||
|
||||
Reference in new issue
Block a user