diff --git a/src/agents/model-auth.ts b/src/agents/model-auth.ts index 1f7882bb6fd..9cb23dbbf45 100644 --- a/src/agents/model-auth.ts +++ b/src/agents/model-auth.ts @@ -23,6 +23,7 @@ import { type AuthProfileStore, externalCliDiscoveryForProviderAuth, ensureAuthProfileStore, + ensureAuthProfileStoreWithoutExternalProfiles, listProfilesForProvider, resolveApiKeyForProfile, resolveAuthProfileOrder, @@ -43,7 +44,11 @@ import { } from "./model-auth-runtime-shared.js"; import { normalizeProviderId } from "./model-selection.js"; -export { ensureAuthProfileStore, resolveAuthProfileOrder } from "./auth-profiles.js"; +export { + ensureAuthProfileStore, + ensureAuthProfileStoreWithoutExternalProfiles, + resolveAuthProfileOrder, +} from "./auth-profiles.js"; export { requireApiKey, resolveAwsSdkEnvVarName } from "./model-auth-runtime-shared.js"; export type { ResolvedProviderAuth } from "./model-auth-runtime-shared.js"; export type ProviderCredentialPrecedence = "profile-first" | "env-first"; diff --git a/src/agents/pi-embedded-runner/compact.hooks.harness.ts b/src/agents/pi-embedded-runner/compact.hooks.harness.ts index 5e634d1093b..340369fed3b 100644 --- a/src/agents/pi-embedded-runner/compact.hooks.harness.ts +++ b/src/agents/pi-embedded-runner/compact.hooks.harness.ts @@ -313,6 +313,7 @@ export async function loadCompactHooksHarness(): Promise<{ vi.doMock("../model-auth.js", () => ({ applyAuthHeaderOverride: vi.fn((model: unknown) => model), applyLocalNoAuthHeaderOverride: vi.fn((model: unknown) => model), + ensureAuthProfileStoreWithoutExternalProfiles: vi.fn(() => ({})), getApiKeyForModel: vi.fn(async () => ({ apiKey: "test", mode: "env" })), resolveModelAuthMode: vi.fn(() => "env"), })); diff --git a/src/agents/pi-embedded-runner/run.overflow-compaction.harness.ts b/src/agents/pi-embedded-runner/run.overflow-compaction.harness.ts index 33bb6a9030b..363cc57f991 100644 --- a/src/agents/pi-embedded-runner/run.overflow-compaction.harness.ts +++ b/src/agents/pi-embedded-runner/run.overflow-compaction.harness.ts @@ -218,6 +218,8 @@ export const mockedGetApiKeyForModel = vi.fn( mode: "api-key" as const, }), ); +export const mockedEnsureAuthProfileStore = vi.fn(() => ({})); +export const mockedEnsureAuthProfileStoreWithoutExternalProfiles = vi.fn(() => ({})); export const mockedResolveAuthProfileOrder = vi.fn(() => [] as string[]); export const mockedShouldPreferExplicitConfigApiKeyAuth = vi.fn(() => false); @@ -386,6 +388,10 @@ export function resetRunOverflowCompactionHarnessMocks(): void { mode: "api-key", }), ); + mockedEnsureAuthProfileStore.mockReset(); + mockedEnsureAuthProfileStore.mockReturnValue({}); + mockedEnsureAuthProfileStoreWithoutExternalProfiles.mockReset(); + mockedEnsureAuthProfileStoreWithoutExternalProfiles.mockReturnValue({}); mockedResolveAuthProfileOrder.mockReset(); mockedResolveAuthProfileOrder.mockReturnValue([]); mockedShouldPreferExplicitConfigApiKeyAuth.mockReset(); @@ -500,7 +506,9 @@ export async function loadRunOverflowCompactionHarness(): Promise<{ vi.doMock("../model-auth.js", () => ({ applyAuthHeaderOverride: vi.fn((model: unknown) => model), applyLocalNoAuthHeaderOverride: vi.fn((model: unknown) => model), - ensureAuthProfileStore: vi.fn(() => ({})), + ensureAuthProfileStore: mockedEnsureAuthProfileStore, + ensureAuthProfileStoreWithoutExternalProfiles: + mockedEnsureAuthProfileStoreWithoutExternalProfiles, getApiKeyForModel: mockedGetApiKeyForModel, resolveAuthProfileOrder: mockedResolveAuthProfileOrder, shouldPreferExplicitConfigApiKeyAuth: mockedShouldPreferExplicitConfigApiKeyAuth, diff --git a/src/agents/pi-embedded-runner/run.overflow-compaction.test.ts b/src/agents/pi-embedded-runner/run.overflow-compaction.test.ts index f35363941bb..a667f811d78 100644 --- a/src/agents/pi-embedded-runner/run.overflow-compaction.test.ts +++ b/src/agents/pi-embedded-runner/run.overflow-compaction.test.ts @@ -18,6 +18,8 @@ import { mockedContextEngine, mockedDescribeFailoverError, mockedEvaluateContextWindowGuard, + mockedEnsureAuthProfileStore, + mockedEnsureAuthProfileStoreWithoutExternalProfiles, mockedGlobalHookRunner, mockedGetApiKeyForModel, mockedPickFallbackThinkingLevel, @@ -193,6 +195,21 @@ describe("runEmbeddedPiAgent overflow compaction trigger routing", () => { ); }); + it("uses the lightweight auth profile store during reply startup", async () => { + mockedRunEmbeddedAttempt.mockResolvedValueOnce(makeAttemptResult({ promptError: null })); + + await runEmbeddedPiAgent({ + ...overflowBaseRunParams, + runId: "run-lightweight-auth-store", + }); + + expect(mockedEnsureAuthProfileStore).not.toHaveBeenCalled(); + expect(mockedEnsureAuthProfileStoreWithoutExternalProfiles).toHaveBeenCalledWith( + "/tmp/agent-dir", + { allowKeychainPrompt: false }, + ); + }); + it("forwards optional attempt params and the runtime plan into one attempt call", async () => { const internalEvents: AgentInternalEvent[] = []; const forwardingCase = makeForwardingCase(internalEvents); diff --git a/src/agents/pi-embedded-runner/run.ts b/src/agents/pi-embedded-runner/run.ts index b1c8a279c72..cffa69daebc 100644 --- a/src/agents/pi-embedded-runner/run.ts +++ b/src/agents/pi-embedded-runner/run.ts @@ -33,7 +33,6 @@ import { markAuthProfileGood, markAuthProfileUsed, } from "../auth-profiles.js"; -import { externalCliDiscoveryForProviderAuth } from "../auth-profiles/external-cli-discovery.js"; import { resolveSessionKeyForRequest, resolveStoredSessionKeyForSessionId, @@ -52,7 +51,7 @@ import { shouldSwitchToLiveModel, clearLiveModelSwitchPending } from "../live-mo import { applyAuthHeaderOverride, applyLocalNoAuthHeaderOverride, - ensureAuthProfileStore, + ensureAuthProfileStoreWithoutExternalProfiles, type ResolvedProviderAuth, resolveAuthProfileOrder, shouldPreferExplicitConfigApiKeyAuth, @@ -514,12 +513,8 @@ export async function runEmbeddedPiAgent( const authStore = pluginHarnessOwnsTransport ? createEmptyAuthProfileStore() - : ensureAuthProfileStore(agentDir, { - externalCli: externalCliDiscoveryForProviderAuth({ - cfg: params.config, - provider, - preferredProfile: params.authProfileId, - }), + : ensureAuthProfileStoreWithoutExternalProfiles(agentDir, { + allowKeychainPrompt: false, }); const requestedProfileId = params.authProfileId?.trim(); const resolvePluginHarnessPreferredProfileId = (): string | undefined => { @@ -541,7 +536,7 @@ export async function runEmbeddedPiAgent( if (!harnessAuthProvider) { return undefined; } - const harnessAuthStore = ensureAuthProfileStore(agentDir, { + const harnessAuthStore = ensureAuthProfileStoreWithoutExternalProfiles(agentDir, { allowKeychainPrompt: false, }); return resolveAuthProfileOrder({