mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
In sessions created by `createAgentSession`, compaction, branch summaries and bug-report summaries resolved the stored OAuth credential in `AgentSession._getSummarizationRequestAuth`, then passed the access token on as `options.apiKey`. The SDK's stream function calls `modelRuntime.streamSimple`, which resolves auth again. Because it was given an explicit `apiKey`, `resolveProviderAuth` took the API-key override branch instead of using stored OAuth. Built-in providers accept the token either way. A provider whose API-key path differs from its OAuth path, such as one that refuses explicit keys, failed every summary while normal prompts worked. `createAgentSession` now marks its stream function with `markRuntimeStreamFunction`. This records it in a module-level `WeakMap` keyed by the function, mapped to its `ModelRuntime`. `_getSummarizationRequestAuth` skips pre-resolution when the agent's stream function is marked for the session's own runtime, so that runtime resolves auth once, as it does for normal prompts. The check runs after virtual-model routing. Bare `streamSimple` and custom `streamFn`s still receive resolved credentials, so the fixes for #6324 and #7579 are unchanged. If a caller replaces `agent.streamFunction`, the old behavior applies. **Testing** - Added `test/suite/regressions/11520-sdk-summary-oauth-auth.test.ts`. It builds an SDK session on a provider that has stored OAuth and also an API-key method, runs a branch summary, and asserts two things: no `getAuth` call carries an `apiKey` override, and the provider receives the OAuth access token. It fails without the change and passes with it. - `npm run check` passes and `./test.sh` passes. I also ran the related tests: 6324 branch-summary auth, compaction model overrides, auto-compaction cancellation, SDK stream options, virtual models, and the compaction and branch-summary tests. - Manual reproduction: an SDK script with an `openai` OAuth credential that logs `ModelRuntime.getAuth` during `navigateTree(..., { summarize: true })`. Before the change there were two calls, the second with `apiKey = <oauth token>`. After the change there is one call, with no override. Fixes #11520 Requested by @badlogic Co-authored-by: triagent <triagent@localhost> |
||
|---|---|---|
| .. | ||
| regressions | ||
| agent-session-bash-persistence.test.ts | ||
| agent-session-boundaries.test.ts | ||
| agent-session-codemode.test.ts | ||
| agent-session-compaction-model-overrides.test.ts | ||
| agent-session-compaction.test.ts | ||
| agent-session-mcp-oauth.test.ts | ||
| agent-session-mcp.test.ts | ||
| agent-session-model-extension.test.ts | ||
| agent-session-prompt.test.ts | ||
| agent-session-queue.test.ts | ||
| agent-session-retry-events.test.ts | ||
| agent-session-runtime.test.ts | ||
| agent-session-tool-orchestration.test.ts | ||
| agent-session-tool-result-images.test.ts | ||
| harness.ts | ||
| lax-message-content.test.ts | ||
| mcp-oauth-server.ts | ||
| README.md | ||
| virtual-models.test.ts | ||
Coding agent suite tests
Use test/suite/ for the new harness-based test suite around AgentSession and AgentSessionRuntime.
Rules:
- Use
test/suite/harness.ts - Use the faux provider from
packages/ai/src/providers/faux.ts - Do not use real provider APIs, real API keys, network calls, or paid tokens
- Keep these tests CI-safe and deterministic
- Do not use or extend the legacy
test/test-harness.tspath unless a missing capability forces it