Skip to content

fix(local-ai): avoid stale OpenAI primary after provider hot reload #1293

Closed as not planned

Description

@joelagnel

Summary

Immediately after Local AI setup hot-reloads agents.defaults.model.primary and models.providers.llamacpp, the embedded agent can still dispatch one or more requests through the stale openai/gpt-5.6-sol primary. On a Local AI-only installation with no OpenAI credential, the first prompt fails with missing-provider-auth even though the llama.cpp provider configuration was just applied.

This is separate from #1282. That PR removes stale setup-managed gateway records; it does not synchronize gateway provider reload with embedded-agent dispatch.

Environment

  • Windows 11 ARM64 on RTX Spark hardware
  • Windows integration branch integration/local-ai-2026-09-02, head 38a172f1
  • Gateway OpenClaw 2026.6.34 (5c38f99) in the managed OpenClawGateway WSL distro
  • Managed Local AI model: Qwen3.8 27B through the llamacpp provider

Reproduction

  1. Run managed Local AI setup from a clean/isolated Windows app state.
  2. Complete model/provider configuration.
  3. Send the first embedded-agent prompt immediately after setup reports completion and the gateway reports the provider/model hot reload as applied.

Actual behavior

The gateway log shows the new Local AI configuration applied, followed about one second later by a request using the stale OpenAI primary:

2026-09-02T16:59:32.323Z config change detected (agents.defaults.model.primary, models.providers.llamacpp)
2026-09-02T16:59:33.144Z config hot reload applied (agents.defaults.model.primary, models.providers.llamacpp)
2026-09-02T16:59:34.174Z ProviderAuthError: No API key found for provider "openai"
2026-09-02T16:59:34.186Z requestedProvider="openai" requestedModel="gpt-5.6-sol" code="missing-provider-auth"

After the provider/model configuration is applied again and the gateway settles, the same installation routes correctly:

2026-09-02T17:03:55.625Z provider=llamacpp model=qwen3.8-27b-mtp-ud-q4-k-m POST /v1/chat/completions
2026-09-02T17:04:36.148Z provider=llamacpp status=200

The user-visible failure is:

Agent failed before reply: No API key found for provider "openai" ... | missing-provider-auth

No OpenAI provider is intended or required for this Local AI-only setup.

Expected behavior

Once the grouped provider/model reload reports success, every newly dispatched embedded-agent request should resolve the new llamacpp primary. A request must not observe stale model/provider state or tell the user to configure an unrelated OpenAI credential.

Suggested acceptance criteria

  • Apply the provider registration and default-model switch atomically from the embedded agent's point of view.
  • Gate or retry first dispatch while provider/model state is reloading instead of falling through to stale auth state.
  • Add a deterministic test that pauses reload between config persistence, provider registration, agent model resolution, and first dispatch.
  • Add current-head proof for setup completion followed immediately by a successful first Local AI prompt without a manual gateway restart or second config write.

Diagnostics

  • The setup log setup-engine-20260902-164018.jsonl records a separate pre-cleanup recipe-mismatch failure and is not the source of this provider-auth error.
  • The relevant evidence is in gateway logs around 2026-09-02T16:59:32Z through 17:04:36Z.
  • Identifiers and tokens are intentionally omitted from the excerpts above.

Activity

  1. added
    P1
    clawsweeper:bulk-filed
    clawsweeper:needs-maintainer-review
    clawsweeper:no-new-fix-pr
    impact:auth-provider
    issue-rating: 🦪 silver shellfish
    on Sep 2, 2026
  2. clawsweeper commented on Sep 2, 2026

    @clawsweeper

    ClawSweeper status: review started.

    I am starting a fresh review of this issue: fix(local-ai): avoid stale OpenAI primary after provider hot reload This is item 1/1 in the current shard. Shard 0/1.

    This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

    Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

  3. larroy commented on Sep 4, 2026

    @larroy
    Collaborator

    Reproduced on Windows 11 x64 / RTX 5090 with the same model (Qwen3.8 27B UD-Q4_K_M via llamacpp), gateway 2026.6.34. I dug into it and I think the diagnosis in the issue body is slightly off in a way that matters for the fix: this is not a stale-reload/dispatch race inside the gateway. The companion deliberately unsets the Local AI config and leaves it unset for ~10 seconds.

    What actually happens

    ~/.openclaw/logs/config-audit.jsonl in the managed distro shows three writes on tray startup:

    Time (UTC) Command the companion ran
    01:26:12.432 openclaw config unset agents.defaults.model.primary
    01:26:13.579 openclaw config unset models.providers.llamacpp
    01:26:22.662 openclaw config set --batch-file /dev/stdin (re-publishes provider + primary)

    My first prompt landed at 18:26:15 local — inside that ~9s hole. Gateway journal:

    18:26:14.627 [reload] config hot reload applied (agents.defaults.model.primary, models.providers.llamacpp)
    18:26:15.607 [model-fallback/decision] decision=candidate_failed
                 requested=openai/gpt-5.6-sol candidate=openai/gpt-5.6-sol reason=auth next=none
    18:26:15.614 Embedded agent failed before reply: No API key found for provider "openai" | missing-provider-auth
    18:26:23.281 [reload] config hot reload applied (agents.defaults.model.primary, models.providers.llamacpp)
    

    So the reload at 18:26:14 was correct — it correctly applied the unset. With agents.defaults.model.primary absent, the gateway resolves its built-in default openai/gpt-5.6-sol, which has no credential. Nothing is stale and no dispatch observed torn state; the gateway did exactly what the config told it to. Once the batch write lands at 18:26:22 the same install routes cleanly (provider=llamacpp ... status=200 elapsedMs=3987 at 18:28:36).

    Why the window exists

    LlamaServerRuntimeService.EnsureStartedCoreAsync (src/OpenClaw.Connection/LocalAi/LlamaServerRuntimeService.cs:168) sequences quiesce → start → probe → publish:

    1. QuiesceAsync unsets models.providers.llamacpp, and because manifest.GatewayFallbackModel is null it unsets agents.defaults.model.primary outright (LocalAiGatewayProviderCoordinator.cs:75-90).
    2. llama-server starts and is probed. This takes seconds — the manifest has "requestedPort": 0, so the endpoint port is OS-assigned on every run and the previously published baseUrl is stale by construction.
    3. PublishAsync restores provider + primary only after the probe succeeds.

    StartLocalAiRouterInBackground (src/OpenClaw.Tray.WinUI/App.xaml.cs:966) is intentionally fire-and-forget so it can't delay tray startup, so the chat window is live and accepting sends for the whole window. That is why it reproduces every time: send anything within ~10s of app start.

    Worth noting this reproduces on plain app start, not just immediately after setup — the quiesce/publish cycle runs on every launch.

    Implication for the acceptance criteria

    The listed criteria target gateway-side reload/dispatch synchronization, which I don't think is where the defect is. Suggested reframing:

    • Never unset agents.defaults.model.primary while Local AI is the selected route. Unsetting is what hands routing to the built-in OpenAI default. Keeping it pointed at llamacpp/<alias> across the cycle turns the failure into a local transport error instead of a foreign-provider auth error.
    • Make the normal restart path a no-op instead of teardown/rebuild. Persist the bound port and reuse it (still honouring an explicit requestedPort); with a stable endpoint the previous run's published config is already valid, so EnsureStartedCoreAsync can skip QuiesceAsync entirely when the live config already matches the managed definition. PublishAsync already returns Ok on an exact match (LocalAiGatewayProviderCoordinator.cs:118-127).
    • Keep quiesce only for paths that genuinely change the endpoint (port conflict, failed publish, stop/uninstall), and make it a single atomic config set --batch-file rather than unset-now / set-later.
    • Gate first send on readiness. _localAiRuntime is already in the DI context (App.xaml.cs:469); surfacing LocalAiRuntimeSnapshot.State to the composer covers the residual cold-start seconds.

    Useful regression test: assert that across a full restart cycle, no observed gateway config state has the primary model unset. That fails today and is independent of any gateway-side timing.

    Separately (not the cause here, but relevant to first-prompt latency): the generated preset sets load-on-startup = false, so the first real request also pays model load — ~4s in my run, well inside the provider's timeoutSeconds: 300.

    Tokens, session keys and identifiers omitted from all excerpts above.

  4. added this to the 9/30 MXC Release milestone on Sep 4, 2026
  5. github-actions commented on Sep 19, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale due to inactivity.
    Please add updated OpenClaw Windows details or it will be closed.

  6. github-actions commented on Sep 26, 2026

    @github-actions
    Contributor

    Closing due to inactivity.
    If this still affects OpenClaw Windows, open a new issue with the current version, logs, and fresh reproduction details.

  7. locked as resolved and limited conversation to collaborators on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clawsweeper:bulk-filedclawsweeper:needs-maintainer-reviewclawsweeper:no-new-fix-primpact:auth-providerissue-rating: 🦪 silver shellfishstale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions