Hmbown/CodeWhale · error

worker record remains

Error message

worker record remains

What it means

Test panic: `manager.get_worker_record(&agent_id)` returned None after cancellation, failing `.expect("worker record remains")`. The worker record (event history) must survive the terminal Cancelled transition so exactly one terminal event can be observed.

Solutions

  1. Ensure cancel_agent appends a terminal Cancelled event to the worker record instead of removing it.
  2. Keep records retained after terminal transitions; prune only at explicit cleanup points.
  3. Assert event.status.is_terminal() filtering yields exactly one Cancelled event.

Example fix

// before
if status.is_terminal() { self.workers.remove(id); }
// after: append terminal event, keep record
self.record_event(id, AgentWorkerStatus::Cancelled);
Defensive patterns

Strategy: validation

Validate before calling

assert!(manager.get_worker_record(&agent_id).is_some(), "worker record must survive terminal transitions");

Try / catch

let record = manager.get_worker_record(&agent_id)
    .unwrap_or_else(|| panic!("worker record removed for {agent_id}"));

Prevention

When it happens

Trigger: Inspecting the worker record after cancel when the record was deleted or never appended the Cancelled event on the cancel path.

Common situations: Refactor pruning records on terminal status; cancel path bypassing record_event for AgentWorkerStatus::Cancelled.

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/dadddd6801b58211. Report an issue: GitHub.

Appendix: source

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

        .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");
    let terminal = record
        .events
        .iter()
        .filter(|event| event.status.is_terminal())
        .collect::<Vec<_>>();
    assert_eq!(terminal.len(), 1);
    assert_eq!(terminal[0].status, AgentWorkerStatus::Cancelled);
}

#[tokio::test]
async fn completion_claim_preserves_running_gate_and_excludes_late_cancel() {
    let tmp = tempdir().expect("tempdir");
    let mut manager = SubAgentManager::new(tmp.path().to_path_buf(), 2);
    let agent_id = "agent_completion_claim".to_string();
    let (input_tx, _input_rx) = mpsc::unbounded_channel();
    let mut agent = SubAgent::new(
        agent_id.clone(),
        FleetRole::Worker,

View on GitHub (pinned to 73e0f67d83)