Skip to content

Commit 1f24a8e

Browse files
committed
Continue compaction auth fallback after provider miss
1 parent 2063514 commit 1f24a8e

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎src/agents/pi-extensions/compaction-safeguard.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,31 @@ describe("resolveCompactionRequestAuth", () => {
19861986
});
19871987
});
19881988

1989+
it("falls through to legacy getApiKey when provider lookup misses", async () => {
1990+
const getApiKeyForProvider = vi.fn(async () => undefined);
1991+
const getApiKey = vi.fn(async () => "sk-legacy");
1992+
1993+
await expect(
1994+
resolveCompactionRequestAuth({
1995+
model: createAnthropicModelFixture({
1996+
provider: "codex-lb",
1997+
id: "gpt-5.4",
1998+
headers: { "chatgpt-account-id": "proxy_codex-lb" },
1999+
}),
2000+
modelRegistry: {
2001+
getApiKeyForProvider,
2002+
getApiKey,
2003+
} as unknown as ExtensionContext["modelRegistry"],
2004+
modelHeaders: { "chatgpt-account-id": "proxy_codex-lb" },
2005+
}),
2006+
).resolves.toEqual({
2007+
apiKey: "sk-legacy",
2008+
headers: { "chatgpt-account-id": "proxy_codex-lb" },
2009+
});
2010+
expect(getApiKeyForProvider).toHaveBeenCalledWith("codex-lb");
2011+
expect(getApiKey).toHaveBeenCalled();
2012+
});
2013+
19892014
it("throws a readable error when no supported auth method exists", async () => {
19902015
await expect(
19912016
resolveCompactionRequestAuth({

‎src/agents/pi-extensions/compaction-safeguard.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,13 @@ async function resolveCompactionRequestAuth(params: {
161161

162162
if (typeof registry.getApiKeyForProvider === "function") {
163163
const apiKey = await registry.getApiKeyForProvider(params.model.provider);
164-
if (apiKey || params.modelHeaders) {
164+
if (apiKey) {
165165
return { apiKey, headers: params.modelHeaders };
166166
}
167-
return null;
167+
}
168+
169+
if (!registry.getApiKey && params.modelHeaders) {
170+
return { headers: params.modelHeaders };
168171
}
169172

170173
if (typeof registry.getApiKey === "function") {

0 commit comments

Comments
 (0)