Skip to content

fix(ollama): resolve per-provider baseUrl in createStreamFn#61776

Merged
steipete merged 1 commit into
openclaw:mainfrom
zozo123:fix/ollama-multi-provider-baseurl
Apr 6, 2026
Merged

fix(ollama): resolve per-provider baseUrl in createStreamFn#61776
steipete merged 1 commit into
openclaw:mainfrom
zozo123:fix/ollama-multi-provider-baseurl

Conversation

@zozo123

@zozo123 zozo123 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When multiple Ollama providers are configured (e.g. ollama and ollama2), createStreamFn hardcoded config.models.providers.ollama.baseUrl — ignoring the active provider's actual baseUrl.
  • Changed createStreamFn to use the provider parameter from ProviderCreateStreamFnContext and resolve the correct config via resolveConfiguredOllamaProviderConfig.
  • Exported resolveConfiguredOllamaProviderConfig from extensions/ollama/src/stream.ts (was already implemented but unexported).

Test plan

  • Added test: createStreamFn resolves baseUrl from the active provider id when multiple Ollama providers are configured
  • Verified backward compatibility — single-provider setups continue to work unchanged

Closes #61678

@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a real bug where createStreamFn hardcoded config.models.providers.ollama.baseUrl, causing all inference to hit the first provider's endpoint regardless of which provider was active. The fix exports the existing private helper resolveConfiguredOllamaProviderConfig and threads the provider context parameter through the lookup — minimal and correct. Two new tests cover both the multi-provider routing path and backward compatibility for the default ollama id.

Confidence Score: 5/5

Safe to merge — the fix is surgical, correctly scoped, and both code paths are tested.

The logic change is correct and well-tested. The only remaining finding is a P2 test-style suggestion about importOriginal on a broad module; it does not affect correctness or production behaviour.

No files require special attention beyond the optional mock factory improvement in extensions/ollama/index.test.ts.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/ollama/index.test.ts
Line: 33-39

Comment:
**`importOriginal` on a broad module**

Per the repo's test-performance guardrail, `importOriginal()` should be reserved for narrow modules where partial-real behaviour is genuinely required. `stream.ts` is ~767 lines with many exported functions; loading the full module graph per mock resolution adds unnecessary overhead. Consider an explicit mock factory that stubs only what's exercised in this file:

```ts
vi.mock("./src/stream.js", () => ({
  OLLAMA_NATIVE_BASE_URL: "http://127.0.0.1:11434",
  createConfiguredOllamaStreamFn: createConfiguredOllamaStreamFnMock,
  createConfiguredOllamaCompatStreamWrapper: vi.fn(),
  resolveConfiguredOllamaProviderConfig: vi.fn((p) =>
    (p.config?.models?.providers as Record<string, unknown>)?.[p.providerId ?? ""],
  ),
}));
```

Not a blocker — defer if the test file is not a hotspot.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(ollama): resolve per-provider baseUr..." | Re-trigger Greptile

Comment on lines +33 to +39
vi.mock("./src/stream.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("./src/stream.js")>();
return {
...actual,
createConfiguredOllamaStreamFn: createConfiguredOllamaStreamFnMock,
};
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 importOriginal on a broad module

Per the repo's test-performance guardrail, importOriginal() should be reserved for narrow modules where partial-real behaviour is genuinely required. stream.ts is ~767 lines with many exported functions; loading the full module graph per mock resolution adds unnecessary overhead. Consider an explicit mock factory that stubs only what's exercised in this file:

vi.mock("./src/stream.js", () => ({
  OLLAMA_NATIVE_BASE_URL: "http://127.0.0.1:11434",
  createConfiguredOllamaStreamFn: createConfiguredOllamaStreamFnMock,
  createConfiguredOllamaCompatStreamWrapper: vi.fn(),
  resolveConfiguredOllamaProviderConfig: vi.fn((p) =>
    (p.config?.models?.providers as Record<string, unknown>)?.[p.providerId ?? ""],
  ),
}));

Not a blocker — defer if the test file is not a hotspot.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/ollama/index.test.ts
Line: 33-39

Comment:
**`importOriginal` on a broad module**

Per the repo's test-performance guardrail, `importOriginal()` should be reserved for narrow modules where partial-real behaviour is genuinely required. `stream.ts` is ~767 lines with many exported functions; loading the full module graph per mock resolution adds unnecessary overhead. Consider an explicit mock factory that stubs only what's exercised in this file:

```ts
vi.mock("./src/stream.js", () => ({
  OLLAMA_NATIVE_BASE_URL: "http://127.0.0.1:11434",
  createConfiguredOllamaStreamFn: createConfiguredOllamaStreamFnMock,
  createConfiguredOllamaCompatStreamWrapper: vi.fn(),
  resolveConfiguredOllamaProviderConfig: vi.fn((p) =>
    (p.config?.models?.providers as Record<string, unknown>)?.[p.providerId ?? ""],
  ),
}));
```

Not a blocker — defer if the test file is not a hotspot.

How can I resolve this? If you propose a fix, please make it concise.

The createStreamFn callback hardcoded config.models.providers.ollama.baseUrl,
ignoring the actual provider ID from the context. When multiple Ollama providers
are configured on different ports (e.g. ollama on 11434, ollama2 on 11435), all
requests routed to the first provider's port.

Export resolveConfiguredOllamaProviderConfig from stream.ts and use it with the
ctx.provider parameter to dynamically look up the correct baseUrl per provider.

Closes openclaw#61678
@zozo123 zozo123 force-pushed the fix/ollama-multi-provider-baseurl branch from ce71b59 to baa6cfd Compare April 6, 2026 09:38
@steipete steipete merged commit 045d956 into openclaw:main Apr 6, 2026
24 of 32 checks passed
@steipete

steipete commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm test extensions/ollama/index.test.ts
  • Land commit: 20ccf00
  • Merge commit: 045d956

Thanks @zozo123!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Gateway ignores baseUrl for ollama2, routes all requests to ollama port

2 participants