From d0a84fc273a920de570bb972ff47cb2e5ad2c96f Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Sat, 7 Nov 2026 18:30:40 -0600 Subject: [PATCH] perf(core): fetch Console instructions and skills concurrently (#62672) --- packages/core/src/plugin/provider/opencode.ts | 6 ++- .../test/plugin/provider-opencode.test.ts | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/core/src/plugin/provider/opencode.ts b/packages/core/src/plugin/provider/opencode.ts index 8b371fa787d..4d109608f7f 100644 --- a/packages/core/src/plugin/provider/opencode.ts +++ b/packages/core/src/plugin/provider/opencode.ts @@ -595,8 +595,10 @@ function fetchConfig(http: HttpClient.HttpClient, value: Credential.Key | Creden }), ), ) - const instructions = yield* list("/api/v2/instructions", ConsoleInstructions) - const skills = yield* list("/api/v2/skills", ConsoleSkills) + const [instructions, skills] = yield* Effect.all( + [list("/api/v2/instructions", ConsoleInstructions), list("/api/v2/skills", ConsoleSkills)], + { concurrency: 2 }, + ) return { ...remote, instructions: instructions?.instructions ?? [], skills: skills?.skills ?? [], watches } }), ), diff --git a/packages/core/test/plugin/provider-opencode.test.ts b/packages/core/test/plugin/provider-opencode.test.ts index 850e7101cb8..1650fa4ead4 100644 --- a/packages/core/test/plugin/provider-opencode.test.ts +++ b/packages/core/test/plugin/provider-opencode.test.ts @@ -1682,6 +1682,46 @@ describe("OpencodePlugin", () => { }), ) + it.effect("requests Console instructions and skills together", () => + Effect.gen(function* () { + const credentials = yield* Credential.Service + const discovery = yield* InstructionDiscovery.Service + const requests: string[] = [] + // Instructions answer only once skills were requested, so fetching the lists one after the other never finishes. + const skillsRequested = Promise.withResolvers() + const server = { + fetch: async (request: Request) => { + const path = new URL(request.url).pathname + requests.push(path) + if (path === "/api/v2/config") return Response.json({ providers: {} }) + if (path === "/api/v2/instructions") { + await skillsRequested.promise + return Response.json({ instructions: [{ id: "style", content: "Use tabs." }] }) + } + if (path === "/api/v2/skills") { + skillsRequested.resolve() + return Response.json({ skills: [] }) + } + return new Response(null, { status: 404 }) + }, + } + yield* credentials.create({ + integrationID: Integration.ID.make("opencode"), + value: Credential.Key.make({ type: "key", key: "secret", metadata: { server: "https://console.test" } }), + }) + const activation = yield* addPlugin().pipe(inProcess(server), Effect.forkChild({ startImmediately: true })) + yield* drain + expect(requests.toSorted()).toEqual(["/api/v2/config", "/api/v2/instructions", "/api/v2/skills"]) + yield* Fiber.join(activation) + const files = yield* discovery.list() + expect( + Array.isArray(files) + ? files.filter((file) => file.path.startsWith("OpenCode Console")).map((file) => file.content) + : [], + ).toEqual(["Use tabs."]) + }), + ) + it.live("keeps credentials on a same-origin skill redirect", () => Effect.acquireUseRelease( Effect.sync(() => {