nanocoai/nanoclaw · error · Error

policy not found

Error message

policy not found

What it means

Thrown by `ncl policies remove` when removeMessagePolicy(from, to) returns false — no message_policies row exists for that (from, to) pair, so there was nothing to delete.

Source

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

        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. Check which policies exist (ncl policies list) before removing
  2. Confirm the direction: the pair must match how the policy was set exactly
  3. If already gone, the desired end state is reached — continue
Defensive patterns

Strategy: try-catch

Validate before calling

const exists = await getMessagePolicy(from, to); if (!exists) { /* nothing to remove */ }

Try / catch

try { await removePolicy(from, to); } catch (e) { if (e.message === 'policy not found') return; throw e; }

Prevention

When it happens

Trigger: The policy was already removed, was never set for that exact pair, or one of the ids is wrong.

Common situations: Re-running an idempotent cleanup script; policy was set with a different from/to direction (policies are directional).

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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