{"record":{"id":"dadddd6801b58211","repo":"Hmbown/CodeWhale","slug":"worker-record-remains","errorCode":null,"errorMessage":"worker record remains","messagePattern":"worker record remains","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/tests.rs","lineNumber":6816,"sourceCode":"        .expect(\"cancelled snapshot exists\");\n    late.status = SubAgentStatus::Completed;\n    late.result = Some(\"late success\".to_string());\n    assert!(\n        !manager.update_from_result(&agent_id, late),\n        \"late completion must lose the terminal transition\"\n    );\n\n    let snapshot = manager\n        .get_result(&agent_id)\n        .expect(\"terminal snapshot remains\");\n    assert_eq!(snapshot.status, SubAgentStatus::Cancelled);\n    assert_eq!(\n        snapshot.result.as_deref(),\n        Some(\"Cancelled by parent request.\")\n    );\n    let record = manager\n        .get_worker_record(&agent_id)\n        .expect(\"worker record remains\");\n    let terminal = record\n        .events\n        .iter()\n        .filter(|event| event.status.is_terminal())\n        .collect::<Vec<_>>();\n    assert_eq!(terminal.len(), 1);\n    assert_eq!(terminal[0].status, AgentWorkerStatus::Cancelled);\n}\n\n#[tokio::test]\nasync fn completion_claim_preserves_running_gate_and_excludes_late_cancel() {\n    let tmp = tempdir().expect(\"tempdir\");\n    let mut manager = SubAgentManager::new(tmp.path().to_path_buf(), 2);\n    let agent_id = \"agent_completion_claim\".to_string();\n    let (input_tx, _input_rx) = mpsc::unbounded_channel();\n    let mut agent = SubAgent::new(\n        agent_id.clone(),\n        FleetRole::Worker,","sourceCodeStart":6798,"sourceCodeEnd":6834,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/tests.rs#L6798-L6834","documentation":"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.","triggerScenarios":"Inspecting the worker record after cancel when the record was deleted or never appended the Cancelled event on the cancel path.","commonSituations":"Refactor pruning records on terminal status; cancel path bypassing record_event for AgentWorkerStatus::Cancelled.","solutions":["Ensure cancel_agent appends a terminal Cancelled event to the worker record instead of removing it.","Keep records retained after terminal transitions; prune only at explicit cleanup points.","Assert event.status.is_terminal() filtering yields exactly one Cancelled event."],"exampleFix":"// before\nif status.is_terminal() { self.workers.remove(id); }\n// after: append terminal event, keep record\nself.record_event(id, AgentWorkerStatus::Cancelled);","handlingStrategy":"validation","validationCode":"assert!(manager.get_worker_record(&agent_id).is_some(), \"worker record must survive terminal transitions\");","typeGuard":null,"tryCatchPattern":"let record = manager.get_worker_record(&agent_id)\n    .unwrap_or_else(|| panic!(\"worker record removed for {agent_id}\"));","preventionTips":["Append a terminal Cancelled event on the cancel path rather than deleting the record","Restrict record pruning to explicit cleanup APIs","Assert exactly one terminal event per agent lifecycle in tests"],"tags":["test-assertion","worker-record","terminal-state","subagent"],"backgroundTag":"record-not-found","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}