Skip to content

Instantly share code, notes, and snippets.

@TakashiSasaki
Last active June 15, 2026 06:42
Show Gist options
  • Select an option

  • Save TakashiSasaki/bcdcafa0d6d97a3f956cabd30cb6e2e7 to your computer and use it in GitHub Desktop.

Select an option

Save TakashiSasaki/bcdcafa0d6d97a3f956cabd30cb6e2e7 to your computer and use it in GitHub Desktop.
OpenClawでGemma 4 31Bをメインに使うときの設定
{
"agents": {
"defaults": {
"workspace": "C:\\Users\\<USER_NAME>\\.openclaw\\workspace",
"model": {
"primary": "google/gemma-4-31b-it",
"fallbacks": [
"google/gemma-4-26b-a4b-it",
"google/gemini-2.5-flash",
"google/gemini-3.1-flash-lite",
"google/gemini-2.5-pro",
"google/gemini-2.5-flash-lite",
"google/gemini-3-flash-preview"
]
},
"bootstrapMaxChars": 12000,
"bootstrapTotalMaxChars": 60000,
"contextInjection": "continuation-skip",
"bootstrapPromptTruncationWarning": "once",
"heartbeat": {
"every": "10m",
"target": "last",
"directPolicy": "allow"
},
"contextLimits": {
"memoryGetMaxChars": 8000,
"memoryGetDefaultLines": 80,
"toolResultMaxChars": 16000,
"postCompactionMaxChars": 1200
},
"contextTokens": 240000,
"compaction": {
"mode": "safeguard",
"reserveTokens": 25000,
"reserveTokensFloor": 25000,
"keepRecentTokens": 40000,
"midTurnPrecheck": {
"enabled": true
},
"truncateAfterCompaction": true,
"maxActiveTranscriptBytes": "25mb",
"notifyUser": true,
"identifierPolicy": "strict",
"qualityGuard": {
"enabled": true,
"maxRetries": 1
},
"postCompactionSections": [
"Session Startup",
"Red Lines"
]
}
}
},
"gateway": {
"mode": "local",
"auth": {
"mode": "token",
"token": "********"
},
"port": 18789,
"bind": "loopback",
"tailscale": {
"mode": "off",
"resetOnExit": false
},
"controlUi": {
"allowInsecureAuth": true
},
"nodes": {
"denyCommands": [
"camera.snap",
"camera.clip",
"screen.record",
"contacts.add",
"calendar.add",
"reminders.add",
"sms.send",
"sms.search"
]
}
},
"session": {
"dmScope": "per-channel-peer"
},
"tools": {
"profile": "coding",
"web": {
"search": {
"provider": "parallel-free",
"enabled": true
}
}
},
"plugins": {
"entries": {
"google": {
"enabled": true
},
"telegram": {
"enabled": true
},
"parallel": {
"enabled": true
}
}
},
"auth": {
"profiles": {
"google:default": {
"provider": "google",
"mode": "api_key"
}
}
},
"channels": {
"telegram": {
"enabled": true,
"groups": {
"*": {
"requireMention": true
}
},
"botToken": "********"
}
},
"hooks": {
"internal": {
"enabled": true,
"entries": {
"compaction-notifier": {
"enabled": true
},
"command-logger": {
"enabled": true
},
"session-memory": {
"enabled": true
}
}
}
},
"wizard": {
"lastRunAt": "2026-06-12T02:26:03.585Z",
"lastRunVersion": "2026.6.5",
"lastRunCommand": "onboard",
"lastRunMode": "local"
},
"meta": {
"lastTouchedVersion": "2026.6.5",
"lastTouchedAt": "2026-06-12T02:31:51.629Z"
},
"commands": {
"ownerAllowFrom": [
"telegram:********"
]
}
}

OpenClaw Gateway 応答遅延改善メモ

概要

OpenClaw 2026.6.6 の Gateway 常駐運用において、WebChat / Telegram から短いメッセージを送っても応答開始まで非常に時間がかかる問題があった。

当初は、短文入力でも model-resolution に 35〜40 秒程度かかるケースがあり、実際の LLM API 呼び出しよりも、OpenClaw 内部のモデル解決・認証・プラグイン初期化まわりがボトルネックになっていた。

その後、未使用プラグインの無効化、フックの整理、モデル fallback の単純化を行った結果、短文応答の総処理時間はおおむね 5〜6 秒程度まで改善した。

最終的な主要ボトルネックは、Google/Gemma API ではなく、OpenClaw 内部の model-resolution に残る約 2.6 秒の固定コストである。

環境

OpenClaw version:

OpenClaw 2026.6.6 (8c802aa)

OS / shell:

Windows / PowerShell

主な利用チャネル:

WebChat / Dashboard
Telegram

主モデル:

google/gemma-4-31b-it

認証状態:

openclaw models auth list

Agent: main
Auth state store: ~\.openclaw\agents\main\agent\openclaw-agent.sqlite
Profiles:
- google:default [google/api_key]

Google provider では google/gemma-4-31b-it が認識されており、実際の model-fetch も Google Generative AI API の streamGenerateContent に到達していた。

初期症状

短い入力でも、応答開始前に非常に長い待ち時間が発生していた。

代表的な trace では、startup stages のうち model-resolution が 35〜40 秒程度を占めていた。

典型的な構造は以下。

startup stages:
  workspace: 数 ms
  runtime-plugins: 数 ms
  hooks: 数 ms
  model-resolution: 35000〜40000ms
  auth: 数十 ms
  context-engine: 数 ms

この時点で重要だったのは、実際の Google API 呼び出し自体は比較的速かったこと。

[model-fetch] start provider=google model=gemma-4-31b-it
[model-fetch] response provider=google model=gemma-4-31b-it status=200 elapsedMs=1300〜数秒程度

つまり、遅延の主因は Gemma 4 31B の生成速度ではなく、OpenClaw がモデル呼び出しに入る前の内部処理だった。

調査で見えた問題

1. plugin prewarm / provider plugin loading が重い

起動時または hot reload 時に多数の provider plugin が読み込まれていた。

例:

[plugins] loading anthropic ...
[plugins] loading openai ...
[plugins] loading opencode ...
[plugins] loading openrouter ...
...
[plugins] loaded 47 plugin(s) ... in 5739.1ms

さらに、初期状態では以下のような非常に重い prewarm が出ていた。

post-ready.agent-runtime-plugins:90512ms
provider auth state pre-warmed in 93502ms

このため、Gateway 起動後や config hot reload 後に、OpenClaw の main event loop が長時間ブロックされるような状態になっていた。

2. OpenAI の外部 CLI OAuth bootstrap が発生していた

Google/Gemma を主モデルにしているにもかかわらず、ログに以下が出ていた。

[agents/auth-profiles] used external cli oauth bootstrap because local oauth was missing or unusable

trace では、具体的に以下のように openai:default が示された。

{
  "profileId": "openai:default",
  "provider": "openai",
  "externalExpires": 1781671454000
}
used external cli oauth bootstrap because local oauth was missing or unusable

ただし、openclaw models auth list では保存済み profile は google:default [google/api_key] のみだった。

このことから、OpenAI OAuth profile が main agent の auth store に保存されているわけではなく、provider prewarm / catalog / status / reload などの処理で、外部 CLI 認証情報を runtime 的に見に行っている可能性が高いと判断した。

3. disabled plugin でも registry / catalog 用に読み込まれることがある

openclaw plugins disable <name> で無効化しても、ログ上は extension module が loading ... と表示される場合がある。

これは、無効化された plugin が通常 runtime surface から外れることと、OpenClaw が plugin registry / model catalog / metadata inspection のために module を読み込むことが別だからと考えられる。

したがって、disable は「完全にファイル import されない」ことを意味しない。

実用上は、以下を区別する必要がある。

plugin が registry/catalog inspection のために読み込まれる
plugin が enabled plugin として runtime surface に参加する
plugin が実際の model call / tool call / hook に使われる

実施した改善

1. 未使用 provider plugin の無効化

Google/Gemma を主用途とするため、不要な hosted model provider、Copilot 系、OpenAI / Anthropic 系、OpenRouter 系、ローカル provider 系を無効化対象にした。

代表的な無効化対象:

openclaw plugins disable openai
openclaw plugins disable anthropic
openclaw plugins disable opencode
openclaw plugins disable opencode-go
openclaw plugins disable openrouter
openclaw plugins disable github-copilot
openclaw plugins disable copilot-proxy
openclaw plugins disable runway

その他、利用予定のない provider plugin も無効化した。

openclaw plugins disable arcee
openclaw plugins disable byteplus
openclaw plugins disable cerebras
openclaw plugins disable chutes
openclaw plugins disable cloudflare-ai-gateway
openclaw plugins disable deepinfra
openclaw plugins disable deepseek
openclaw plugins disable fal
openclaw plugins disable fireworks
openclaw plugins disable gmi
openclaw plugins disable groq
openclaw plugins disable huggingface
openclaw plugins disable kilocode
openclaw plugins disable kimi
openclaw plugins disable litellm
openclaw plugins disable lmstudio
openclaw plugins disable microsoft-foundry
openclaw plugins disable minimax
openclaw plugins disable mistral
openclaw plugins disable moonshot
openclaw plugins disable novita
openclaw plugins disable nvidia
openclaw plugins disable ollama
openclaw plugins disable qianfan
openclaw plugins disable qwen
openclaw plugins disable sglang
openclaw plugins disable stepfun
openclaw plugins disable synthetic
openclaw plugins disable tencent
openclaw plugins disable together
openclaw plugins disable venice
openclaw plugins disable vercel-ai-gateway
openclaw plugins disable vllm
openclaw plugins disable volcengine
openclaw plugins disable vydra
openclaw plugins disable xai
openclaw plugins disable xiaomi
openclaw plugins disable zai

実際に残す候補は、用途に応じて次のように整理した。

最小構成:

google
telegram
workboard
memory-core

Dashboard / ファイル転送 / ブラウザ操作も使う場合:

browser
canvas
device-pair
document-extract
file-transfer
google
memory-core
telegram
web-readability
workboard

音声やスマホ操作を使わない場合は、以下は無効化候補。

openclaw plugins disable phone-control
openclaw plugins disable talk-voice

2. config hot reload の連発を避ける

Gateway 起動中に openclaw plugins disable ... を1つずつ実行すると、そのたびに config hot reload が走る。

例:

config change detected; evaluating reload
config hot reload applied

このたびに prewarm や auth bootstrap が走る可能性があるため、まとめて変更する場合は Gateway を停止してから行うのが望ましい。

openclaw gateway stop

# plugins disable / enable をまとめて実行

openclaw gateway start

または、最後に必ず再起動する。

openclaw gateway restart

3. fallback を単一 Google/Gemma に整理

モデル設定を最小化した。

{
  "primary": "google/gemma-4-31b-it",
  "fallbacks": [
    "google/gemma-4-31b-it"
  ]
}

これにより、fallback 解決時に OpenAI / Anthropic / OpenRouter / Copilot などの他 provider を探索する余地を潰した。

ただし、この設定では google/gemma-4-31b-it が一時的に 500 error を返した場合、別モデルへ逃げることはできない。可用性重視なら、以下のように Google provider 内の Gemini Flash 系を fallback に入れる案もある。

{
  "primary": "google/gemma-4-31b-it",
  "fallbacks": [
    "google/gemini-2.5-flash",
    "google/gemini-2.5-flash-lite"
  ]
}

ただし、fallback を増やすと model-resolution の探索範囲が増える可能性があるため、性能検証中は単一モデル構成の方が切り分けやすい。

4. hooks の確認と整理

以下で hook 一覧を確認した。

openclaw hooks list

確認された hooks:

boot-md
bootstrap-extra-files
command-logger
compaction-notifier
session-memory

これらはすべて ready だった。

通常応答時には以下のログが出ていた。

[plugins] [hooks] running before_agent_reply (1 handlers, first-claim wins)

ただし trace では、startup stages 内の hooks は 0ms だった。

startup stages:
  runtime-plugins:2ms
  hooks:0ms
  model-resolution:2666ms

したがって、今回の残存遅延の主因は hook ではなかった。

改善後のログ

改善後、短い「こんにちは」入力では以下のようなログになった。

message received
...
embedded run start provider=google model=gemma-4-31b-it
...
model-fetch start provider=google model=gemma-4-31b-it
model-fetch response status=200 elapsedMs=1902
...
embedded run done durationMs=5194
message processed duration=5866ms

別の実行でも、全体は約 5.6 秒だった。

message processed ... duration=5635ms

この時点で、最初に問題だった 35〜40 秒級の応答遅延は解消した。

改善後に残ったボトルネック

trace で見ると、残りの主な固定コストは model-resolution だった。

startup stages:
  totalMs=2721
  workspace:0ms
  runtime-plugins:2ms
  hooks:0ms
  model-resolution:2666ms
  auth:47ms
  context-engine:0ms
  attempt-workspace:4ms
  attempt-prompt:0ms
  attempt-runtime-plan:2ms
  attempt-dispatch:0ms

別実行でも同様。

startup stages:
  totalMs=2719
  workspace:0ms
  runtime-plugins:2ms
  hooks:0ms
  model-resolution:2631ms
  auth:51ms
  context-engine:1ms
  attempt-workspace:32ms
  attempt-runtime-plan:2ms

このため、改善後の内訳は概ね以下。

model-resolution: 約2.6秒
auth: 約50ms
core-plugin-tools: 約100〜140ms
Google/Gemma model-fetch: 約1.4〜1.9秒
全体: 約5〜6秒

core-plugin-tools は以下の程度で、主因ではなかった。

core-plugin-tools totalMs=107〜141ms
plugin-tools:44〜70ms
authorization-policy:12ms
schema-normalization:3〜6ms

Google/Gemma API の一時エラー

改善後、以下のような 500 error が発生することがあった。

[model-fetch] response provider=google api=google-generative-ai model=gemma-4-31b-it status=500 elapsedMs=942 contentType=text/event-stream

error=LLM request failed.
rawError=Google Generative AI API error (500): Internal error encountered. [code=INTERNAL]

これは OpenClaw の model-resolution 問題ではなく、Google Generative AI API 側が 500 Internal error を返したもの。

認証エラーなら 401 / 403、クォータなら 429、モデル名不正なら 404 系になるため、この 500 は上流 API または当該モデル提供基盤側の一時的失敗と判断する。

頻度確認:

Select-String -Path "$env:LOCALAPPDATA\Temp\openclaw\openclaw-*.log" `
  -Pattern "status=500|code=INTERNAL|LLM request failed" |
  Select-Object -Last 30

単発なら再送でよい。頻発する場合は、一時的に google/gemini-2.5-flash などへ切り替えるか、fallback に入れる。

調査に使ったコマンド

OpenClaw version

openclaw --version

Gateway restart

openclaw gateway restart

深い状態確認

openclaw status --deep
openclaw doctor
openclaw doctor --fix

Google provider のモデル確認

openclaw models list --provider google

auth profile 確認

openclaw models auth list

model status 確認

openclaw models status --json

plugin 一覧

openclaw plugins list
openclaw plugins list --enabled
openclaw plugins list --disabled

hook 一覧

openclaw hooks list

trace logging

openclaw config set logging.level trace
openclaw gateway restart

遅延関連ログ抽出

openclaw logs --follow | Select-String "startup stages|model-resolution|runtime-plugins|hooks|auth|agent harness selected|embedded run start|model-fetch|message processed|liveness warning"

external OAuth bootstrap 確認

Select-String -Path "$env:LOCALAPPDATA\Temp\openclaw\openclaw-*.log" `
  -Pattern "external cli oauth|openai:default|anthropic|oauth bootstrap" |
  Select-Object -Last 30

500 error 確認

Select-String -Path "$env:LOCALAPPDATA\Temp\openclaw\openclaw-*.log" `
  -Pattern "status=500|code=INTERNAL|LLM request failed" |
  Select-Object -Last 30

現時点の結論

最初の深刻な応答遅延は、主に以下の対応で大幅に改善した。

未使用 provider plugin の無効化
OpenAI / Anthropic / Copilot / OpenRouter / opencode 系の無効化
不要 capability plugin の無効化
fallback を google/gemma-4-31b-it のみに整理
hooks の確認と不要 hook の整理
Gateway restart による hot reload 状態のリセット

改善前は model-resolution が 35〜40 秒程度かかることがあった。

改善後は、短文応答の全体処理時間がおおむね 5〜6 秒程度になった。

残っている主な固定コストは、毎 turn の model-resolution 約 2.6 秒である。

この残存コストは、現在の設定ではかなり詰めた状態であり、OpenClaw 本体側で resolved model / provider / harness を process 内 cache するなどの改善がないと、さらに大きく削るのは難しい可能性がある。

今後の改善要望として出すなら

OpenClaw 側に issue / feature request を出すなら、以下のような内容が妥当。

Single provider / single model / single fallback configuration still spends about 2.6s per turn in model-resolution.

Config:
primary: google/gemma-4-31b-it
fallbacks: [google/gemma-4-31b-it]

Trace:
startup stages totalMs=2721
workspace:0ms
runtime-plugins:2ms
hooks:0ms
model-resolution:2666ms
auth:47ms
context-engine:0ms

Request:
Cache resolved model/provider/harness within the Gateway process and invalidate it only on config reload, plugin reload, model config change, or auth state change.

この要望は、今回の観測結果と整合している。

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