The discussion author's analysis is accurate on all counts. Here's what the code confirms:
-
resolve_effective_policy is unreachable — it exists only in crates/tools/src/policy.rs and is called exclusively by its own unit tests. The actual runtime path at crates/chat/src/lib.rs:1683 uses a separate effective_tool_policy() that reads only global config (config.tools.policy.allow/deny + optional profile).
-
Schema drift is real — the function walks JSON pointers like /agents/list[i], but AgentsConfig uses presets: HashMap<String, AgentPreset> (not an array). Channel configs are HashMap<String, serde_json::Value> with no groups, tools.policy, or bySender substructure. So layers 3–5 can never resolve even if the function were called.
-
Only layers 1, 2, and 6 could theoretically work — global policy, per-provider, and sandbox. But even those aren't wired in; the runtime uses a completely different code path.
My take: This is classic "designed ahead of implementation" scaffolding. The layered merge logic and the PolicyContext struct show clear intent — someone designed a proper defense-in-depth policy system — but it was never connected to either the config schema or the runtime. The discussion author is right that it's in a dead zone: too well-tested to look like an accident, too disconnected to be functional.
The practical options are:
-
Ship it properly: wire resolve_effective_policy into the runtime path (replacing effective_tool_policy), extend AgentsConfig and ChannelsConfig with typed policy fields, and add the PolicyContext to the chat service call site. This would be a meaningful feature for multi-channel deployments.
-
Remove it: delete resolve_effective_policy, PolicyContext, and the associated tests. Point users to BeforeToolCall hooks (once #640 lands with channel metadata in hook payloads).
The author's use case — per-channel/per-sender tool gating for mixed-trust environments — is legitimate and this is exactly the kind of thing that should be first-class rather than reimplemented in shell hooks. If it's on the roadmap, even a rough timeline would let people like this avoid building parallel mechanisms.
Want me to create a beads issue to track making a decision on this, or draft a response to the discussion?