HKUDS/Vibe-Trading · error · ValueError
DAG contains a cycle: processed {processed}/{len(tasks)} tas
Error message
DAG contains a cycle: processed {processed}/{len(tasks)} tasks What it means
topological_layers uses Kahn's algorithm; if the processed count is less than the total task count, in-degree never reached zero for some tasks, which can only happen when the dependency graph contains a cycle. ValueError reports processed vs total counts.
Source
Thrown at agent/src/swarm/task_store.py:244
)
layers: list[list[str]] = []
processed = 0
while queue:
layer: list[str] = list(queue)
queue.clear()
layers.append(layer)
processed += len(layer)
for tid in layer:
for downstream in dependents[tid]:
in_degree[downstream] -= 1
if in_degree[downstream] == 0:
queue.append(downstream)
if processed != len(tasks):
raise ValueError(
f"DAG contains a cycle: processed {processed}/{len(tasks)} tasks"
)
return layers
View on GitHub (pinned to 80ffdda44c)
Solutions
- Run validate_dag on the same task list to get the exact cycle path and break it
- Audit recently added depends_on entries for backward-pointing edges
- Prevent unvalidated task lists from reaching _execute_run
Example fix
# before topological_layers([t_a_depends_on_b, t_b_depends_on_a]) # after validate_dag(tasks) # run first; fix reported cycle, then: topological_layers([t_a, t_b_depends_on_a])
Defensive patterns
Strategy: validation
Validate before calling
validate_dag(tasks) # raises with exact cycle path before layering layers = topological_layers(tasks)
Try / catch
try:
layers = topological_layers(tasks)
except ValueError as e:
if 'DAG contains a cycle' in str(e): validate_dag(tasks) # get precise path, then fix
else: raise Prevention
- Never let unvalidated task lists reach _execute_run
- Validate at preset load (inspect_preset) and again before scheduling
- Test dynamic task injection paths with cyclic fixtures
When it happens
Trigger: Executing a run (or inspect_preset) whose task set has a circular depends_on chain; validate_dag was skipped so the cycle survived to layering.
Common situations: Hand-edited presets bypassing validation; dynamic task injection at runtime creating a loop.
Related errors
- Cycle detected in task DAG: {' -> '.join(cycle)}
- Task '{task.id}' depends on unknown task '{dep}'
- invalid alpha_id
- alpha_id not found
- invalid period: {exc}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/c861b561b341ba12.
Report an issue: GitHub.