Skip to content

Commit fcd6c5b

Browse files
fix: tell a credential reissued after logout from an untouched one
The register route's credential identity now also covers the rejected flag and the logout nonce. Logout rotates the nonce, so a registration that reissues the same key, URL and expiry after a logout in another process still reloads the provider caches. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_016x3nbZU5Vb6HnSTqE7vELm
1 parent b103818 commit fcd6c5b

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎packages/opencode/src/altimate/free/client.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export interface Credentials {
5454
expiresAt?: string
5555
installSecret: string
5656
rejected?: boolean
57+
/** Rotated by every logout; lets a caller tell a re-registered credential from an untouched one. */
58+
logoutNonce?: string
5759
}
5860

5961
export type RegistrationFailureKind = "network" | "http" | "response" | "cancelled"
@@ -114,6 +116,7 @@ function credentialsFromStored(stored: FreeTierStore.Record | undefined): Creden
114116
expiresAt: stored.expiresAt,
115117
installSecret: stored.installSecret,
116118
...(stored.rejected ? { rejected: true } : {}),
119+
...(stored.logoutNonce ? { logoutNonce: stored.logoutNonce } : {}),
117120
}
118121
}
119122

‎packages/opencode/src/server/server.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,13 @@ export namespace Server {
821821
// pure disruption for zero benefit.
822822
if (outcome.ok) {
823823
const after = await FreeTier.credentials().catch(() => undefined)
824-
// Expiry is part of the identity: an expired credential loads as absent, so renewing it
825-
// with the same key and URL still changes what a provider loader sees.
824+
// Identity covers everything that decides whether a loader sees Base: an expired or
825+
// rejected credential loads as absent, and a logout elsewhere rotates the nonce, so the
826+
// same key and URL reissued after either still has to reload.
826827
const identity = (value: typeof after) =>
827-
value ? `${value.baseURL}\n${value.apiKey}\n${value.expiresAt ?? ""}` : undefined
828+
value
829+
? [value.baseURL, value.apiKey, value.expiresAt ?? "", value.rejected ? "rejected" : "", value.logoutNonce ?? ""].join("\n")
830+
: undefined
828831
const fingerprint = identity(after)
829832
const changed = identity(before) !== fingerprint
830833
// An unchanged file is not enough to skip: a startup registration that finished in the

‎packages/opencode/test/server/altimate-base-registration.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,34 @@ describe("Altimate Base registration route", () => {
205205
}
206206
})
207207

208+
test("reloads when the same credential is reissued after a logout in another process", async () => {
209+
// Logout rotates the nonce; directories opened while logged out cached no Base. A later
210+
// registration can reissue the identical key, URL and expiry, so only the nonce differs.
211+
const first = { apiKey: "sk-aba", baseURL: "https://gateway.test", installSecret: "s", logoutNonce: "n1" }
212+
const reissued = { ...first, logoutNonce: "n2" }
213+
const disposeAll = spyOn(Instance, "disposeAll")
214+
const post = () =>
215+
app().request("/altimate/base/register", {
216+
method: "POST",
217+
headers: { "content-type": "application/json" },
218+
body: JSON.stringify({}),
219+
})
220+
try {
221+
mockCredentialsSequence(first)
222+
mockRegister(async () => first)
223+
await post()
224+
expect(disposeAll).toHaveBeenCalledTimes(1)
225+
credentialsSpy?.mockRestore()
226+
registerSpy?.mockRestore()
227+
mockCredentialsSequence(reissued)
228+
mockRegister(async () => reissued)
229+
expect(await (await post()).json()).toMatchObject({ ok: true })
230+
expect(disposeAll).toHaveBeenCalledTimes(2)
231+
} finally {
232+
disposeAll.mockRestore()
233+
}
234+
})
235+
208236
test("reloads for a credential registered in the background, even if one directory already sees Base", async () => {
209237
// A startup auto-registration that finished after the server started leaves the file unchanged
210238
// across this request, while caches built earlier (another directory, or the /api registry)

0 commit comments

Comments
 (0)