OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Feature]: Openclaw plugin supports X-OpenViking-Account and X-OpenViking-User

Open GavinYang-LR opened this issue 7 months ago • 1 comments

Problem Statement

Problem

The OpenClaw openviking plugin currently works with apiKey, but it does not properly support multi-tenant production usage with explicit accountId and userId.

Before patching locally, the plugin always sent requests effectively as default/default, because X-OpenViking-Account and X-OpenViking-User were not configurable through plugin config and were hardcoded to empty values in the client setup.

This causes a problem when OpenViking is running in production mode with root_api_key:

  • root_api_key can authenticate successfully
  • but requests are still routed to the default tenant
  • newly created real accounts/users are not actually used by the plugin

As a result, OpenClaw appears to work, but all memory/session/resource writes still go into the default tenant instead of the intended production account.

Expected behavior

The plugin should support tenant-aware configuration, for example:

  • accountId
  • userId

and pass them through as:

  • X-OpenViking-Account
  • X-OpenViking-User

This is required when using root_api_key with a real OpenViking account/user in production.

Additional issue

Even after adding accountId / userId support in code, Gateway config validation fails unless the plugin schema also includes these fields.

So this needs to be fixed in both:

  • runtime plugin config parsing
  • plugin config schema / metadata

Proposed Solution

Proposal

Add first-class multi-tenant support to the OpenClaw openviking plugin.

Proposed changes

  1. Extend plugin config with:

    • accountId
    • userId
  2. Pass these values through on every OpenViking request as:

    • X-OpenViking-Account
    • X-OpenViking-User
  3. Update the plugin config schema so Gateway accepts these fields.

  4. Optionally allow env fallback, for example:

    • OPENVIKING_ACCOUNT_ID
    • OPENVIKING_USER_ID

Why

This makes the plugin work correctly with OpenViking production mode when using root_api_key, and prevents requests from silently falling back to the default tenant.

Without this, OpenClaw may appear functional, but all data is written to the wrong tenant.

Alternatives Considered

No response

Feature Area

Core (Client/Engine)

Use Case

Openclaw

Example API (Optional)


Additional Context

No response

Contribution

  • [ ] I am willing to contribute to implementing this feature

GavinYang-LR avatar Apr 04 '26 06:04 GavinYang-LR

Resolved in main.

Root cause: the OpenClaw OpenViking plugin had client-side support for tenant headers, but the plugin runtime did not expose/pass tenant identity from plugin config. In practice the client was initialized with empty tenant values, and the OpenClaw plugin manifest schema did not accept accountId/userId, so root-key production deployments could still route writes to the default tenant.

Fix point:

  • Primary fix: ef2513c3e73be47c640c15c4dcd2b0a71a0c5f5d, committed 2026-04-21 16:02:06 +0800 (2026-04-21 08:02:06 UTC), via #1606, "feat(openclaw-plugin): align auth, namespace, and role id handling".
    • Added accountId/userId to plugin config parsing, including OPENVIKING_ACCOUNT_ID / OPENVIKING_USER_ID fallback.
    • Passed cfg.accountId / cfg.userId into OpenVikingClient instead of hardcoded empty tenant values.
    • Added accountId/userId to openclaw.plugin.json config schema so Gateway validation accepts the fields.
    • Preserved explicit tenant headers for root-key style api_key flows.
  • Follow-up hardening: 08dcfc10ac5ab75a2e15442aaefbb305faff3600, committed 2026-04-29 11:49:37 +0800 (2026-04-29 03:49:37 UTC), via #1789, "fix(openclaw-plugin): stop synthesizing tenant headers".
    • Ensures X-OpenViking-Account / X-OpenViking-User are only sent when explicitly configured, while normal user-key flow lets the server derive identity from the API key.

Current verification on origin/main:

  • examples/openclaw-plugin/config.ts parses accountId/userId and env fallbacks.
  • examples/openclaw-plugin/index.ts passes cfg.accountId/cfg.userId into OpenVikingClient.
  • examples/openclaw-plugin/client.ts sends X-OpenViking-Account and X-OpenViking-User when configured.
  • examples/openclaw-plugin/openclaw.plugin.json includes accountId/userId in the schema.
  • Related tests cover config parsing, tenant header propagation, user-key no-override behavior, and tool/search propagation.

Local verification command:

npm test -- --run tests/ut/config.test.ts tests/ut/client.test.ts tests/ut/manifest-contracts.test.ts tests/ut/tools.test.ts

Result: 4 test files passed, 126 tests passed.

Closing this issue as resolved. For root_api_key deployments, configure both accountId and userId; for normal user API keys, leave them unset and identity is derived by the server.

Mijamind719 avatar May 31 '26 07:05 Mijamind719