{"record":{"id":"b5318372f9ccbd81","repo":"Hmbown/CodeWhale","slug":"persistent-command-allow-rules-must-use-exact-matc","errorCode":null,"errorMessage":"persistent command allow rules must use exact matching","messagePattern":"persistent command allow rules must use exact matching","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/lib.rs","lineNumber":5339,"sourceCode":"    /// `permissions.toml` file.\n    ///\n    /// The caller is responsible for deciding which tool calls are eligible;\n    /// this boundary rejects broad or incorrectly typed records so a UI bug\n    /// cannot persist an unscoped allow grant.\n    pub fn append_allow_rules(&mut self, rules: &[ToolAskRule]) -> Result<usize> {\n        for rule in rules {\n            if rule.action != PermissionAction::Allow {\n                bail!(\"append_allow_rules only accepts action = \\\"allow\\\"\");\n            }\n            let Some(workspace) = rule\n                .workspace\n                .as_deref()\n                .and_then(codewhale_execpolicy::normalize_workspace_scope)\n            else {\n                bail!(\"persistent allow rules must be scoped to a workspace\");\n            };\n            if rule.command.is_some() && !rule.command_exact {\n                bail!(\"persistent command allow rules must use exact matching\");\n            }\n            if rule.command.is_none() && rule.path.is_none() {\n                bail!(\"persistent allow rules must match an exact command or path\");\n            }\n            if let Some(command) = rule.command.as_deref()\n                && command.trim().is_empty()\n            {\n                bail!(\"persistent command allow rules must not be empty\");\n            }\n            if let Some(path) = rule.path.as_deref()\n                && codewhale_execpolicy::normalize_workspace_relative_path(path, &workspace)\n                    .is_none_or(|path| path.is_empty())\n            {\n                bail!(\"persistent path allow rules must stay within the workspace\");\n            }\n        }\n        self.append_permission_rules(rules, PermissionAction::Allow)\n    }","sourceCodeStart":5321,"sourceCodeEnd":5357,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/config/src/lib.rs#L5321-L5357","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nPermissionRule { command: Some(\"cargo test\".into()), command_exact: false, .. }\n// after\nPermissionRule { command: Some(\"cargo test\".into()), command_exact: true, .. }","handlingStrategy":"validation","validationCode":"fn can_persist(rule: &PermissionRule) -> bool {\n    rule.command.is_none() || rule.command_exact\n}","typeGuard":"fn is_exact_command_rule(rule: &PermissionRule) -> bool {\n    matches!(rule.command, Some(ref c) if !c.trim().is_empty()) && rule.command_exact\n}","tryCatchPattern":"match config.append_persistent_allow_rules(&rules) {\n    Err(e) if e.to_string().contains(\"must use exact matching\") => {\n        // rebuild rules with command_exact = true and retry\n    }\n    result => result?,\n}","preventionTips":["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"],"tags":["config","permissions","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}