Hmbown/CodeWhale · error

cancelled snapshot exists

Error message

cancelled snapshot exists

What it means

Test panic: `manager.get_result(&agent_id)` returned None after `cancel_agent`, so `.expect("cancelled snapshot exists")` panicked. Cancellation must persist a terminal snapshot of the agent's result immediately.

Solutions

  1. Ensure cancel_agent writes a SubAgentStatus::Cancelled snapshot synchronously before returning Ok.
  2. Verify the result map key equals the agent_id used for lookup.
  3. Guard against snapshot eviction on terminal transitions in the manager.

Example fix

// before
let mut late = manager.get_result(&agent_id).expect("cancelled snapshot exists");
// after
let mut late = manager.get_result(&agent_id)
    .unwrap_or_else(|| panic!("no cancelled snapshot for {agent_id}"));
Defensive patterns

Strategy: validation

Validate before calling

assert!(manager.get_result(&agent_id).is_some(), "cancel must persist a snapshot synchronously");

Try / catch

let mut late = manager.get_result(&agent_id)
    .unwrap_or_else(|| panic!("no cancelled snapshot for {agent_id}"));

Prevention

When it happens

Trigger: Querying results right after cancel when the cancel path failed to write a Cancelled snapshot into the result map.

Common situations: Refactor moving snapshot persistence off the cancel path; key mismatch between agent registration and result storage.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/tools/subagent/tests.rs:6798

    let agent = SubAgent::new(
        agent_id.clone(),
        FleetRole::Worker,
        "race".to_string(),
        make_assignment(),
        "deepseek-v4-flash".to_string(),
        None,
        None,
        input_tx,
        tmp.path().to_path_buf(),
        manager.current_session_boot_id.clone(),
    );
    manager.agents.insert(agent_id.clone(), agent);
    manager.register_worker(make_worker_spec(&agent_id, tmp.path().to_path_buf()));

    manager.cancel_agent(&agent_id).expect("cancel wins race");
    let mut late = manager
        .get_result(&agent_id)
        .expect("cancelled snapshot exists");
    late.status = SubAgentStatus::Completed;
    late.result = Some("late success".to_string());
    assert!(
        !manager.update_from_result(&agent_id, late),
        "late completion must lose the terminal transition"
    );

    let snapshot = manager
        .get_result(&agent_id)
        .expect("terminal snapshot remains");
    assert_eq!(snapshot.status, SubAgentStatus::Cancelled);
    assert_eq!(
        snapshot.result.as_deref(),
        Some("Cancelled by parent request.")
    );
    let record = manager
        .get_worker_record(&agent_id)
        .expect("worker record remains");

View on GitHub (pinned to 73e0f67d83)