Skip to content

Surface a warning when enabled policy names or policy tool names can never match (silent policy failure at the name layer) #998

Open

Description

@xiong-wei1

Problem / Motivation

A failproofai policy can be silently dead — configured, displayed as fine, and never firing — purely because of a name mismatch, and today nothing anywhere tells the user. I found three places where this happens:

  1. Unknown names in enabledPolicies are dropped silently. registerBuiltinPolicies (src/hooks/builtin-policies.ts) builds an enabledSet from the config and registers only catalog entries that match. A misspelled, renamed, or stale name (hand-edited config, a project-level .failproofai/policies-config.json checked into a repo, a policy renamed in a newer release) matches nothing and disappears without a log line or warning. The failproofai policies screen can't show it either: it iterates over known policies, so the dead name never appears in any row.

  2. Policy match.toolNames are never checked for reachability. Pack manifest validation (src/hooks/pack-manifest.ts) verifies that match.toolNames is a list of non-empty strings, but not that any of those names can ever occur. The same applies to custom policies validated at load time. At runtime, canonicalizeToolName passes unknown names through unchanged and policy lookup is an exact string match, so a toolNames entry that is off by one character matches no tool call, ever, with zero signal.

  3. There is an in-repo inconsistency that makes this more surprising: the policies screen does warn about unknown policyParams keys — an attention line (Unknown policyParams key "…", possibly a typo.) plus a policy_params_validation_warning telemetry event. Unknown policy names and tool names — which disable enforcement entirely, a much more severe outcome than a stray params key — get no equivalent treatment.

This failure mode is not hypothetical. Tool-name drift has bitten repeatedly: #690 (Copilot task/web_search unmapped, so Task-class policies silently stopped applying) and the follow-up mapping PRs #693, #792, #844 each fixed one instance by hand after the fact. Those PRs fix individual mappings; nothing detects the next drift, typo, or stale config name when it happens.

The user-visible consequence: someone believes a guard (e.g. a file-protection or secret-sanitizing policy) is active in their agent sessions when it has never fired once.

Relation to #537 (scope boundary)

#537 already argues, persuasively, that silent failures should become visible warnings — its motivating example is block-env-files silently going dead for several releases because of Copilot version drift. I read #537 as being about the CLI version-detection layer: detecting that the harness/CLI version changed so name mappings and behaviours can be re-validated.

This proposal is the neighbouring but distinct name layer: names written in user configuration and policy definitions (enabledPolicies entries, match.toolNames in custom and pack policies) that can never resolve against the names the runtime actually knows. Same philosophy, different mechanism, no version detection involved. I'm filing it separately so the scope stays reviewable, but if you'd rather track it as a sub-item of #537, I'm happy to fold it in — please say so.

Proposed Solution

Add a "can this name ever match?" check at configuration/display time, reusing the existing attention-line + telemetry pattern from the policyParams warning:

  • enabledPolicies names: when failproofai policies runs (and/or when configuration is loaded), any enabled name that resolves to no registered policy — builtin, pack, or custom — produces an attention line naming it, e.g. Unknown enabled policy "block-env-file", possibly a typo — it will never run., plus a telemetry event analogous to policy_params_validation_warning.
  • match.toolNames in custom and pack policies: validate entries against the known tool-name universe (the canonical names produced by the per-CLI tool maps, union the tool names referenced by builtin policy matches). Entries outside that universe produce a low-confidence warning at validation time: the name may never match any tool.
  • Deliberate exemptions and wording: MCP tool names (e.g. mcp__* / server-defined names) are user-defined by design and must not warn. Because new harness tools appear over time, warnings should be phrased as "may never match" rather than errors, and should never block loading or enforcement.

Scope and non-goals:

If the direction looks reasonable, I'm willing to implement it, with unit tests in __tests__/hooks/ covering: an unknown enabled policy name warns; an unknown toolNames entry warns; MCP-style names and all currently valid builtin/pack configurations produce no warning; and the existing test suite stays green.

Alternatives Considered

  • Runtime counting of unmatched tool names (detect drift as it happens in live sessions): more powerful, but it touches the hook hot path and needs its own storage/telemetry design. I'd suggest it as a possible second phase rather than the first step.
  • Failing hard on unknown names at load time: rejected — a checked-in project config with one stale name would break everyone's setup, and legitimate not-yet-known names (new harness tools, MCP) would false-positive. A warning matches the repo's existing possibly a typo precedent.
  • Doing nothing and relying on mapping PRs: the COPILOT_TOOL_MAP is missing task and web_search — Task policies silently never fire on Copilot #690 series shows this pattern recurs; each instance is currently found by accident.

Additional Context

  • Code pointers (current main): silent drop in registerBuiltinPolicies in src/hooks/builtin-policies.ts; shape-only toolNames validation in src/hooks/pack-manifest.ts; pass-through in canonicalizeToolName (src/hooks/tool-name-canonicalize.ts) and exact-match lookup in getPoliciesForEvent (src/hooks/policy-registry.ts); the warning pattern to align with is in listHooks in src/hooks/manager.ts (attention line ~"possibly a typo" and the policy_params_validation_warning event).
  • There is currently no "known tool names" set anywhere in the codebase to validate against; building that universe from the existing tool maps is part of the proposed change.

Questions where I'd like a maintainer call before writing code:

  1. Which surfaces should warn — the failproofai policies screen only, or also at config-load time (which would surface in more flows but risks repeating the warning)?
  2. Should the tool-name side (match.toolNames) be in scope for the same change, or would you prefer policy names (enabledPolicies) first and tool names as a follow-up?
  3. Wording/confidence: is the "possibly a typo / may never match" low-confidence phrasing and a policy_params_validation_warning-style telemetry event the right conventions to reuse here?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions