#20665: fix(ollama): register API provider for completeSimple/compaction
agents
size: S
Cluster:
Model Input and Streaming Fixes
## 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
#20705: fix(ollama): cover remaining completeSimple gaps and add transcript...
by BrokenFinger98 · 2026-02-19
77.8%
#5783: fix(ollama): add streamToolCalls fallback for tool calling
by deepmehta11 · 2026-01-31
74.1%
#21977: Preserve provider API for discovered Ollama models
by graysurf · 2026-02-20
69.1%
#19612: feat(onboarding): add Ollama to onboarding provider list
by ParthSareen · 2026-02-18
68.9%
#23776: feat(ollama): auto-register Ollama provider with placeholder key an...
by jayy-77 · 2026-02-22
65.2%
#18587: fix(ollama): improve timeout handling and cooldown logic for local ...
by manthis · 2026-02-16
65.2%
#7278: feat(ollama): optimize local LLM support with auto-discovery and ti...
by alltomatos · 2026-02-02
65.1%
#4782: fix: Auto-discover Ollama models without requiring explicit API key
by spiceoogway · 2026-01-30
65.0%
#16098: fix: omit tools param for models without tool support, surface erro...
by claw-sylphx · 2026-02-14
64.9%
#5115: fix: guard against undefined model.name in Ollama discovery (#5062)
by TheWildHustle · 2026-01-31
63.7%