BUG-HUNT: [validation] ResourceTypeSpec inheritance cycle detection only catches direct self-inheritance #7093

Open
opened 2026-04-10 07:40:13 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Branch: bugfix/m6-resource-type-inheritance-cycle-detection
  • Commit Message: fix(validation): detect multi-step inheritance cycles in ResourceTypeSpec
  • Milestone: v3.6.0
  • Parent Epic: (see orphan note below)

Bug Report: [Validation] — Incomplete inheritance cycle detection

Severity Assessment

  • Impact: Complex inheritance cycles (A→B→A) could cause infinite recursion during type resolution, leading to stack overflow crashes
  • Likelihood: Low but catastrophic - occurs when users define custom resource types with circular inheritance chains
  • Priority: Critical

Location

  • File: src/cleveragents/domain/models/core/resource_type.py
  • Function/Class: ResourceTypeSpec._validate_model()
  • Lines: ~290-295

Description

The inheritance validation only checks for direct self-inheritance (inherits == self.name) but doesn't detect longer inheritance cycles like A inherits from B, B inherits from A, or A→B→C→A chains.

Evidence

# ADR-042 rule 3: no cycles (self-inheritance)
if self.inherits is not None and self.inherits == self.name:
    raise ValueError(f"'{self.name}' cannot inherit from itself.")

This only catches single-step cycles but misses multi-step cycles.

Expected Behavior

The validation should detect all inheritance cycles regardless of length, preventing infinite recursion during type resolution or capability inheritance traversal.

Actual Behavior

Multi-step inheritance cycles are not detected at validation time, allowing creation of resource type configurations that will cause runtime failures (stack overflow) when the inheritance chain is traversed.

Suggested Fix

Implement a cycle detection algorithm that traverses the full inheritance chain during validation, such as using a visited set or Floyd's cycle detection algorithm.

Category

validation

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it.


Subtasks

  • Confirm bug is reproducible: create two custom resource types where A inherits B and B inherits A, verify no ValueError is raised at construction time
  • Implement multi-step cycle detection in ResourceTypeSpec._validate_model() using a visited-set traversal over the full inheritance chain
  • Ensure the fix handles chains of arbitrary length (A→B→C→…→A)
  • Ensure the fix does not regress the existing direct self-inheritance check
  • Update/add unit tests in the resource type model test suite
  • TDD: Create Type/Testing issue and tdd/m6-resource-type-inheritance-cycle-detection branch with @tdd_expected_fail tagged scenario
  • Remove @tdd_expected_fail tag on bug fix branch once fix is implemented
  • Run nox (all default sessions), fix any errors
  • Verify coverage ≥ 97% via nox -s coverage_report

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (fix(validation): detect multi-step inheritance cycles in ResourceTypeSpec), followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (bugfix/m6-resource-type-inheritance-cycle-detection).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • A corresponding Type/Testing TDD issue has been created, its tdd/ branch merged, and the @tdd_expected_fail tag removed by this fix.
  • All nox stages pass.
  • Coverage ≥ 97%.

Orphan note: No open Type/Epic parent was found for resource type validation work at issue creation time. This issue must be manually linked to the appropriate parent Epic by a maintainer before it moves to State/Verified.


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunter | Agent: new-issue-creator

## Metadata - **Branch**: `bugfix/m6-resource-type-inheritance-cycle-detection` - **Commit Message**: `fix(validation): detect multi-step inheritance cycles in ResourceTypeSpec` - **Milestone**: v3.6.0 - **Parent Epic**: *(see orphan note below)* --- ## Bug Report: [Validation] — Incomplete inheritance cycle detection ### Severity Assessment - **Impact**: Complex inheritance cycles (A→B→A) could cause infinite recursion during type resolution, leading to stack overflow crashes - **Likelihood**: Low but catastrophic - occurs when users define custom resource types with circular inheritance chains - **Priority**: Critical ### Location - **File**: `src/cleveragents/domain/models/core/resource_type.py` - **Function/Class**: `ResourceTypeSpec._validate_model()` - **Lines**: ~290-295 ### Description The inheritance validation only checks for direct self-inheritance (`inherits == self.name`) but doesn't detect longer inheritance cycles like A inherits from B, B inherits from A, or A→B→C→A chains. ### Evidence ```python # ADR-042 rule 3: no cycles (self-inheritance) if self.inherits is not None and self.inherits == self.name: raise ValueError(f"'{self.name}' cannot inherit from itself.") ``` This only catches single-step cycles but misses multi-step cycles. ### Expected Behavior The validation should detect all inheritance cycles regardless of length, preventing infinite recursion during type resolution or capability inheritance traversal. ### Actual Behavior Multi-step inheritance cycles are not detected at validation time, allowing creation of resource type configurations that will cause runtime failures (stack overflow) when the inheritance chain is traversed. ### Suggested Fix Implement a cycle detection algorithm that traverses the full inheritance chain during validation, such as using a visited set or Floyd's cycle detection algorithm. ### Category validation ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. --- ## Subtasks - [ ] Confirm bug is reproducible: create two custom resource types where A inherits B and B inherits A, verify no `ValueError` is raised at construction time - [ ] Implement multi-step cycle detection in `ResourceTypeSpec._validate_model()` using a visited-set traversal over the full inheritance chain - [ ] Ensure the fix handles chains of arbitrary length (A→B→C→…→A) - [ ] Ensure the fix does not regress the existing direct self-inheritance check - [ ] Update/add unit tests in the resource type model test suite - [ ] TDD: Create `Type/Testing` issue and `tdd/m6-resource-type-inheritance-cycle-detection` branch with `@tdd_expected_fail` tagged scenario - [ ] Remove `@tdd_expected_fail` tag on bug fix branch once fix is implemented - [ ] Run `nox` (all default sessions), fix any errors - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`fix(validation): detect multi-step inheritance cycles in ResourceTypeSpec`), followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`bugfix/m6-resource-type-inheritance-cycle-detection`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - A corresponding `Type/Testing` TDD issue has been created, its `tdd/` branch merged, and the `@tdd_expected_fail` tag removed by this fix. - All nox stages pass. - Coverage ≥ 97%. --- > **Orphan note:** No open `Type/Epic` parent was found for resource type validation work at issue creation time. This issue must be manually linked to the appropriate parent Epic by a maintainer before it moves to `State/Verified`. --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunter | Agent: new-issue-creator
HAL9000 added this to the v3.6.0 milestone 2026-04-10 07:40:22 +00:00
Author
Owner

⚠️ Orphan Issue — Needs Parent Epic Link

This issue was created by an automated bug hunter and no suitable open Type/Epic parent was found for resource type validation work at creation time.

Per CONTRIBUTING.md, all non-Epic/non-Legendary issues must be linked to a parent Epic via Forgejo's dependency system (child blocks parent). A maintainer must:

  1. Identify or create the appropriate parent Epic for ResourceTypeSpec validation work (e.g., a "Resource Type Domain Model" or "Validation" Epic).
  2. Open this issue and add the parent Epic under "blocks", OR open the parent Epic and add this issue under "depends on".

This issue should not be moved to State/Verified until the parent link is established.


Automated by CleverAgents Bot
Supervisor: Acting on behalf of: Bug Hunter | Agent: new-issue-creator

⚠️ **Orphan Issue — Needs Parent Epic Link** This issue was created by an automated bug hunter and no suitable open `Type/Epic` parent was found for resource type validation work at creation time. Per CONTRIBUTING.md, all non-Epic/non-Legendary issues must be linked to a parent Epic via Forgejo's dependency system (child **blocks** parent). A maintainer must: 1. Identify or create the appropriate parent Epic for `ResourceTypeSpec` validation work (e.g., a "Resource Type Domain Model" or "Validation" Epic). 2. Open this issue and add the parent Epic under **"blocks"**, OR open the parent Epic and add this issue under **"depends on"**. This issue should **not** be moved to `State/Verified` until the parent link is established. --- **Automated by CleverAgents Bot** Supervisor: Acting on behalf of: Bug Hunter | Agent: new-issue-creator
Author
Owner

Verified — Critical validation bug: ResourceTypeSpec cycle detection incomplete. MoSCoW: Must-have. Priority: Critical.


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

✅ **Verified** — Critical validation bug: ResourceTypeSpec cycle detection incomplete. MoSCoW: Must-have. Priority: Critical. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
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#7093
No description provided.