Skip to content

fix: doctor --fix auto-repairs dmPolicy="open" missing allowFrom wildcard#18544

Merged
steipete merged 3 commits intoopenclaw:mainfrom
gitwithuli:fix/doctor-open-policy-allowfrom
Feb 16, 2026
Merged

fix: doctor --fix auto-repairs dmPolicy="open" missing allowFrom wildcard#18544
steipete merged 3 commits intoopenclaw:mainfrom
gitwithuli:fix/doctor-open-policy-allowfrom

Conversation

@gitwithuli
Copy link

@gitwithuli gitwithuli commented Feb 16, 2026

Summary

When a channel is configured with dmPolicy: "open" but without allowFrom: ["*"], the gateway rejects the config and crashes on startup with:

Config invalid
File: ~/.openclaw/openclaw.json
Problem:
  - channels.discord.dm.allowFrom: channels.discord.dmPolicy="open" requires
    channels.discord.allowFrom (or channels.discord.dm.allowFrom) to include "*"
Run: openclaw doctor --fix

The error message tells users to run openclaw doctor --fix, but the doctor has no repair logic for this case — it just reports the same error again.

Changes

Adds maybeRepairOpenPolicyAllowFrom() to the doctor's repair flow that:

  1. Scans all channel configs (discord, slack, telegram, etc.) for dmPolicy: "open" without allowFrom containing "*"
  2. If allowFrom array exists, appends "*" to it
  3. If no allowFrom exists, creates allowFrom: ["*"]
  4. Handles both top-level (channels.X.allowFrom) and nested (channels.X.dm.allowFrom) paths
  5. Handles per-account configs (channels.X.accounts.Y.allowFrom)

This also fixes the gateway startup crash, since the gateway runs doctor in best-effort mode before starting — with this fix, the doctor will auto-repair the config and the gateway will start successfully.

Reproduction

  1. Set this in openclaw.json:
    {
      "channels": {
        "discord": {
          "token": "your-bot-token",
          "dmPolicy": "open",
          "groupPolicy": "open"
        }
      }
    }
    
  2. Run openclaw gateway — crashes with config invalid error
  3. Run openclaw doctor --fix — reports the same error, doesn't fix it

After this fix:

  • openclaw doctor --fix adds allowFrom: ["*"] automatically
  • openclaw gateway starts successfully (doctor auto-repairs during startup)

Testing

  • All existing doctor config tests pass
  • 5 new test cases covering: missing allowFrom, existing allowFrom array, nested dm.allowFrom, already-valid config (no-op), and per-account configs
  • Tested against a production OpenClaw v2026.2.15 gateway deployment where this exact crash occurred

[AI-assisted] Created with Claude Code. Tested in production.

Greptile Summary

Adds auto-repair logic to openclaw doctor --fix for the case where dmPolicy: "open" is set without allowFrom: ["*"], which causes the schema validator to reject the config and crash the gateway on startup. The new maybeRepairOpenPolicyAllowFrom() function scans all channel configs (including per-account and nested dm.allowFrom paths) and adds the required wildcard entry. The non-repair path (running doctor without --fix) now also detects this misconfiguration and suggests the fix command.

  • Repair logic correctly mirrors the schema validation in requireOpenAllowFrom (checks both account.dmPolicy and account.dm.policy)
  • Handles three cases: appending "*" to existing top-level allowFrom, appending to nested dm.allowFrom, or creating new allowFrom: ["*"]
  • 5 new test cases covering the key scenarios
  • Minor style issue: unused channelName parameter in the ensureWildcard helper

Confidence Score: 4/5

  • This PR is safe to merge — it adds a targeted repair for a known crash scenario with correct logic and good test coverage.
  • The repair function correctly handles all the dmPolicy resolution paths that the schema validator checks (top-level dmPolicy, nested dm.policy, top-level allowFrom, nested dm.allowFrom, per-account configs). The structuredClone approach ensures no unintended mutation. Tests cover the main scenarios. One minor style issue (unused parameter) does not affect correctness.
  • No files require special attention — both changed files are straightforward additions to existing patterns.

Last reviewed commit: 2151684

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

…card

When a channel is configured with dmPolicy="open" but without
allowFrom: ["*"], the gateway rejects the config and exits.
The error message suggests running "openclaw doctor --fix", but
the doctor had no repair logic for this case.

This adds a repair step that automatically adds "*" to allowFrom
(or creates it) when dmPolicy="open" is set without the required
wildcard. Handles both top-level and nested dm.allowFrom, as well
as per-account configs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added commands Command implementations size: M labels Feb 16, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +574 to +578
const ensureWildcard = (
channelName: string,
account: Record<string, unknown>,
prefix: string,
) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused channelName parameter

The channelName parameter is declared but never referenced inside ensureWildcard — only prefix is used for the change messages. This will likely trigger a lint warning. Consider removing the unused parameter.

Suggested change
const ensureWildcard = (
channelName: string,
account: Record<string, unknown>,
prefix: string,
) => {
const ensureWildcard = (
account: Record<string, unknown>,
prefix: string,
) => {

If you remove the parameter here, update the call sites at lines 619 and 627 accordingly (drop the first argument).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/doctor-config-flow.ts
Line: 574:578

Comment:
**Unused `channelName` parameter**

The `channelName` parameter is declared but never referenced inside `ensureWildcard` — only `prefix` is used for the change messages. This will likely trigger a lint warning. Consider removing the unused parameter.

```suggestion
  const ensureWildcard = (
    account: Record<string, unknown>,
    prefix: string,
  ) => {
```

If you remove the parameter here, update the call sites at lines 619 and 627 accordingly (drop the first argument).

How can I resolve this? If you propose a fix, please make it concise.

uli-will-code and others added 2 commits February 16, 2026 15:55
Addresses review feedback — channelName was declared but only
prefix was used for change messages.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@steipete steipete merged commit c89eb35 into openclaw:main Feb 16, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants