Skip to content

The agent that grows with you

fix(kanban): preserve foreign child linking

fangliquanflq46763ce37820
diff --git a/hermes_cli/kanban.py b/hermes_cli/kanban.py
index 2ea787da245..6692bd658f0 100644
--- a/hermes_cli/kanban.py
+++ b/hermes_cli/kanban.py
@@ -694,12 +694,18 @@ def _cmd_diagnostics(args: argparse.Namespace) -> int:
def _cmd_link(args: argparse.Namespace) -> int:
+ worker_task_id = os.environ.get("HERMES_KANBAN_TASK")
+ expected_child_run_id = (
+ _worker_run_id_for(args.child_id)
+ if args.child_id == worker_task_id
+ else None
+ )
with kbc.connect_closing() as conn:
gated = kb.link_tasks(
conn,
args.parent_id,
args.child_id,
- expected_child_run_id=_worker_run_id_for(args.child_id),
+ expected_child_run_id=expected_child_run_id,
)
print(f"Linked {args.parent_id} -> {args.child_id}")
if gated:
diff --git a/tests/hermes_cli/test_kanban_cli.py b/tests/hermes_cli/test_kanban_cli.py
index 376c79f2a97..e44ca8cd27f 100644
--- a/tests/hermes_cli/test_kanban_cli.py
+++ b/tests/hermes_cli/test_kanban_cli.py
@@ -72,6 +72,32 @@ def test_kanban_show_text_renders_graph_with_open_connection(kanban_home):
assert "Cannot operate on a closed database" not in output
+def test_worker_link_preserves_foreign_child_rules(kanban_home, monkeypatch):
+ with kbc.connect_closing() as conn:
+ worker = kb.create_task(conn, title="worker")
+ assert kb.claim_task(conn, worker, claimer="worker") is not None
+ worker_run_id = kb.get_task(conn, worker).current_run_id
+ parent = kb.create_task(conn, title="unfinished parent")
+ ready_child = kb.create_task(conn, title="foreign ready child")
+ running_child = kb.create_task(conn, title="foreign running child")
+ assert kb.claim_task(conn, running_child, claimer="other") is not None
+
+ monkeypatch.setenv("HERMES_KANBAN_TASK", worker)
+ monkeypatch.setenv("HERMES_KANBAN_RUN_ID", str(worker_run_id))
+
+ assert kc._cmd_link(argparse.Namespace(
+ parent_id=parent, child_id=ready_child,
+ )) == 0
+ with pytest.raises(ValueError, match="child is already running"):
+ kc._cmd_link(argparse.Namespace(
+ parent_id=parent, child_id=running_child,
+ ))
+
+ with kbc.connect_closing() as conn:
+ assert kb.parent_ids(conn, ready_child) == [parent]
+ assert kb.parent_ids(conn, running_child) == []
+
+
def test_board_override_is_isolated_per_concurrent_call(kanban_home, monkeypatch):
kb.create_board("alpha")
kb.create_board("beta")