Hmbown/CodeWhale · warning

permissions changed after they were listed; reload

Error message

permissions changed after they were listed; reload {} and retry

What it means

Edit operations on the permissions config are performed under a write lock but re-read the file and verify the state matches what the caller saw when the rules were listed. If the permissions file no longer exists at edit time, the listed data is stale and the library bails, telling the caller to reload the config file and retry, to avoid editing against a diverged file.

Solutions

  1. Re-list the permissions (reloading the config at the quoted path) to get fresh state, then retry the edit
  2. Recreate the permissions file if its deletion was unintended, then re-list and retry the edit
  3. Check for another process/session modifying or removing the permissions file concurrently
Defensive patterns

Strategy: retry

Validate before calling

fn permissions_file_present(config_path: &Path) -> bool {
    resolve_permissions_path(config_path).map_or(false, |p| p.exists())
}

Try / catch

match edit_permission_rule(config_path, index, &expected_token) {
    Err(e) if e.to_string().contains("reload") => {
        let fresh = list_permission_rules(config_path)?; // reload and re-list
        retry_edit_with_fresh_state(config_path, &fresh)?
    }
    result => result?,
}

Prevention

When it happens

Trigger: Calling a targeted permissions edit (e.g. update/remove rule by index returning `ToolAskRule`) after the permissions file was deleted or moved between the list step and the edit step; `read_permissions_state` reports `file_exists == false`.

Common situations: Two sessions/tabs where one deleted or reset the permissions file while the other still shows a stale list; a `codewhale` reset/clean command wiping state mid-edit; container/workspace rebuilt between list and edit.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/bcfc4923cc0f73b4. Report an issue: GitHub.

Appendix: source

Thrown at crates/config/src/lib.rs:6219

    })
}

/// Remove one zero-based permission rule if `expected_token` still describes
/// that exact index in the current file.
///
/// The file is re-read only after acquiring the same adjacent lock used by
/// append operations. This makes the token check and atomic replacement one
/// transaction, preventing stale list views from deleting a different rule.
pub fn remove_permission_rule(
    config_path: Option<PathBuf>,
    index: usize,
    expected_token: &str,
) -> Result<ToolAskRule> {
    let path = resolve_permissions_path(config_path)?;
    config_document::with_config_write_lock(&path, |path| {
        let (file_exists, raw, permissions) = read_permissions_state(path)?;
        if !file_exists {
            bail!(
                "permissions changed after they were listed; reload {} and retry",
                quote_os_path(path)
            );
        }
        let rule = permissions.rules.get(index).cloned().with_context(|| {
            format!(
                "permission rule {} no longer exists in {}; list rules again",
                index + 1,
                quote_os_path(path)
            )
        })?;
        let current_token = permission_removal_token(path, &raw, index);
        if current_token != expected_token {
            bail!(
                "permissions changed after they were listed; reload {} and retry",
                quote_os_path(path)
            );
        }

View on GitHub (pinned to 73e0f67d83)