nikivdev/code · error

Todo id '{}' is ambiguous

Error message

Todo id '{}' is ambiguous

What it means

Raised by find_item_index (src/todo.rs:551) when the given id prefix matches more than one todo item (matches.len() > 1). The tool supports id-prefix shortcuts, but only when the prefix uniquely identifies a single item.

Source

Thrown at src/todo.rs:551

    }
    item.note
        .as_deref()
        .map(|n| n.to_lowercase().contains("review timed out"))
        .unwrap_or(false)
}

pub(crate) fn find_item_index(items: &[TodoItem], id: &str) -> Result<usize> {
    let mut matches = Vec::new();
    for (idx, item) in items.iter().enumerate() {
        if item.id == id || item.id.starts_with(id) {
            matches.push(idx);
        }
    }

    match matches.len() {
        0 => bail!("Todo '{}' not found", id),
        1 => Ok(matches[0]),
        _ => bail!("Todo id '{}' is ambiguous", id),
    }
}

fn resolve_session_ref(session: Option<&str>, no_session: bool) -> Result<Option<String>> {
    if no_session {
        return Ok(None);
    }

    if let Some(session) = session {
        let trimmed = session.trim();
        return Ok(if trimmed.is_empty() {
            None
        } else {
            Some(trimmed.to_string())
        });
    }

    let root = project_root();

View on GitHub (pinned to a747e741ae)

Solutions

  1. Use a longer prefix of the id until it is unique (UUIDs diverge quickly after a few chars).
  2. Use the full 32-char simple UUID from `f todo list`.
  3. Remove or consolidate duplicate/stale todos so prefixes become unambiguous.

Example fix

// before
todo remove a1
// after: use a longer unique prefix
todo remove a1b2c3d4
Defensive patterns

Strategy: validation

Validate before calling

// ensure the prefix is unique before invoking
code.split(/[ \t\r?\n]+/)
// shell: count matching ids in the listing
const matches = execSync("f todo list").toString().split("\n")
  .filter(l => l.includes(idPrefix));
if (matches.length > 1) throw new Error(`prefix ${idPrefix} is ambiguous (${matches.length} matches)`);

Try / catch

try {
  editTodo(prefix);
} catch (e) {
  if (String(e).match(/ambiguous/)) {
    console.error("Lengthen the id prefix until it matches exactly one todo");
  } else throw e;
}

Prevention

When it happens

Trigger: Calling edit, set_status, or remove (via run) with a short prefix (e.g. first one or two characters of a UUID) that happens to match multiple stored item ids.

Common situations: Large todo lists where short prefixes collide; using a 1-2 char abbreviation out of habit; pasting only the first few chars of a UUID.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/f94469e2fab79ac4. Report an issue: GitHub.