The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): reject links to running children
fangliquanflqb95513df7c4b
diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex 6ac24a3f532..1499e11cf1e 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -1620,7 +1620,11 @@ def set_reasoning_effort(conn: sqlite3.Connection, task_id: str, effort: Optionadef link_tasks(conn: sqlite3.Connection, parent_id: str, child_id: str) -> bool:"""Link ``parent_id -> child_id``. Returns True when the link gated a``ready`` child back to ``todo`` (the new parent is not yet terminal), so- callers can surface the demotion instead of a silent status flip."""+ callers can surface the demotion instead of a silent status flip.++ A running child cannot be gated retroactively, so reject the edge rather+ than record a dependency that did not constrain the active run.+ """if parent_id == child_id:raise ValueError("a task cannot depend on itself")gated = False@@ -1628,6 +1632,8 @@ def link_tasks(conn: sqlite3.Connection, parent_id: str, child_id: str) -> bool:missing = _missing_task_ids(conn, [parent_id, child_id])if missing:raise ValueError(f"unknown task(s): {', '.join(missing)}")+ if _task_status(conn, child_id) == "running":+ raise ValueError(f"cannot link {parent_id} -> {child_id}: child is already running")if _would_cycle(conn, parent_id, child_id):raise ValueError(f"linking {parent_id} -> {child_id} would create a cycle")_link(conn, parent_id, child_id)diff --git a/tests/hermes_cli/test_kanban_db.py b/tests/hermes_cli/test_kanban_db.pyindex 78064e878c0..571e96a1d70 100644--- a/tests/hermes_cli/test_kanban_db.py+++ b/tests/hermes_cli/test_kanban_db.py@@ -1181,6 +1181,20 @@ def test_link_tasks_emits_dependency_wait_when_demoting_ready_child(kanban_home)assert payload["parent"] == parent+def test_link_tasks_rejects_running_child_without_recording_edge(kanban_home):+ """Regression for #113374: a dependency added after claim cannot gate that run."""+ with kbc.connect() as conn:+ parent = kb.create_task(conn, title="unfinished parent")+ child = kb.create_task(conn, title="claimed child")+ assert kb.claim_task(conn, child, claimer="worker") is not None++ with pytest.raises(ValueError, match="child is already running"):+ kb.link_tasks(conn, parent, child)++ assert kb.parent_ids(conn, child) == []+ assert "linked" not in [event.kind for event in kb.list_events(conn, child)]++def test_link_tasks_no_dependency_wait_when_parent_done(kanban_home):"""A done parent demotes nothing and reports no gate."""with kbc.connect() as conn: