nanocoai/nanoclaw · error · Error

--from and --to must differ (self-messages are never gated)

Error message

--from and --to must differ (self-messages are never gated)

What it means

Thrown by `ncl policies set` when --from and --to reference the same agent group. Self-messages within one group are never routed through the inter-agent gating path, so a self-policy would be meaningless and is rejected up front.

Source

Thrown at src/cli/resources/policies.ts:35

      type: 'string',
      description: 'User-id who approves each gated message (required). Only this user (or an owner) can approve.',
    },
    { name: 'created_at', type: 'string', description: 'Auto-set.' },
  ],
  operations: { list: 'open' },
  customOperations: {
    set: {
      access: 'approval',
      description:
        'Require approval for messages from one agent to another. Use --from <agent-group-id> --to <agent-group-id> --approver <user-id>. Only the named approver (or an owner) can approve.',
      handler: async (args) => {
        const from = args.from as string;
        const to = args.to as string;
        const approver = args.approver as string;
        if (!from) throw new Error('--from is required');
        if (!to) throw new Error('--to is required');
        if (!approver) throw new Error('--approver is required');
        if (from === to) throw new Error('--from and --to must differ (self-messages are never gated)');
        if (!(await getAgentGroup(from))) throw new Error(`source agent group not found: ${from}`);
        if (!(await getAgentGroup(to))) throw new Error(`target agent group not found: ${to}`);

        await setMessagePolicy(from, to, approver, new Date().toISOString());
        return { from_agent_group_id: from, to_agent_group_id: to, approver };
      },
    },
    remove: {
      access: 'approval',
      description: 'Remove an approval policy (back to free flow). Use --from <agent-group-id> --to <agent-group-id>.',
      handler: async (args) => {
        const from = args.from as string;
        const to = args.to as string;
        if (!from) throw new Error('--from is required');
        if (!to) throw new Error('--to is required');
        if (!(await removeMessagePolicy(from, to))) throw new Error('policy not found');
        return { removed: { from_agent_group_id: from, to_agent_group_id: to } };
      },

View on GitHub (pinned to 294ef2aee8)

Solutions

  1. Use two distinct group ids: re-check `ncl groups list` and pick the actual source and target
  2. If you meant self-message gating, that is not supported by this command — remove the policy intent

Example fix

// before
ncl policies set --from grp-a --to grp-a --approver telegram:owner
// after
ncl policies set --from grp-a --to grp-b --approver telegram:owner
Defensive patterns

Strategy: validation

Validate before calling

if (from === to) throw new Error('from and to must differ');

Type guard

const isDistinctPair = (a, b) => Boolean(a && b && a !== b);

Prevention

When it happens

Trigger: Passing the same group id to both flags — usually a copy-paste of one id into both slots, or a script that fills both from one variable.

Common situations: Operator intends to gate a group's outbound messages to a different group but reuses the same id; automation loops that accidentally set from === to.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of nanocoai/nanoclaw@294ef2aee8 (2026-08-28). Data as JSON: /api/errors/3bedebd07bed7972. Report an issue: GitHub.