fix(kanban): detect cycles in decompose_triage_task sibling-link pre-validation

decompose_triage_task inlines SQL INSERTs for atomicity and intentionally
bypasses link_tasks() — which calls _would_cycle() per edge.  If the LLM
emits a cyclic parent graph (e.g. A.parents=[1], B.parents=[0]) the DB
write succeeds but every involved child deadlocks in 'todo' forever:
recompute_ready() requires all parents to be done, which is impossible
when A waits for B and B waits for A.

Add a Kahn topological sort over the sibling parent indices in the
pre-validation block, before any DB writes.  Mirrors the cycle-safety
guarantee that link_tasks() provides for manually linked tasks.
This commit is contained in:
EloquentBrush0x 2026-05-18 17:56:23 +03:00 committed by Teknium
parent a86d2ad557
commit 502d03d5a3
2 changed files with 39 additions and 0 deletions

View file

@ -132,6 +132,22 @@ def test_decompose_rejects_out_of_range_parent(kanban_home):
)
def test_decompose_rejects_cyclic_parents(kanban_home):
with kb.connect() as conn:
tid = _create_triage(conn)
with pytest.raises(ValueError, match="cyclic dependency"):
kb.decompose_triage_task(
conn,
tid,
root_assignee="orch",
children=[
{"title": "A", "parents": [1]},
{"title": "B", "parents": [0]},
],
author="me",
)
def test_decompose_records_audit_comment_and_event(kanban_home):
with kb.connect() as conn:
tid = _create_triage(conn)