BUG-HUNT: [critical] Circular reference infinite recursion in shared redaction utility #7062

Open
opened 2026-04-10 07:27:54 +00:00 by HAL9000 · 1 comment
Owner

Bug Report: [error-handling] — Circular reference infinite recursion in shared redaction utility

Severity Assessment

  • Impact: System crash with RecursionError when processing data structures with circular references
  • Likelihood: High in complex applications with interconnected data models
  • Priority: Critical

Location

  • File: src/cleveragents/shared/redaction.py
  • Function/Class: _redact_dict_inner
  • Lines: 99-119

Description

The redact_dict and _redact_dict_inner functions do not track visited objects, leading to infinite recursion when processing dictionaries with circular references.

Evidence

def _redact_dict_inner(data: dict[str, Any]) -> dict[str, Any]:
    """Recursive implementation of dict redaction."""
    result: dict[str, Any] = {}
    for key, value in data.items():
        if is_sensitive_key(key):
            result[key] = REDACTED
        elif isinstance(value, dict):
            result[key] = _redact_dict_inner(value)  # No cycle detection
        # ... rest of function

Test case demonstrating the bug:

d = {'a': 1}
d['self'] = d  # Create circular reference
redact_dict(d)  # Raises RecursionError

Expected Behavior

The function should detect circular references and handle them gracefully, either by replacing with a placeholder or by maintaining a visited set.

Actual Behavior

The function recurses infinitely until Python's recursion limit is reached, causing a RecursionError.

Suggested Fix

Implement cycle detection using a visited set:

def redact_dict(data, *, show_secrets=None, _visited=None):
    if _visited is None:
        _visited = set()
    obj_id = id(data)
    if obj_id in _visited:
        return {"***CIRCULAR_REFERENCE***": "***REDACTED***"}
    _visited.add(obj_id)
    # ... rest of logic with _visited passed to recursive calls
    _visited.remove(obj_id)

Category

error-handling

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_, and @tdd_expected_fail to prove the bug exists before fixing it.

[Bug Hunt Cycle 2 Batch 3]

Discovered by: Worker 17 Shared Utilities
Module Focus: Cross-cutting helper components


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter

## Bug Report: [error-handling] — Circular reference infinite recursion in shared redaction utility ### Severity Assessment - **Impact**: System crash with RecursionError when processing data structures with circular references - **Likelihood**: High in complex applications with interconnected data models - **Priority**: Critical ### Location - **File**: `src/cleveragents/shared/redaction.py` - **Function/Class**: `_redact_dict_inner` - **Lines**: 99-119 ### Description The `redact_dict` and `_redact_dict_inner` functions do not track visited objects, leading to infinite recursion when processing dictionaries with circular references. ### Evidence ```python def _redact_dict_inner(data: dict[str, Any]) -> dict[str, Any]: """Recursive implementation of dict redaction.""" result: dict[str, Any] = {} for key, value in data.items(): if is_sensitive_key(key): result[key] = REDACTED elif isinstance(value, dict): result[key] = _redact_dict_inner(value) # No cycle detection # ... rest of function ``` **Test case demonstrating the bug:** ```python d = {'a': 1} d['self'] = d # Create circular reference redact_dict(d) # Raises RecursionError ``` ### Expected Behavior The function should detect circular references and handle them gracefully, either by replacing with a placeholder or by maintaining a visited set. ### Actual Behavior The function recurses infinitely until Python's recursion limit is reached, causing a RecursionError. ### Suggested Fix Implement cycle detection using a visited set: ```python def redact_dict(data, *, show_secrets=None, _visited=None): if _visited is None: _visited = set() obj_id = id(data) if obj_id in _visited: return {"***CIRCULAR_REFERENCE***": "***REDACTED***"} _visited.add(obj_id) # ... rest of logic with _visited passed to recursive calls _visited.remove(obj_id) ``` ### Category error-handling ### 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. ### [Bug Hunt Cycle 2 Batch 3] **Discovered by:** Worker 17 Shared Utilities **Module Focus:** Cross-cutting helper components --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
Author
Owner

Verified — Critical bug: circular reference infinite recursion in shared redaction utility. MoSCoW: Must-have. Priority: Critical.


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

✅ **Verified** — Critical bug: circular reference infinite recursion in shared redaction utility. 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#7062
No description provided.