openai/codex · error · AmendError

prefix rule requires at least one token

Error message

prefix rule requires at least one token

What it means

AmendError::EmptyPrefix fires when amending an exec policy file with a new prefix rule whose token list is empty — a rule with no tokens would match nothing (or everything) and cannot be serialized into the policy file, so it is rejected up front.

Solutions

  1. Provide at least one token for the prefix rule
  2. Skip adding the rule when the prefix is empty instead of writing it
  3. Validate user-supplied command prefixes before amending the policy
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/execpolicy/src/amend.rs:16 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/c6e199c996f75d6e. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/execpolicy/src/amend.rs:16

use std::fs::OpenOptions;
use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;

use crate::decision::Decision;
use crate::rule::NetworkRuleProtocol;
use crate::rule::normalize_network_rule_host;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum AmendError {
    #[error("prefix rule requires at least one token")]
    EmptyPrefix,
    #[error("invalid network rule: {0}")]
    InvalidNetworkRule(String),
    #[error("policy path has no parent: {path}")]
    MissingParent { path: PathBuf },
    #[error("failed to create policy directory {dir}: {source}")]
    CreatePolicyDir {
        dir: PathBuf,
        source: std::io::Error,
    },
    #[error("failed to format prefix tokens: {source}")]
    SerializePrefix { source: serde_json::Error },
    #[error("failed to serialize network rule field: {source}")]
    SerializeNetworkRule { source: serde_json::Error },
    #[error("failed to open policy file {path}: {source}")]
    OpenPolicyFile {
        path: PathBuf,
        source: std::io::Error,

View on GitHub (pinned to 339751715c)