← Back to PRs

#20665: fix(ollama): register API provider for completeSimple/compaction

by BrokenFinger98 open 2026-02-19 05:59 View on GitHub →
agents size: S
## Summary - Register `"ollama"` in the SDK's **global API provider registry** via `registerApiProvider()`, so that `completeSimple()` (used by `session.compact()`) can resolve the Ollama API type - Adds `ensureOllamaApiRegistered()` to `ollama-stream.ts` — idempotent, called from both `compact.ts` and `attempt.ts` - Fixes "No API provider registered for api: ollama" error during compaction with Ollama models ## Root Cause The initial analysis (commit `5e4d7fb`) was incomplete. Overriding `session.agent.streamFn` only covers the SDK's **agent run loop**. However, `session.compact()` internally calls: ``` session.compact() → SDK compact() → completeSimple() → resolveApiProvider(model.api) ``` `completeSimple()` resolves providers through a **global API registry** (`apiProviderRegistry` Map), NOT through `streamFn`. Since `"ollama"` is not a built-in API type in `@mariozechner/pi-ai`, the registry lookup fails with the reported error. ## Fix 1. **`ollama-stream.ts`**: Added `ensureOllamaApiRegistered()` that calls `registerApiProvider()` to register `"ollama"` in the SDK's global API provider registry. Uses `model.baseUrl` at call time for flexibility. Idempotent — safe to call multiple times. 2. **`compact.ts`**: Call `ensureOllamaApiRegistered()` before `session.compact()` so `completeSimple()` can find the `"ollama"` provider. 3. **`attempt.ts`**: Call `ensureOllamaApiRegistered()` alongside the existing `streamFn` override, ensuring both the agent run loop AND any internal `completeSimple()` calls (e.g., branch summarization) work correctly. ## Changes | File | Change | |------|--------| | `src/agents/ollama-stream.ts` | Add `ensureOllamaApiRegistered()` using `registerApiProvider()` | | `src/agents/pi-embedded-runner/compact.ts` | Call `ensureOllamaApiRegistered()` in compaction path | | `src/agents/pi-embedded-runner/run/attempt.ts` | Call `ensureOllamaApiRegistered()` in run path | ## Test plan - [x] Existing `ollama-stream.test.ts` passes (16 tests) - [x] oxfmt formatting check passes - [x] oxlint check passes (0 warnings, 0 errors) - [x] Manual verification: Ollama model compaction works correctly after fix Closes #20652

Most Similar PRs