Skip to content

Token refresh rewrites openclaw.json causing repeated gateway restarts #1

@vmhq

Description

@vmhq

Summary

Each time the OAuth access token is refreshed, the plugin calls upsertPluginConfig() which rewrites ~/.openclaw/openclaw.json with the new accessToken and refreshToken. OpenClaw detects this config file change and triggers a full gateway restart (by design — the config watcher restarts on sensitive field changes).

This causes the gateway to restart multiple times per hour, which:

  • Interrupts running cron jobs (they land in a "missed jobs after restart" queue and execute late)
  • Creates a noisy restart loop visible in logs all day
  • Breaks timed automation workflows that depend on stable scheduling

Observed behavior

Logs show a clear pattern repeating ~every 15–60 min:

config change detected; evaluating reload (plugins.entries.openclaw-membase.config.accessToken, plugins.entries.openclaw-membase.config.refreshToken)
config change requires gateway restart (plugins.entries.openclaw-membase.config.accessToken, plugins.entries.openclaw-membase.config.refreshToken)
membase: stopped
membase: connected (recall: true, capture: true)

Root cause

upsertPluginConfig() in src/commands/cli.ts writes the refreshed tokens directly into openclaw.json. Since accessToken and refreshToken are listed as sensitive fields that require gateway restart when changed, every token rotation restarts the entire gateway.

Proposed fix

Store the OAuth tokens in a separate file (e.g., ~/.openclaw/extensions/openclaw-membase/tokens.json) and only keep stable config values (apiUrl, clientId, tokenFile) in openclaw.json.

Changes needed:

  1. src/config.ts: Add readTokenFile() and writeTokenFile() helpers; load tokens from the file at plugin load instead of from pluginConfig
  2. src/index.ts: Call writeTokenFile() in the onTokenRefresh callback instead of upsertPluginConfig(); auto-migrate existing tokens on first boot
  3. src/commands/cli.ts: Update login and logout to write/clear the token file; only persist apiUrl, clientId, and tokenFile path to openclaw.json
  4. openclaw.plugin.json: Add tokenFile to the config schema
  5. src/types.ts: Add tokenFile: string to MembasePluginConfig

This way, token refreshes only touch the private token file — which OpenClaw does not watch for config-triggered restarts — leaving the gateway stable.

Workaround applied locally

We implemented the patch described above locally on @membase/openclaw-membase@0.3.1. The gateway has been stable since applying it. Happy to share the diff if useful.

Environment

  • openclaw-membase version: 0.3.1
  • OpenClaw version: 2026.3.12
  • OS: Ubuntu 24.04 LTS

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