{"record":{"id":"240bdb16da62a322","repo":"tinyhumansai/openhuman","slug":"dependency-cycle-detected","errorCode":null,"errorMessage":"dependency cycle detected","messagePattern":"dependency cycle detected","errorType":"validation","errorClass":"TeamError","httpStatus":null,"severity":"error","filePath":"src/openhuman/agent/orchestration/agent_teams/ops.rs","lineNumber":416,"sourceCode":"    existing: &[AgentTeamTask],\n) -> Result<()> {\n    let known: HashSet<&str> = existing.iter().map(|t| t.id.as_str()).collect();\n\n    for dep in depends_on {\n        if dep == new_task_id {\n            return Err(anyhow!(TeamError::SelfDependency {\n                task_id: new_task_id.to_string(),\n            }));\n        }\n        if !known.contains(dep.as_str()) {\n            return Err(anyhow!(TeamError::UnknownDependency {\n                depends_on: dep.clone(),\n            }));\n        }\n    }\n\n    if has_task_cycle(new_task_id, depends_on, existing) {\n        return Err(anyhow!(TeamError::CyclicDependency));\n    }\n\n    Ok(())\n}\n\n/// Kahn's-algorithm cycle check over the task dependency graph (existing tasks\n/// plus the candidate new task). Edge `dep -> task` means `task` depends on\n/// `dep`. Edges pointing at unknown ids are ignored here (rejected separately).\nfn has_task_cycle(\n    new_task_id: &str,\n    new_depends_on: &[String],\n    existing: &[AgentTeamTask],\n) -> bool {\n    // Node set: every existing task id plus the new one.\n    let mut nodes: HashSet<&str> = existing.iter().map(|t| t.id.as_str()).collect();\n    nodes.insert(new_task_id);\n\n    let mut indegree: HashMap<&str, usize> = nodes.iter().map(|&n| (n, 0)).collect();","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/agent/orchestration/agent_teams/ops.rs#L398-L434","documentation":"has_task_cycle (Kahn's algorithm over existing tasks plus the new one) detected that the proposed dependency edges would introduce a cycle (TeamError::DependencyCycle). The new task's deps, combined with existing edges, form a strongly connected wait graph; the scheduler would deadlock, so the assignment is rejected before any state changes.","triggerScenarios":"Thrown at src/openhuman/agent/orchestration/agent_teams/ops.rs:416 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Trace the cycle reported in the error and remove or reverse the edge that closes it","Restructure the dependent tasks into sequential phases so the wait graph is a DAG","Re-run task assignment after breaking the cycle"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}