openclaw - ✅(Solved) Fix Bug: Gateway ignores baseUrl for ollama2, routes all requests to ollama port [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#61678Fetched 2026-04-08 02:56:03
View on GitHub
Comments
0
Participants
1
Timeline
9
Reactions
0
Author
Participants
Timeline (top)
referenced ×6cross-referenced ×2closed ×1

When configuring multiple Ollama providers (ollama on port 11434 and ollama2 on port 11435), the Gateway routes ALL requests to the first provider (ollama on port 11434), completely ignoring the baseUrl configured for ollama2.

Error Message

2026-04-05T18:00:15.774Z warn agent/embedded {"subsystem":"agent/embedded"} low context window: ollama2/gemma4:e2b ctx=16384 (warn<32000) source=modelsConfig 2026-04-05T18:03:49.786Z warn agent/embedded {"subsystem":"agent/embedded"} [compaction-diag] end ... provider=ollama2/gemma4:e2b ...

Root Cause

Root Cause Hypothesis

Fix Action

Workaround

Currently, the only workaround is to use the default ollama provider (port 11434) for all agents, as ollama2 configuration is effectively ignored.

PR fix notes

PR #61755: fix(ollama): resolve per-model baseUrl routing for ollama-variant providers

Description (problem / solution / changelog)

Problem

When a second Ollama-compatible provider (ollama2) is configured alongside the default ollama provider, all its models silently route to the first provider's endpoint. This happens because:

  1. createOllamaStreamFn bakes chatUrl into a closure at creation time
  2. ensureCustomApiRegistered("ollama", streamFn) registers that function globally once — subsequent providers with api: "ollama" reuse the same function with the wrong URL
  3. The createStreamFn callback in the plugin entry hardcoded ?.providers?.ollama?.baseUrl instead of using the runtime provider key

Fixes #61678.

Solution

  • Compute chatUrl per-call in createOllamaStreamFn, preferring model.baseUrl over the creation-time default (consistent with how OpenAI-compatible transports already work)
  • Fix createStreamFn to look up config?.models?.providers?.[provider]?.baseUrl using the actual runtime provider key

Tests

Added extensions/ollama/src/stream.routing.test.ts with 3 tests covering: fallback to creation-time URL, per-model URL override (the ollama2 scenario), and /v1 normalization.

All 600 existing extension-provider tests continue to pass.

Changed files

  • extensions/ollama/index.ts (modified, +52/-7)
  • extensions/ollama/src/stream.routing.test.ts (added, +93/-0)
  • extensions/ollama/src/stream.ts (modified, +65/-131)

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

Description (problem / solution / changelog)

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

Changed files

  • extensions/ollama/index.test.ts (modified, +66/-0)
  • extensions/ollama/index.ts (modified, +4/-2)
  • extensions/ollama/src/stream.ts (modified, +1/-1)

Code Example

{
  "models": {
    "providers": {
      "ollama": {
        "baseUrl": "http://127.0.0.1:11434",
        "apiKey": "ollama-local",
        "api": "ollama",
        "models": [
          { "id": "gemma4:e2b", "name": "gemma4:e2b", "contextWindow": 32000 }
        ]
      },
      "ollama2": {
        "baseUrl": "http://127.0.0.1:11435",
        "apiKey": "ollama-local",
        "api": "ollama",
        "models": [
          { "id": "gemma4:e2b", "name": "gemma4:e2b", "contextWindow": 16384 }
        ]
      }
    }
  },
  "agents": {
    "list": [
      {
        "id": "coco",
        "model": "ollama2/gemma4:e2b"
      }
    ]
  }
}

---

$ cat ~/.openclaw/agents/coco/agent/models.json | jq '.providers.ollama2.baseUrl'
"http://127.0.0.1:11435"

$ cat ~/.openclaw/openclaw.json | jq '.models.providers.ollama2.baseUrl'
"http://127.0.0.1:11435"

---

$ lsof -i :11434 -i :11435
COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ollama   6692 robin    4u  IPv4 0xb32a81fdbf6e8b21      0t0  TCP localhost:11434 (LISTEN)
ollama   6692 robin   11u  IPv4 0x...                    0t0  TCP localhost:11434->localhost:58024 (ESTABLISHED)
ollama   6692 robin   16u  IPv4 0x...                    0t0  TCP localhost:11434->localhost:58026 (ESTABLISHED)
ollama   6697 robin    4u  IPv4 0x1ffc39c301d9c01a      0t0  TCP localhost:11435 (LISTEN)  # <-- NO CONNECTIONS!
node    12325 robin   28u  IPv4 0x...                    0t0  TCP localhost:58024->localhost:11434 (ESTABLISHED)
node    12325 robin   36u  IPv4 0x...                    0t0  TCP localhost:58026->localhost:11434 (ESTABLISHED)

---

2026-04-05T18:00:15.774Z warn agent/embedded {"subsystem":"agent/embedded"} low context window: ollama2/gemma4:e2b ctx=16384 (warn<32000) source=modelsConfig
2026-04-05T18:03:49.786Z warn agent/embedded {"subsystem":"agent/embedded"} [compaction-diag] end ... provider=ollama2/gemma4:e2b ...

---

$ curl -s -X POST "http://127.0.0.1:11435/api/generate" -d '{"model":"gemma4:e2b","prompt":"hi","stream":false}'
{"model":"gemma4:e2b","created_at":"2026-04-05T...","response":"Hi! How can I help..."}  # SUCCESS

$ curl -s -X POST "http://127.0.0.1:11434/api/generate" -d '{"model":"gemma4:e2b","prompt":"hi","stream":false}'
{"model":"gemma4:e2b","created_at":"2026-04-05T...","response":"Hello..."}  # SUCCESS
RAW_BUFFERClick to expand / collapse

Bug Report: Gateway Ignores ollama2 baseUrl, Routes All Requests to ollama (11434)

Status: Not submitted yet
Date: 2026-04-06
OpenClaw Version: 2026.4.2 (d74a122)
Severity: High - Multi-provider configuration broken


Summary

When configuring multiple Ollama providers (ollama on port 11434 and ollama2 on port 11435), the Gateway routes ALL requests to the first provider (ollama on port 11434), completely ignoring the baseUrl configured for ollama2.

Environment

  • OpenClaw Version: 2026.4.2 (d74a122)
  • OS: macOS 26.3.1 (arm64), Apple M4
  • Node: v25.8.1
  • Ollama: v0.20.0 (two instances running on ports 11434 and 11435)

Configuration

{
  "models": {
    "providers": {
      "ollama": {
        "baseUrl": "http://127.0.0.1:11434",
        "apiKey": "ollama-local",
        "api": "ollama",
        "models": [
          { "id": "gemma4:e2b", "name": "gemma4:e2b", "contextWindow": 32000 }
        ]
      },
      "ollama2": {
        "baseUrl": "http://127.0.0.1:11435",
        "apiKey": "ollama-local",
        "api": "ollama",
        "models": [
          { "id": "gemma4:e2b", "name": "gemma4:e2b", "contextWindow": 16384 }
        ]
      }
    }
  },
  "agents": {
    "list": [
      {
        "id": "coco",
        "model": "ollama2/gemma4:e2b"
      }
    ]
  }
}

Expected Behavior

When coco agent makes LLM requests, they should be routed to ollama2 at http://127.0.0.1:11435.

Actual Behavior

All requests are routed to ollama at http://127.0.0.1:11434, regardless of provider configuration.

Evidence

1. Configuration Files Show Correct baseUrl

$ cat ~/.openclaw/agents/coco/agent/models.json | jq '.providers.ollama2.baseUrl'
"http://127.0.0.1:11435"

$ cat ~/.openclaw/openclaw.json | jq '.models.providers.ollama2.baseUrl'
"http://127.0.0.1:11435"

2. Network Connections Prove Bug

After Gateway restart and test message:

$ lsof -i :11434 -i :11435
COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ollama   6692 robin    4u  IPv4 0xb32a81fdbf6e8b21      0t0  TCP localhost:11434 (LISTEN)
ollama   6692 robin   11u  IPv4 0x...                    0t0  TCP localhost:11434->localhost:58024 (ESTABLISHED)
ollama   6692 robin   16u  IPv4 0x...                    0t0  TCP localhost:11434->localhost:58026 (ESTABLISHED)
ollama   6697 robin    4u  IPv4 0x1ffc39c301d9c01a      0t0  TCP localhost:11435 (LISTEN)  # <-- NO CONNECTIONS!
node    12325 robin   28u  IPv4 0x...                    0t0  TCP localhost:58024->localhost:11434 (ESTABLISHED)
node    12325 robin   36u  IPv4 0x...                    0t0  TCP localhost:58026->localhost:11434 (ESTABLISHED)

Key observation: Port 11435 has zero ESTABLISHED connections from the Gateway (node process), despite coco agent being configured to use ollama2.

3. Gateway Logs Show ollama2 Provider Usage

2026-04-05T18:00:15.774Z warn agent/embedded {"subsystem":"agent/embedded"} low context window: ollama2/gemma4:e2b ctx=16384 (warn<32000) source=modelsConfig
2026-04-05T18:03:49.786Z warn agent/embedded {"subsystem":"agent/embedded"} [compaction-diag] end ... provider=ollama2/gemma4:e2b ...

Gateway correctly identifies ollama2/gemma4:e2b as the provider, but still routes to wrong port.

4. Direct API Tests Succeed on Both Ports

$ curl -s -X POST "http://127.0.0.1:11435/api/generate" -d '{"model":"gemma4:e2b","prompt":"hi","stream":false}'
{"model":"gemma4:e2b","created_at":"2026-04-05T...","response":"Hi! How can I help..."}  # SUCCESS

$ curl -s -X POST "http://127.0.0.1:11434/api/generate" -d '{"model":"gemma4:e2b","prompt":"hi","stream":false}'
{"model":"gemma4:e2b","created_at":"2026-04-05T...","response":"Hello..."}  # SUCCESS

Both ports respond correctly when called directly.

Root Cause Hypothesis

The Gateway's HTTP client likely has a connection pool cache bug:

  1. When ollama provider is initialized first (port 11434), it creates an HTTP connection pool
  2. When ollama2 provider is initialized, it incorrectly reuses the same connection pool instead of creating a new one for port 11435
  3. All subsequent requests go through the cached connection to 11434

This explains why:

  • The configuration shows correct baseUrl: "http://127.0.0.1:11435"
  • Gateway logs show provider=ollama2/gemma4:e2b
  • But network connections only go to 11434

Workaround

Currently, the only workaround is to use the default ollama provider (port 11434) for all agents, as ollama2 configuration is effectively ignored.

Steps to Reproduce

  1. Configure two Ollama instances on different ports (e.g., 11434 and 11435)
  2. Add both as separate providers in openclaw.json
  3. Assign an agent to use ollama2/... model
  4. Send a message to that agent
  5. Observe network connections - all go to port 11434

Impact

  • Users cannot use multiple Ollama instances simultaneously
  • Workload isolation is impossible
  • Different model configurations per provider are ignored
  • Resource management (GPU allocation, rate limiting) across instances is broken

Submission Links


Related Files

  • /Users/robin/.openclaw/openclaw.json - Main configuration
  • /Users/robin/.openclaw/agents/coco/agent/models.json - Agent model config
  • /Users/robin/.openclaw/agents/coco/agent/auth-profiles.json - Auth profiles

Diagnosis Session

  • Date: 2026-04-05 to 2026-04-06
  • Channel: Telegram (@cloudai26)
  • Agents involved: cloud (diagnosis), coco (test agent)

extent analysis

TL;DR

The Gateway's HTTP client likely has a connection pool cache bug, causing it to route all requests to the first initialized Ollama provider, ignoring the baseUrl of subsequent providers.

Guidance

  1. Verify the connection pool cache: Investigate the Gateway's HTTP client implementation to confirm the presence of a connection pool cache and its behavior when multiple Ollama providers are initialized.
  2. Check for provider initialization order: Confirm that the order of provider initialization affects the routing of requests, as hypothesized in the root cause analysis.
  3. Test with a single provider: Verify that the issue is specific to multiple providers by testing with a single Ollama provider and ensuring that requests are routed correctly.
  4. Inspect HTTP client configuration: Review the HTTP client configuration to see if there are any settings that could be contributing to the cache bug, such as connection pool sizing or timeout settings.

Example

No code snippet is provided as the issue is related to the Gateway's internal implementation, and the exact code changes required to fix the bug are unclear without further investigation.

Notes

The provided workaround of using the default ollama provider for all agents is not a scalable solution, and a proper fix is necessary to support multiple Ollama instances. The root cause hypothesis is based on the information provided and may require further investigation to confirm.

Recommendation

Apply a workaround by using a separate HTTP client instance for each Ollama provider, or wait for a fix to be implemented in the Gateway's HTTP client. This will ensure that each provider has its own connection pool and requests are routed correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING