fix(core): stop applying well-known remote config after logout (#62760)

Co-authored-by: 2SinceJuly <202121119+2SinceJuly@users.noreply.github.com>
This commit is contained in:
Aiden Cline
2026-11-09 00:08:10 -06:00
committed by GitHub
Unverified
parent 8e756809a1
commit 550bf20cb8
4 changed files with 37 additions and 12 deletions
+4 -5
View File
@@ -183,11 +183,10 @@ export const layer = (options?: Options) =>
const auth = entry.manifest.auth
const credential = (yield* credentials.list(entry.integrationID)).at(-1)
const variables = auth && credential?.value.type === "key" ? { [auth.env]: credential.value.key } : undefined
// A failed refresh, including a missing credential, keeps the last resolved config so remote providers
// and allowlists do not disappear; only removing the source clears it.
const configs = yield* (
variables ? wellknown.resolve(entry, variables) : Effect.fail(new Error("No usable wellknown credential"))
).pipe(
// Logging out drops the saved remote config, so the source supplies nothing until a fresh fetch succeeds.
if (!variables) return yield* wellknown.clearCached(entry.origin).pipe(Effect.as([]))
// A failed refresh keeps the last resolved config so remote providers and allowlists do not disappear.
const configs = yield* wellknown.resolve(entry, variables).pipe(
Effect.catch((error) =>
Effect.logWarning("failed to load wellknown config", { source: entry.origin, error }).pipe(
Effect.andThen(wellknown.cached(entry.origin)),
+6 -1
View File
@@ -50,8 +50,10 @@ export interface Interface {
readonly remove: (origin: string) => Effect.Effect<void>
/** Resolves and caches the configuration for a registered source. */
readonly resolve: (entry: Entry, variables: Readonly<Record<string, string>>) => Effect.Effect<Config[], Error>
/** Returns the last configuration resolved for an origin, kept until the source is removed. */
/** Returns the last configuration resolved for an origin, kept until it is cleared or the source is removed. */
readonly cached: (origin: string) => Effect.Effect<Config[]>
/** Drops the last configuration resolved for an origin while keeping the source registered. */
readonly clearCached: (origin: string) => Effect.Effect<void>
}
export class Service extends Context.Service<Service, Interface>()("@opencode/WellKnown") {}
@@ -210,6 +212,9 @@ const layer = Layer.effect(
const value = yield* kv.get(configKey(origin))
return Schema.is(Configs)(value) ? [...value] : []
}),
clearCached: Effect.fn("WellKnown.clearCached")(function* (origin) {
yield* kv.remove(configKey(origin))
}),
})
}),
)
+26 -6
View File
@@ -574,7 +574,15 @@ describe("Config", () => {
const credentialNode = makeGlobalNode({
service: Credential.Service,
layer: Layer.mock(Credential.Service)({
list: () => Effect.succeed([]),
list: (integrationID) =>
Effect.succeed([
new Credential.Info({
id: Credential.ID.create(),
integrationID,
label: "default",
value: Credential.Key.make({ type: "key", key: "secret" }),
}),
]),
get: (id) =>
Effect.succeed(
new Credential.Info({
@@ -587,13 +595,17 @@ describe("Config", () => {
}),
deps: [],
})
const entry: WellKnown.Entry = { origin, integrationID: Integration.ID.make(origin), manifest: {} }
const entry: WellKnown.Entry = {
origin,
integrationID: Integration.ID.make(origin),
manifest: { auth: { command: ["login"], env: "TOKEN" } },
}
const wellknownNode = makeGlobalNode({
service: WellKnown.Service,
layer: Layer.mock(WellKnown.Service)({
entries: () => Effect.succeed([entry]),
snapshot: () => [entry],
cached: () =>
resolve: () =>
Effect.succeed([
{
mcp: { servers: { wiki: { type: "remote", url: "https://wiki.acme.com/mcp" } } },
@@ -936,6 +948,7 @@ describe("Config", () => {
resolve: (_entry, variables) =>
available ? Effect.succeed([{ shell: variables.TOKEN }]) : Effect.fail(new Error("expired credential")),
cached: () => Effect.succeed([]),
clearCached: () => Effect.void,
}),
),
deps: [],
@@ -971,7 +984,7 @@ describe("Config", () => {
),
)
it.live("keeps the last resolved wellknown config across failures and restarts until its source is removed", () =>
it.live("keeps the last resolved wellknown config across failures and restarts while a credential exists", () =>
withTempDir((tmp) => {
let manifestStatus = 200
let configStatus = 200
@@ -1079,7 +1092,14 @@ describe("Config", () => {
expect(requests).toBeGreaterThan(before)
key = undefined
expect(yield* warm.reload("logged-out", warm.switched)).toEqual(loaded)
expect(yield* warm.reload("logged-out", warm.switched)).toEqual(removed)
// Logging out drops the saved config, so logging back in while the remote is down supplies nothing.
key = "secret"
expect(yield* warm.reload("logged-in-unavailable", warm.switched)).toEqual(removed)
configStatus = 200
expect(yield* warm.reload("logged-in", warm.switched)).toEqual(loaded)
configStatus = 503
manifestStatus = 503
const updated = yield* warm.bus
@@ -1090,7 +1110,6 @@ describe("Config", () => {
expect(updated.pollUnsafe()).toBeUndefined()
}).pipe(Effect.scoped, Effect.provide(instance()))
key = "secret"
yield* Effect.gen(function* () {
const cold = yield* services
expect(remote(yield* cold.config.entries())).toEqual(loaded)
@@ -1167,6 +1186,7 @@ describe("Config", () => {
// Exercise the loader boundary against a malformed implementation response.
resolve: () => Effect.succeed([null as unknown as WellKnown.Config]),
cached: () => Effect.succeed([]),
clearCached: () => Effect.void,
}),
),
deps: [],
@@ -33,6 +33,7 @@ export const emptyWellknownNode = makeGlobalNode({
remove: () => Effect.die("unused Wellknown.remove"),
resolve: () => Effect.die("unused Wellknown.resolve"),
cached: () => Effect.succeed([]),
clearCached: () => Effect.void,
}),
),
deps: [],