{"record":{"id":"dcede2c077cb5e39","repo":"Hmbown/CodeWhale","slug":"worker-record-remains-inspectable","errorCode":null,"errorMessage":"worker record remains inspectable","messagePattern":"worker record remains inspectable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/tools/subagent/tests.rs","lineNumber":6529,"sourceCode":"        .read()\n        .await\n        .get_result(\"agent_cancel_probe\")\n        .expect(\"agent remains listed\");\n    assert_eq!(snapshot.status, SubAgentStatus::Cancelled);\n\n    let second = tool\n        .execute(\n            json!({\"action\": \"cancel\", \"agent_id\": \"agent_cancel_probe\"}),\n            &context,\n        )\n        .await\n        .expect(\"repeated cancel stays idempotent\");\n    assert_eq!(second.metadata.as_ref().unwrap()[\"action\"], json!(\"cancel\"));\n    let record = manager\n        .read()\n        .await\n        .get_worker_record(\"agent_cancel_probe\")\n        .expect(\"worker record remains inspectable\");\n    assert_eq!(\n        record\n            .events\n            .iter()\n            .filter(|event| event.status == AgentWorkerStatus::Cancelled)\n            .count(),\n        1,\n        \"repeated stop must not append a second terminal outcome\"\n    );\n}\n\n#[tokio::test]\nasync fn model_wait_cancel_fans_in_once_and_preserves_checkpoint() {\n    use tokio_util::sync::CancellationToken;\n\n    let tmp = tempdir().expect(\"tempdir\");\n    let mut manager = SubAgentManager::new(tmp.path().to_path_buf(), 2);\n    let agent_id = \"agent_model_wait_cancel\".to_string();","sourceCodeStart":6511,"sourceCodeEnd":6547,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/tests.rs#L6511-L6547","documentation":"A test assertion in `crates/tui/src/tools/subagent/tests.rs` that fetches a subagent worker record via `get_worker_record(\"agent_cancel_probe\")` and expects `Some`. The expect encodes the test's premise that a previously cancelled worker's record must still be readable and inspectable after cancellation. If the manager dropped, evicted, or never persisted the record, this panics with 'worker record remains inspectable'.","triggerScenarios":"Running the cancel-idempotency test when `SubAgentManager` fails to retain the worker record after `cancel_agent` — e.g. a change that removes the record on cancel, cleans up terminal workers eagerly, or a typo in the agent id ('agent_cancel_probe').","commonSituations":"A refactor of SubAgentManager's record lifecycle (e.g. garbage-collecting cancelled workers, changing the storage map keying, or moving records behind a new persistence layer) breaks the invariant the test guards.","solutions":["Re-run the test and check the preceding `cancel_agent` calls succeeded (their own expects would have failed first otherwise); if they pass, record retention was broken by a recent change.","Inspect get_worker_record and the cancel path in the SubAgentManager to confirm cancelled records are kept in the map, not removed.","Confirm the agent id string matches exactly ('agent_cancel_probe') in registration and lookup.","If eager cleanup of terminal workers is now intended product behavior, update the test to assert on the new contract rather than keeping the record."],"exampleFix":"// before\nlet record = manager\n    .read()\n    .await\n    .get_worker_record(\"agent_cancel_probe\")\n    .expect(\"worker record remains inspectable\");\n// after\nlet record = manager\n    .read()\n    .await\n    .get_worker_record(\"agent_cancel_probe\")\n    .unwrap_or_else(|| panic!(\"worker record for agent_cancel_probe missing after cancel; retained keys: {:?}\", manager.read().await.worker_ids()));","handlingStrategy":"type-guard","validationCode":"// Before asserting, ensure the manager still holds the id:\nassert!(manager.read().await.worker_ids().contains(&\"agent_cancel_probe\".to_string()), \"record pruned after cancel\");","typeGuard":"fn record_of<'a>(m: &'a SubAgentManager, id: &str) -> Option<&'a AgentWorkerRecord> { m.get_worker_record(id) }","tryCatchPattern":null,"preventionTips":["Pin record-retention-after-cancel with a dedicated regression test.","Never prune terminal worker records without updating the tests that inspect them.","Extract agent ids into constants shared between registration and lookup."],"tags":["rust","test","panic","state-management","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-22T11:17:16.035Z"}