feat(decision): implement influence DAG traversal in correction affected subtree computation #556

Merged
freemo merged 1 commit from feature/m5-influence-dag-traversal into master 2026-03-04 15:46:55 +00:00
Owner

Summary

  • Extended CorrectionService._compute_affected_subtree() to BFS over both the structural tree (parent-child) and influence DAG (decision_dependencies edges), computing the union of all transitively affected decisions as specified in § Affected Subtree Computation (lines 28359-28391).
  • Added cycle detection guard via visited set — corrupt DAG cycles are handled gracefully with a warning log rather than infinite loops.
  • Updated DecisionService.record_decision() to accept dependency_decision_ids for recording influence relationships during decision creation, populating the influence DAG.
  • Added DecisionService.get_influence_edges() to retrieve the influence DAG as an adjacency list.
  • All public CorrectionService methods (analyze_impact, execute_revert, execute_correction, generate_dry_run_report) now accept an optional influence_edges parameter (backward-compatible, defaults to None).

Key Design Decisions

  • Single BFS pass over union of edges: Rather than separate traversals for structural tree and influence DAG, one BFS pass unions both edge sources. This ensures O(V+E) complexity and consistent visit order.
  • Cycle detection via visited set: The visited set prevents revisiting nodes. A warning is logged when a cycle is detected (indicating data corruption), but the BFS terminates cleanly.
  • Influence edge logging: Traversal emits count of influence edges processed for observability.
  • Backward-compatible API: Existing callers that only pass decision_tree without influence_edges continue to work identically.

Test Results

  • Behave BDD: 257 features passed, 8145 scenarios passed, 31446 steps passed — 0 failures, 0 errors
  • Robot Framework: 1120 passed, 23 failed (all 23 failures are pre-existing, unrelated to this change; our 6 new tests all pass)
  • Coverage: 97.0% (threshold: 97%)
  • Lint: All checks passed (ruff)
  • Typecheck: 0 errors, 0 warnings (pyright strict)

Files Changed

  • src/cleveragents/application/services/correction_service.py — Extended _compute_affected_subtree() and public method signatures
  • src/cleveragents/application/services/decision_service.py — Added dependency_decision_ids, _record_dependencies(), get_influence_edges()
  • features/influence_dag_traversal.feature — 11 BDD scenarios
  • features/steps/influence_dag_traversal_steps.py — Step implementations
  • robot/influence_dag_traversal.robot — 6 Robot Framework integration tests
  • robot/helper_influence_dag_traversal.py — Robot helper script
  • benchmarks/influence_dag_bench.py — ASV benchmarks for traversal performance
  • CHANGELOG.md — Changelog entry

Closes #542

## Summary - Extended `CorrectionService._compute_affected_subtree()` to BFS over both the structural tree (parent-child) and influence DAG (`decision_dependencies` edges), computing the union of all transitively affected decisions as specified in § Affected Subtree Computation (lines 28359-28391). - Added cycle detection guard via visited set — corrupt DAG cycles are handled gracefully with a warning log rather than infinite loops. - Updated `DecisionService.record_decision()` to accept `dependency_decision_ids` for recording influence relationships during decision creation, populating the influence DAG. - Added `DecisionService.get_influence_edges()` to retrieve the influence DAG as an adjacency list. - All public `CorrectionService` methods (`analyze_impact`, `execute_revert`, `execute_correction`, `generate_dry_run_report`) now accept an optional `influence_edges` parameter (backward-compatible, defaults to `None`). ## Key Design Decisions - **Single BFS pass over union of edges**: Rather than separate traversals for structural tree and influence DAG, one BFS pass unions both edge sources. This ensures O(V+E) complexity and consistent visit order. - **Cycle detection via visited set**: The visited set prevents revisiting nodes. A warning is logged when a cycle is detected (indicating data corruption), but the BFS terminates cleanly. - **Influence edge logging**: Traversal emits count of influence edges processed for observability. - **Backward-compatible API**: Existing callers that only pass `decision_tree` without `influence_edges` continue to work identically. ## Test Results - **Behave BDD**: 257 features passed, 8145 scenarios passed, 31446 steps passed — 0 failures, 0 errors - **Robot Framework**: 1120 passed, 23 failed (all 23 failures are pre-existing, unrelated to this change; our 6 new tests all pass) - **Coverage**: 97.0% (threshold: 97%) - **Lint**: All checks passed (ruff) - **Typecheck**: 0 errors, 0 warnings (pyright strict) ## Files Changed - `src/cleveragents/application/services/correction_service.py` — Extended `_compute_affected_subtree()` and public method signatures - `src/cleveragents/application/services/decision_service.py` — Added `dependency_decision_ids`, `_record_dependencies()`, `get_influence_edges()` - `features/influence_dag_traversal.feature` — 11 BDD scenarios - `features/steps/influence_dag_traversal_steps.py` — Step implementations - `robot/influence_dag_traversal.robot` — 6 Robot Framework integration tests - `robot/helper_influence_dag_traversal.py` — Robot helper script - `benchmarks/influence_dag_bench.py` — ASV benchmarks for traversal performance - `CHANGELOG.md` — Changelog entry Closes #542
freemo added this to the v3.4.0 milestone 2026-03-04 04:22:35 +00:00
freemo force-pushed feature/m5-influence-dag-traversal from 7a7db52be5
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 15s
CI / quality (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 27s
CI / security (pull_request) Successful in 33s
CI / typecheck (pull_request) Successful in 34s
CI / unit_tests (pull_request) Successful in 2m21s
CI / docker (pull_request) Successful in 42s
CI / integration_tests (pull_request) Successful in 3m20s
CI / coverage (pull_request) Successful in 4m8s
CI / benchmark-regression (pull_request) Successful in 26m26s
to 8e6642e8c9
All checks were successful
CI / lint (pull_request) Successful in 13s
CI / typecheck (pull_request) Successful in 31s
CI / security (pull_request) Successful in 32s
CI / quality (pull_request) Successful in 15s
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 1m17s
CI / integration_tests (pull_request) Successful in 2m50s
CI / coverage (pull_request) Successful in 4m16s
CI / unit_tests (pull_request) Successful in 6m28s
CI / docker (pull_request) Successful in 39s
CI / lint (push) Successful in 12s
CI / typecheck (push) Successful in 31s
CI / security (push) Successful in 29s
CI / quality (push) Successful in 15s
CI / build (push) Successful in 21s
CI / unit_tests (push) Successful in 2m11s
CI / benchmark-regression (push) Has been skipped
CI / docker (push) Successful in 40s
CI / integration_tests (push) Successful in 2m58s
CI / coverage (push) Successful in 6m20s
CI / benchmark-publish (push) Successful in 14m5s
CI / benchmark-regression (pull_request) Successful in 33m18s
2026-03-04 15:36:35 +00:00
Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-03-04 15:36:47 +00:00
freemo merged commit 8e6642e8c9 into master 2026-03-04 15:46:55 +00:00
freemo deleted branch feature/m5-influence-dag-traversal 2026-03-04 15:46:56 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core!556
No description provided.