Skip to content

fix(openclaw): avoid gateway restart when switching models#893

Merged
btc69m979y-dotcom merged 1 commit intonetease-youdao:release/2026.03.26from
winsan-zhang:fix/avoid-gateway-restart-on-model-switch
Mar 26, 2026
Merged

fix(openclaw): avoid gateway restart when switching models#893
btc69m979y-dotcom merged 1 commit intonetease-youdao:release/2026.03.26from
winsan-zhang:fix/avoid-gateway-restart-on-model-switch

Conversation

@winsan-zhang
Copy link
Copy Markdown
Collaborator

Summary

  • Eliminate OpenClaw gateway process restarts when switching
    between 套餐模型 (lobsterai-server) and custom providers, or
    between different custom providers
  • Use per-provider env vars (LOBSTER_APIKEY_) instead of a
    single shared LOBSTER_PROVIDER_API_KEY, so all apiKeys are
    pre-injected at gateway startup
  • Model switching now only rewrites openclaw.json, which OpenClaw
    hot-reloads silently via its file-watcher — no process restart
    needed

Problem

When users switch models across provider types (e.g.,
lobsterai-server ↔ moonshot), the gateway was killed and restarted
because:

  1. collectSecretEnvVars() returned a single
    LOBSTER_PROVIDER_API_KEY set to the active provider's apiKey
  2. Switching providers changed this value → secretEnvVarsChanged =
    true
  3. Since env vars are fixed at process spawn time, a full process
    restart was forced

Key changes:

  • claudeSettings.ts: New resolveAllProviderApiKeys() — enumerates
    all enabled providers and returns their apiKeys keyed by stable
    env var suffix
  • openclawConfigSync.ts:
    • New providerApiKeyEnvVar() helper — generates
      provider-specific env var names
    • buildProviderSelection() — all 4 provider cases now use
      ${LOBSTER_APIKEY_} instead of ${LOBSTER_PROVIDER_API_KEY}
    • collectSecretEnvVars() — collects all provider apiKeys
      upfront; legacy LOBSTER_PROVIDER_API_KEY set to fixed value

Test Plan

  • Unit tests for env var naming convention and switch stability
  • Manual: switch between 套餐 and 自定义 models — verify no
    stopGateway/startGateway in logs
  • Manual: switch between different custom providers — verify no
    restart
  • Manual: send messages after switch — verify correct model and
    apiKey used
  • Manual: edit a provider's apiKey — verify gateway restarts once
    (expected)

Use per-provider env vars (LOBSTER_APIKEY_<NAME>) instead of a single
shared LOBSTER_PROVIDER_API_KEY. All configured provider apiKeys are
collected and injected at gateway startup, so switching between
providers only rewrites openclaw.json (hot-reloaded silently) without
changing env vars — eliminating the forced process restart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants