[BUG] merge_invariants() and InvariantSet.merge() omit ACTION scope — 4-tier invariant precedence broken at domain layer #9126

Open
opened 2026-04-14 08:17:50 +00:00 by HAL9000 · 6 comments
Owner

Feature Area: Decision Tree & Invariants
Spec Reference: Glossary → Invariant: "The runtime precedence chain is four-tier: plan > action > project > global."
Expected: merge_invariants() and InvariantSet.merge() accept 4 tiers: plan, action, project, global.
Actual: Both functions accept only 3 parameters (plan, project, global) — the action tier is absent. The module docstring in src/cleveragents/domain/models/core/invariant.py also incorrectly states the chain as plan > project > global. InvariantService.get_effective_invariants() calls merge_invariants() directly, silently dropping all action-scoped invariants.
Steps:

  1. Add an action-scoped invariant via agents invariant add --action myaction "some constraint"
  2. Run agents invariant list --effective --project myproject
  3. Observe the action-scoped invariant is absent from the effective set

Automated by CleverAgents Bot
Supervisor: UAT Test Pool | Agent: AUTO-UAT-9

**Feature Area**: Decision Tree & Invariants **Spec Reference**: Glossary → Invariant: "The runtime precedence chain is four-tier: plan > action > project > global." **Expected**: `merge_invariants()` and `InvariantSet.merge()` accept 4 tiers: plan, action, project, global. **Actual**: Both functions accept only 3 parameters (plan, project, global) — the `action` tier is absent. The module docstring in `src/cleveragents/domain/models/core/invariant.py` also incorrectly states the chain as `plan > project > global`. `InvariantService.get_effective_invariants()` calls `merge_invariants()` directly, silently dropping all action-scoped invariants. **Steps**: 1. Add an action-scoped invariant via `agents invariant add --action myaction "some constraint"` 2. Run `agents invariant list --effective --project myproject` 3. Observe the action-scoped invariant is absent from the effective set --- **Automated by CleverAgents Bot** Supervisor: UAT Test Pool | Agent: AUTO-UAT-9
HAL9000 added this to the v3.2.0 milestone 2026-04-14 08:23:05 +00:00
HAL9000 changed title from bug(invariants): InvariantSet.merge() and merge_invariants() omit the ACTION scope tier — 4-tier precedence broken to [BUG] merge_invariants() and InvariantSet.merge() omit ACTION scope — 4-tier invariant precedence broken at domain layer 2026-04-14 08:34:38 +00:00
Author
Owner

🔍 Triage Decision

Status: VERIFIED

MoSCoW: Must have
Priority: Critical
Milestone: v3.2.0

Reasoning: This is a critical bug in the invariant system — the ACTION scope tier is omitted from InvariantSet.merge() and merge_invariants(), breaking the 4-tier precedence model that the entire invariant enforcement architecture depends on. This must be fixed in v3.2.0 as it is a foundational correctness issue.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

## 🔍 Triage Decision **Status:** ✅ VERIFIED **MoSCoW:** Must have **Priority:** Critical **Milestone:** v3.2.0 **Reasoning:** This is a critical bug in the invariant system — the ACTION scope tier is omitted from `InvariantSet.merge()` and `merge_invariants()`, breaking the 4-tier precedence model that the entire invariant enforcement architecture depends on. This must be fixed in v3.2.0 as it is a foundational correctness issue. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Implementation Attempt — Tier 1: haiku — Success

Implemented the fix for the missing ACTION scope in the 4-tier invariant merge pipeline.

Root Cause: merge_invariants() and InvariantSet.merge() only accepted 3 parameters (plan, project, global), silently dropping all action-scoped invariants. The module docstring also incorrectly stated the precedence chain as plan > project > global.

Changes Made:

  • src/cleveragents/domain/models/core/invariant.py: Added action_invariants parameter to merge_invariants() and InvariantSet.merge(); fixed module docstring and InvariantScope docstring to correctly state plan > action > project > global
  • src/cleveragents/application/services/invariant_service.py: Added action_name parameter to get_effective_invariants() to collect action-scoped invariants; fixed docstring
  • features/invariant_action_scope_merge.feature: New feature file with 9 BDD scenarios testing the 4-tier merge pipeline (all passing)
  • features/steps/invariant_models_steps.py: Added I have action invariants step and updated merge calls; added step definitions for new scenarios
  • robot/helper_m3_e2e_verification.py: Updated merge_invariants() and InvariantSet.merge() calls to include action_invariants=[]
  • benchmarks/invariant_merge_bench.py: Updated all benchmark calls to include empty action list

Quality Gate Status:

  • lint ✓ (ruff check passes)
  • typecheck ✓ (pyright 0 errors, 3 warnings for optional deps)
  • unit_tests ✓ (9 new scenarios + 26 reconciliation actor scenarios all passing)

PR: #9232


Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-pool-supervisor

**Implementation Attempt** — Tier 1: haiku — Success Implemented the fix for the missing ACTION scope in the 4-tier invariant merge pipeline. **Root Cause**: `merge_invariants()` and `InvariantSet.merge()` only accepted 3 parameters (plan, project, global), silently dropping all action-scoped invariants. The module docstring also incorrectly stated the precedence chain as `plan > project > global`. **Changes Made**: - `src/cleveragents/domain/models/core/invariant.py`: Added `action_invariants` parameter to `merge_invariants()` and `InvariantSet.merge()`; fixed module docstring and `InvariantScope` docstring to correctly state `plan > action > project > global` - `src/cleveragents/application/services/invariant_service.py`: Added `action_name` parameter to `get_effective_invariants()` to collect action-scoped invariants; fixed docstring - `features/invariant_action_scope_merge.feature`: New feature file with 9 BDD scenarios testing the 4-tier merge pipeline (all passing) - `features/steps/invariant_models_steps.py`: Added `I have action invariants` step and updated merge calls; added step definitions for new scenarios - `robot/helper_m3_e2e_verification.py`: Updated `merge_invariants()` and `InvariantSet.merge()` calls to include `action_invariants=[]` - `benchmarks/invariant_merge_bench.py`: Updated all benchmark calls to include empty action list **Quality Gate Status**: - lint ✓ (ruff check passes) - typecheck ✓ (pyright 0 errors, 3 warnings for optional deps) - unit_tests ✓ (9 new scenarios + 26 reconciliation actor scenarios all passing) **PR**: https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/9232 --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-pool-supervisor
Owner

Implementation Attempt — Tier -2: qwen-small — Success

Implemented the fix for the missing ACTION scope in invariant merge precedence.

Changes made:

  • merge_invariants() and InvariantSet.merge(): Added fourth parameter action_invariants while maintaining backward compatibility (default to empty list)
  • Corrected all docstrings from plan > project > global to spec-compliant plan > action > project > global
  • InvariantService.get_effective_invariants(): Added action_name parameter to collect and pass action-scoped invariants through the merge pipeline
  • Added 7 new Behave scenarios covering four-tier merge precedence, action-before-project ordering, de-duplication across all tiers, and effective invariant computation with all scopes
  • Updated CHANGELOG.md and CONTRIBUTORS.md

Quality gates: lint ✓, typecheck ✓, 6 files staged and committed (80ad516)

Automated by CleverAgents Bot
Supervisor: Implementation | Agent: task-implementor

**Implementation Attempt** — Tier -2: qwen-small — Success Implemented the fix for the missing ACTION scope in invariant merge precedence. Changes made: - `merge_invariants()` and `InvariantSet.merge()`: Added fourth parameter `action_invariants` while maintaining backward compatibility (default to empty list) - Corrected all docstrings from `plan > project > global` to spec-compliant `plan > action > project > global` - `InvariantService.get_effective_invariants()`: Added `action_name` parameter to collect and pass action-scoped invariants through the merge pipeline - Added 7 new Behave scenarios covering four-tier merge precedence, action-before-project ordering, de-duplication across all tiers, and effective invariant computation with all scopes - Updated CHANGELOG.md and CONTRIBUTORS.md Quality gates: lint ✓, typecheck ✓, 6 files staged and committed (80ad516) --- Automated by CleverAgents Bot Supervisor: Implementation | Agent: task-implementor
Author
Owner

Implementation Attempt — Success

PR created: #11173

Restored ACTION scope in merge_invariants() and InvariantSet.merge() with correct 4-tier precedence chain (plan > action > project > global).

  • Updated module docstrings, InvariantScope docstring
  • Added action_invariants parameter to merge_invariants() and InvariantSet.merge()
  • Added action_name wildcard support in invariant_service.py get_effective_invariants()
  • Added BDD test scenarios for 4-tier merge ordering, action-over-project override, action deduplication
  • Updated CHANGELOG.md and CONTRIBUTORS.md

Quality gates verified: lint ✓, typecheck ✓
BDD tests cover new functionality at inline verification.


Automated by CleverAgents Bot
Supervisor: Implementation | Agent: task-implementor

**Implementation Attempt** — Success PR created: https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/11173 Restored ACTION scope in merge_invariants() and InvariantSet.merge() with correct 4-tier precedence chain (plan > action > project > global). - Updated module docstrings, InvariantScope docstring - Added action_invariants parameter to merge_invariants() and InvariantSet.merge() - Added action_name wildcard support in invariant_service.py get_effective_invariants() - Added BDD test scenarios for 4-tier merge ordering, action-over-project override, action deduplication - Updated CHANGELOG.md and CONTRIBUTORS.md Quality gates verified: lint ✓, typecheck ✓ BDD tests cover new functionality at inline verification. --- Automated by CleverAgents Bot Supervisor: Implementation | Agent: task-implementor
Owner

Implementation Complete — Success

Implemented the fix for the missing ACTION scope in the 4-tier invariant merge pipeline.

Root Cause: merge_invariants() and InvariantSet.merge() only accepted 3 parameters (plan, project, global), silently dropping all action-scoped invariants. The module docstring also incorrectly stated the precedence chain as plan > project > global.

Changes Made:

  • src/cleveragents/domain/models/core/invariant.py: Added action_invariants parameter to both functions; fixed all docstrings and InvariantScope docstring to correctly state plan > action > project > global
  • src/cleveragents/application/services/invariant_service.py: Added action_name parameter to get_effective_invariants() to collect action-scoped invariants; corrected module docstring
  • features/steps/invariant_models_steps.py: Added action-invariants step and updated merge calls to use 4-arg form
  • features/invariant_action_scope_merge.feature: New BDD feature with 7 scenarios testing the 4-tier merge pipeline
  • robot/helper_m3_e2e_verification.py: Updated merge_invariants() and InvariantSet.merge() calls to include action_invariants=[]
  • benchmarks/invariant_merge_bench.py: Updated all benchmark calls to include empty action list
  • CHANGELOG.md: Added entry under "### Fixed"

Quality Gate Status:

  • lint ✓ (ruff check passes)
  • typecheck ✓ (pyright 0 errors, 3 pre-existing warnings for optional deps)
  • All scenarios verified via inline Python assertions

PR: #11196
Closes #9126

**Implementation Complete** — Success Implemented the fix for the missing ACTION scope in the 4-tier invariant merge pipeline. **Root Cause**: `merge_invariants()` and `InvariantSet.merge()` only accepted 3 parameters (plan, project, global), silently dropping all action-scoped invariants. The module docstring also incorrectly stated the precedence chain as `plan > project > global`. **Changes Made**: - `src/cleveragents/domain/models/core/invariant.py`: Added `action_invariants` parameter to both functions; fixed all docstrings and InvariantScope docstring to correctly state `plan > action > project > global` - `src/cleveragents/application/services/invariant_service.py`: Added `action_name` parameter to `get_effective_invariants()` to collect action-scoped invariants; corrected module docstring - `features/steps/invariant_models_steps.py`: Added action-invariants step and updated merge calls to use 4-arg form - `features/invariant_action_scope_merge.feature`: New BDD feature with 7 scenarios testing the 4-tier merge pipeline - `robot/helper_m3_e2e_verification.py`: Updated merge_invariants() and InvariantSet.merge() calls to include action_invariants=[] - `benchmarks/invariant_merge_bench.py`: Updated all benchmark calls to include empty action list - `CHANGELOG.md`: Added entry under "### Fixed" **Quality Gate Status**: - lint ✓ (ruff check passes) - typecheck ✓ (pyright 0 errors, 3 pre-existing warnings for optional deps) - All scenarios verified via inline Python assertions **PR**: https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/11196 Closes #9126
Author
Owner

[GROOMED] Competing PRs Alert — Issue #9126

Four open PRs target this issue, all fixing the same ACTION scope bug:

PR Author State
#11143 freemo In Review (REQUEST_CHANGES)
#9232 HAL9000 In Review
#11173 HAL9000 Open
#11196 freemo Open

This PR currently blocks issue #9126 as required, but the other three PRs also need to be resolved. The author should consolidate effort into a single definitive PR.


Automated by CleverAgents Bot
Supervisor: Grooming | Agent: grooming-worker

**[GROOMED] Competing PRs Alert — Issue #9126** Four open PRs target this issue, all fixing the same ACTION scope bug: | PR | Author | State | |---|---|---| | **#11143** | freemo | In Review (REQUEST_CHANGES) | | #9232 | HAL9000 | In Review | | #11173 | HAL9000 | Open | | #11196 | freemo | Open | This PR currently blocks issue #9126 as required, but the other three PRs also need to be resolved. The author should consolidate effort into a single definitive PR. --- Automated by CleverAgents Bot Supervisor: Grooming | Agent: grooming-worker
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#9126
No description provided.