Hmbown/CodeWhale · error
persistent command allow rules must use exact matching
Error message
persistent command allow rules must use exact matching
What it means
This library only persists exec-permission allow rules for commands when the rule uses exact (literal) command matching. If a rule carries a `command` but `command_exact` is false (i.e. fuzzy/prefix/pattern matching), persisting it is rejected because a non-exact command allow rule surviving across sessions is considered unsafe.
Solutions
- Set `command_exact: true` on the rule before persisting, so the allow rule matches the exact command string only
- Drop the `command` field and use a workspace-relative `path` rule instead if approximate matching is desired
- Keep the fuzzy rule session-scoped (non-persistent) rather than writing it to the config
Example fix
// before
PermissionRule { command: Some("cargo test".into()), command_exact: false, .. }
// after
PermissionRule { command: Some("cargo test".into()), command_exact: true, .. } Defensive patterns
Strategy: validation
Validate before calling
fn can_persist(rule: &PermissionRule) -> bool {
rule.command.is_none() || rule.command_exact
} Type guard
fn is_exact_command_rule(rule: &PermissionRule) -> bool {
matches!(rule.command, Some(ref c) if !c.trim().is_empty()) && rule.command_exact
} Try / catch
match config.append_persistent_allow_rules(&rules) {
Err(e) if e.to_string().contains("must use exact matching") => {
// rebuild rules with command_exact = true and retry
}
result => result?,
} Prevention
- Always set `command_exact: true` when constructing persistent command allow rules
- Keep fuzzy command matches session-scoped only
- Add a unit test asserting persisted rules satisfy the exactness invariant
When it happens
Trigger: Calling the persistent allow-rule API (e.g. `append_persistent_allow_rules`) with a rule where `command` is `Some(..)` but `command_exact` is `false`. Typically produced by an allow rule created from a runtime 'always allow' prompt when the command matcher was not exact.
Common situations: Saving a session-scoped prefix/pattern command rule as persistent via a config-edit tool or CLI; a UI toggle flipping persistence on for a fuzzy command match; hand-editing config JSON with `"commandExact": false` alongside a command.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- persistent allow rules must match an exact command or path
- persistent path allow rules must stay within the workspace
- agent profile provider cannot be empty
- agent profile provider must be a simple provider id
- agent profile tools.posture= would widen permissions; use…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/b5318372f9ccbd81.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/lib.rs:5339
/// `permissions.toml` file.
///
/// The caller is responsible for deciding which tool calls are eligible;
/// this boundary rejects broad or incorrectly typed records so a UI bug
/// cannot persist an unscoped allow grant.
pub fn append_allow_rules(&mut self, rules: &[ToolAskRule]) -> Result<usize> {
for rule in rules {
if rule.action != PermissionAction::Allow {
bail!("append_allow_rules only accepts action = \"allow\"");
}
let Some(workspace) = rule
.workspace
.as_deref()
.and_then(codewhale_execpolicy::normalize_workspace_scope)
else {
bail!("persistent allow rules must be scoped to a workspace");
};
if rule.command.is_some() && !rule.command_exact {
bail!("persistent command allow rules must use exact matching");
}
if rule.command.is_none() && rule.path.is_none() {
bail!("persistent allow rules must match an exact command or path");
}
if let Some(command) = rule.command.as_deref()
&& command.trim().is_empty()
{
bail!("persistent command allow rules must not be empty");
}
if let Some(path) = rule.path.as_deref()
&& codewhale_execpolicy::normalize_workspace_relative_path(path, &workspace)
.is_none_or(|path| path.is_empty())
{
bail!("persistent path allow rules must stay within the workspace");
}
}
self.append_permission_rules(rules, PermissionAction::Allow)
}View on GitHub (pinned to 73e0f67d83)