Skip to content

Cron jobs fail with custom Ollama providers: No API provider registered for api: ollama #57811

@Dhinc1

Description

@Dhinc1

Description

Cron jobs assigned to agents using custom Ollama providers (configured via models.providers with "api": "ollama") fail with:

No API provider registered for api: ollama

The error originates from @mariozechner/pi-ai's resolveApiProvider() in stream.js, which checks the apiProviderRegistry for a registered ollama API handler.

Root Cause

The ollama API provider is registered lazily via ensureCustomApiRegistered()registerProviderStreamForModel()resolveProviderStreamFn(). This registration only happens during model preparation (prepareModelForSimpleCompletion).

In the cron execution path (src/cron/isolated-agent/run.ts), the model is resolved via resolveCronModelSelection() and passed directly to runEmbeddedPiAgent()without calling the model preparation step that triggers lazy registration. The embedded agent then calls pi-ai's stream(), which throws because the ollama API was never registered.

Built-in providers (Anthropic, OpenAI, Google, etc.) work fine because they are registered eagerly at module load via registerBuiltInApiProviders() in pi-ai/dist/providers/register-builtins.js.

Reproduction

  1. Configure a custom Ollama provider:
"models": {
  "providers": {
    "ollama-spark": {
      "baseUrl": "http://10.x.x.x:11434",
      "api": "ollama",
      "models": [{ "id": "nemotron-3-super:120b", "name": "Nemotron" }]
    }
  }
}
  1. Set an agent's primary model to ollama-spark/nemotron-3-super:120b
  2. Create a cron job assigned to that agent with sessionTarget: "isolated"
  3. Run the cron job: openclaw cron run <id>
  4. Result: No API provider registered for api: ollama

Interactive sessions with the same agent and model work fine.

Additional Issue

Even when payload.model is explicitly set on the cron job (via --model), the agent's config-level model (agents.list.<agent>.model.primary) still takes precedence in the embedded agent bootstrap, causing LiveSessionModelSwitchError if they differ. The cron --model override should be authoritative.

Workaround

Reconfigure the custom Ollama provider to use "api": "openai-completions" with "baseUrl": "http://host:11434/v1" (Ollama's OpenAI-compatible endpoint). This uses a built-in transport that is registered eagerly and works in cron context.

Suggested Fix

Either:

  1. Call registerProviderStreamForModel() for all configured custom providers during gateway startup (before cron starts)
  2. Add ollama to the built-in provider registry in pi-ai
  3. Ensure the cron execution path calls the model preparation step before invoking the embedded agent

Environment

  • OpenClaw version: 2026.3.28 (stable)
  • OS: macOS 26.3.1 (arm64)
  • Node: 22.22.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions