Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ All notable changes to this project are documented here. The format follows
`invalid_document` errors name these roots. Old rubric history stays readable.

### Fixed
- Core validation: the dependency-cycle check (`ARA110`, 0.1.33) orients
`also_depends_on` edges from dependency to dependent, the same direction as
`children:` nesting. A cross-branch diamond, such as a node depending on a
node elsewhere that itself depends on an ancestor, is no longer reported as
a cycle and no longer makes `ls`, `find` and `status` refuse the artifact.
A node that depends on its own descendant is now reported as a cycle.
- Core reads: `logic/experiments.md`, `logic/solution/heuristics.md` and
`logic/problem.md` that open with a stray, unclosed `---` line before a
level-one title and typed entries (`## E01: …`, `## H01: …`, `### O1: …`)
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]

[workspace.package]
version = "0.1.32"
version = "0.1.33"
edition = "2024"
license = "MPL-2.0"
repository = "https://github.com/ARA-Labs/ara-cli"
Expand Down
63 changes: 56 additions & 7 deletions crates/ara-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,10 @@ pub(crate) fn parse_sources_detailed_with_claim_redirects(
// dedupe links.
//
// A dependency whose target is an *ancestor* of the source (reachable by
// walking `children:` nesting upward) merely restates the nesting: it is
// redundant, and combined with the parent→child edge it would close a cycle
// and fail the whole artifact. Real traces do this (a child re-declaring a
// dependency on its parent), so drop the redundant edge with a warning
// instead. Genuine cross-cycles — a dependency on a sibling or descendant
// that closes a loop — are not ancestors and stay fatal in `detect_cycles`.
// walking `children:` nesting upward) merely restates the nesting. Real
// traces do this (a child re-declaring a dependency on its parent), so drop
// the redundant edge with a warning. Genuine cycles — a dependency loop, or
// a dependency on one's own descendant — stay fatal in `detect_cycles`.
let parent_of: BTreeMap<NodeId, NodeId> = norm
.child_links
.iter()
Expand Down Expand Up @@ -1200,12 +1198,21 @@ fn dedupe_links(links: Vec<Link>, report: &mut ParseReport) -> Vec<Link> {

/// Reports a cycle error for every back-edge in the combined
/// `Child` + `DependsOn` graph (DFS three-color).
///
/// A `Child` link points downstream (parent to child) while a `DependsOn` link
/// points upstream (dependent to dependency), so dependency edges are reversed
/// here. Mixing the two directions would report a cross-branch diamond as a
/// cycle and miss a node that depends on its own descendant.
fn detect_cycles(nodes: &[Node], links: &[Link], report: &mut ParseReport) {
// BTreeMap (not HashMap) keeps traversal — and thus error ordering — free of
// any hash-seed influence, matching the crate's determinism guarantee.
let mut adj: BTreeMap<&NodeId, Vec<&NodeId>> = BTreeMap::new();
for link in links {
adj.entry(&link.from).or_default().push(&link.to);
let (upstream, downstream) = match link.kind {
LinkKind::DependsOn => (&link.to, &link.from),
_ => (&link.from, &link.to),
};
adj.entry(upstream).or_default().push(downstream);
}
let mut color: BTreeMap<&NodeId, u8> = BTreeMap::new(); // 0=white, 1=gray, 2=black
let mut stack = Vec::new();
Expand Down Expand Up @@ -1609,6 +1616,48 @@ tree:
assert!(err.errors().iter().any(|d| d.message.contains("cycle")));
}

#[test]
fn dependency_diamond_across_branches_is_not_a_cycle() {
// N01 -> N02 -> N03 by nesting, and N01 -> N04 -> N03 by dependencies:
// N04 depends on N01 and N03 depends on N04. Every edge points
// downstream, so this is a diamond, not a loop.
let yaml = "\
tree:
- id: N01
type: question
children:
- id: N02
type: experiment
children:
- id: N03
type: decision
also_depends_on: [N04]
- id: N04
type: experiment
also_depends_on: [N01]
";
let (m, report) = parse_sources(yaml, None).expect("a diamond is not a cycle");
assert!(report.is_ok(), "must not error: {report}");
assert_eq!(m.nodes.len(), 4);
}

#[test]
fn dependency_on_own_descendant_is_a_cycle() {
// N01 nests N02 and also depends on it: N01 is upstream and downstream
// of N02 at once.
let yaml = "\
tree:
- id: N01
type: question
also_depends_on: [N02]
children:
- id: N02
type: experiment
";
let err = parse_sources(yaml, None).unwrap_err();
assert!(err.errors().iter().any(|d| d.message.contains("cycle")));
}

#[test]
fn redundant_ancestor_depends_on_is_dropped_with_warning() {
// A child that re-declares `also_depends_on` on its own parent restates
Expand Down
26 changes: 26 additions & 0 deletions docs/dependency-cycle-direction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dependency cycle check mixes edge directions

**Date:** 2026-10-15. Implemented in 0.1.33.

## Problem

`detect_cycles` (`crates/ara-core/src/parse.rs`) runs one DFS over `Child` and `DependsOn` links. A `Child` link points from parent to child, which is downstream. A `DependsOn` link points from the dependent node to its dependency, which is upstream. Mixing the two directions gives wrong answers both ways:

- **False positive.** A diamond is reported as a cycle. If X nests A, A nests C, B depends on X and C depends on B, the mixed graph has the loop X → A → C → B → X, although every edge runs downstream. `ara check` fails with ARA110, and `ls`, `find` and `status` refuse the artifact (`invalid_artifact`).
- **False negative.** A node that depends on its own descendant is a real cycle, but its `Child` and `DependsOn` links point the same way, so it is not reported.

The ancestor-dependency warning (ARA208) was added for one false-positive shape, a child depending on its own ancestor. It does not cover dependencies that reach an ancestor through another branch.

## Evidence

The ara-eval large-artifact survey found ARA110 on 54 of 127 internal trees, and on the current `main` of Lara-dev and sierra. In every one of the 56, the graph has no cycle once edges are oriented consistently. A local build with the fix below made 24 of them readable; the rest are blocked by unrelated ARA217 diagnostics.

## Design

In `detect_cycles` only, orient `DependsOn` links from dependency to dependent, the same direction as `Child` links. Link data, layout and viewer edges are unchanged. The ARA208 warning and its edge drop stay as they are, because the edge is still redundant.

## Verification

- `dependency_diamond_across_branches_is_not_a_cycle` and `dependency_on_own_descendant_is_a_cycle` in `parse.rs` failed before the change and pass after it. The existing cycle tests (`cycle_is_detected`, `sibling_only_depends_on_cycle_is_detected`, the ARA208 ancestor test) are unchanged and pass.
- The full workspace test suite, `cargo fmt --check` and `cargo clippy -D warnings` pass.
- On the 58 internal trees that reported ARA110 under 0.1.32, the 0.1.33 build reports none.