_sanitize_error_message defines _MAX_SANITIZE_INPUT as a local variable instead of a module-level constant #8463

Open
opened 2026-04-13 19:22:31 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit: Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR.
  • Branch: main
  • SHA: 5a9aaa79ed

Background and Context

In src/cleveragents/core/retry_patterns.py, the _sanitize_error_message function defines _MAX_SANITIZE_INPUT = 2000 as a local variable inside the function body. The ALL_CAPS naming convention in Python indicates a module-level constant, and the comment references it as a design decision ("P2-26"), suggesting it was intended to be a module-level constant.

Defining it as a local variable means:

  1. The value is re-created on every function call (minor performance overhead in hot retry paths).
  2. The constant cannot be referenced or overridden from outside the function.
  3. It violates the naming convention: local variables should use snake_case, not UPPER_CASE.
  4. It is inconsistent with other module-level constants in the same file (DEFAULT_MAX_ATTEMPTS, DEFAULT_MIN_WAIT, DEFAULT_MAX_WAIT, DEFAULT_EXPONENTIAL_BASE).

Current Behavior

def _sanitize_error_message(error: BaseException | None) -> str | None:
    ...
    _MAX_SANITIZE_INPUT = 2000   # ← local variable, re-created on every call
    if len(msg) > _MAX_SANITIZE_INPUT:
        msg = msg[:_MAX_SANITIZE_INPUT]

Expected Behavior

_MAX_SANITIZE_INPUT should be defined at module level alongside the other constants:

# Module-level constants
DEFAULT_MAX_ATTEMPTS = 3
DEFAULT_MIN_WAIT = 1
DEFAULT_MAX_WAIT = 60
DEFAULT_EXPONENTIAL_BASE = 2
_MAX_SANITIZE_INPUT = 2000   # ← module-level constant

def _sanitize_error_message(error: BaseException | None) -> str | None:
    ...
    if len(msg) > _MAX_SANITIZE_INPUT:
        msg = msg[:_MAX_SANITIZE_INPUT]

Acceptance Criteria

  • _MAX_SANITIZE_INPUT is defined at module level in retry_patterns.py
  • _sanitize_error_message references the module-level constant
  • The function behaviour is unchanged
  • No existing tests break

Subtasks

  • Move _MAX_SANITIZE_INPUT = 2000 to module level in retry_patterns.py
  • Remove the local variable definition from _sanitize_error_message
  • Verify all tests pass

Definition of Done

The issue is closed when _MAX_SANITIZE_INPUT is a module-level constant in retry_patterns.py, with all tests passing, merged to main.


Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor

## Metadata - **Commit**: Build: Reinforced label enforcement, and ensure implementation workers dont continue work on a mergable PR. - **Branch**: main - **SHA**: 5a9aaa79edaefb1a257114f054ea87facb8efe69 ## Background and Context In `src/cleveragents/core/retry_patterns.py`, the `_sanitize_error_message` function defines `_MAX_SANITIZE_INPUT = 2000` as a **local variable** inside the function body. The ALL_CAPS naming convention in Python indicates a module-level constant, and the comment references it as a design decision ("P2-26"), suggesting it was intended to be a module-level constant. Defining it as a local variable means: 1. The value is re-created on every function call (minor performance overhead in hot retry paths). 2. The constant cannot be referenced or overridden from outside the function. 3. It violates the naming convention: local variables should use `snake_case`, not `UPPER_CASE`. 4. It is inconsistent with other module-level constants in the same file (`DEFAULT_MAX_ATTEMPTS`, `DEFAULT_MIN_WAIT`, `DEFAULT_MAX_WAIT`, `DEFAULT_EXPONENTIAL_BASE`). ## Current Behavior ```python def _sanitize_error_message(error: BaseException | None) -> str | None: ... _MAX_SANITIZE_INPUT = 2000 # ← local variable, re-created on every call if len(msg) > _MAX_SANITIZE_INPUT: msg = msg[:_MAX_SANITIZE_INPUT] ``` ## Expected Behavior `_MAX_SANITIZE_INPUT` should be defined at module level alongside the other constants: ```python # Module-level constants DEFAULT_MAX_ATTEMPTS = 3 DEFAULT_MIN_WAIT = 1 DEFAULT_MAX_WAIT = 60 DEFAULT_EXPONENTIAL_BASE = 2 _MAX_SANITIZE_INPUT = 2000 # ← module-level constant def _sanitize_error_message(error: BaseException | None) -> str | None: ... if len(msg) > _MAX_SANITIZE_INPUT: msg = msg[:_MAX_SANITIZE_INPUT] ``` ## Acceptance Criteria - [ ] `_MAX_SANITIZE_INPUT` is defined at module level in `retry_patterns.py` - [ ] `_sanitize_error_message` references the module-level constant - [ ] The function behaviour is unchanged - [ ] No existing tests break ## Subtasks - [ ] Move `_MAX_SANITIZE_INPUT = 2000` to module level in `retry_patterns.py` - [ ] Remove the local variable definition from `_sanitize_error_message` - [ ] Verify all tests pass ## Definition of Done The issue is closed when `_MAX_SANITIZE_INPUT` is a module-level constant in `retry_patterns.py`, with all tests passing, merged to `main`. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor
Author
Owner

Verified — Code quality issue: _MAX_SANITIZE_INPUT should be a module-level constant. MoSCoW: Could-have. Priority: Low — minor code quality improvement, not blocking.


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

✅ **Verified** — Code quality issue: `_MAX_SANITIZE_INPUT` should be a module-level constant. MoSCoW: Could-have. Priority: Low — minor code quality improvement, not blocking. --- **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#8463
No description provided.