BUG-HUNT: [type-safety] Action.validate_arguments accepts bool as INTEGER type due to Python bool/int subclass #6391

Open
opened 2026-04-09 21:00:07 +00:00 by HAL9000 · 0 comments
Owner

Bug Report: [type-safety] — Action.validate_arguments silently accepts bool for INTEGER typed arguments

Severity Assessment

  • Impact: Argument validation passes True/False for INTEGER arguments, allowing semantically wrong values into plan execution (e.g. True is treated as 1, False as 0 in arithmetic without any warning)
  • Likelihood: High — any caller passing a boolean to an integer argument will get no validation error
  • Priority: High

Location

  • File: src/cleveragents/domain/models/core/action.py
  • Function/Class: Action.validate_arguments
  • Lines: 538–566

Description

In Python, bool is a subclass of int, so isinstance(True, int) returns True. The validate_arguments method checks if not isinstance(value, int) for ArgumentType.INTEGER arguments, which silently accepts booleans without flagging them as type errors.

This means that if a caller provides {"count": True} for an INTEGER argument named count, the validation passes with no error, and True flows into the execution context where it is treated as 1. This can cause subtle calculation bugs (e.g., max_retries=True when the user intended a numeric value).

Evidence

# src/cleveragents/domain/models/core/action.py, lines 543-547
if arg.arg_type == ArgumentType.INTEGER:
    if not isinstance(value, int):         # BUG: isinstance(True, int) == True in Python
        errors.append(
            f"Argument {arg.name} must be an integer, got {type_name}"
        )

Python confirmation:

>>> isinstance(True, int)
True
>>> isinstance(False, int)
True
>>> type(True).__name__
'bool'

The validate_arguments call with {"flag_arg": True} where flag_arg is declared as ArgumentType.INTEGER will produce no validation error.

Expected Behavior

validate_arguments should reject boolean values when an argument is declared as INTEGER, since booleans are semantically distinct types. It should produce an error like:

Argument flag_arg must be an integer, got bool

Actual Behavior

validate_arguments returns an empty error list (validation passes) when True or False is provided for an INTEGER-typed argument.

Suggested Fix

Add an explicit bool exclusion before the isinstance(value, int) check:

if arg.arg_type == ArgumentType.INTEGER:
    if isinstance(value, bool) or not isinstance(value, int):
        errors.append(
            f"Argument {arg.name} must be an integer, got {type_name}"
        )

This mirrors the BOOLEAN check later (line 558: if not isinstance(value, bool)) which correctly catches bool type checking.

Category

type-safety

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.


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

## Bug Report: [type-safety] — `Action.validate_arguments` silently accepts `bool` for `INTEGER` typed arguments ### Severity Assessment - **Impact**: Argument validation passes `True`/`False` for INTEGER arguments, allowing semantically wrong values into plan execution (e.g. `True` is treated as `1`, `False` as `0` in arithmetic without any warning) - **Likelihood**: High — any caller passing a boolean to an integer argument will get no validation error - **Priority**: High ### Location - **File**: `src/cleveragents/domain/models/core/action.py` - **Function/Class**: `Action.validate_arguments` - **Lines**: 538–566 ### Description In Python, `bool` is a subclass of `int`, so `isinstance(True, int)` returns `True`. The `validate_arguments` method checks `if not isinstance(value, int)` for `ArgumentType.INTEGER` arguments, which silently accepts booleans without flagging them as type errors. This means that if a caller provides `{"count": True}` for an INTEGER argument named `count`, the validation passes with no error, and `True` flows into the execution context where it is treated as `1`. This can cause subtle calculation bugs (e.g., `max_retries=True` when the user intended a numeric value). ### Evidence ```python # src/cleveragents/domain/models/core/action.py, lines 543-547 if arg.arg_type == ArgumentType.INTEGER: if not isinstance(value, int): # BUG: isinstance(True, int) == True in Python errors.append( f"Argument {arg.name} must be an integer, got {type_name}" ) ``` Python confirmation: ```python >>> isinstance(True, int) True >>> isinstance(False, int) True >>> type(True).__name__ 'bool' ``` The `validate_arguments` call with `{"flag_arg": True}` where `flag_arg` is declared as `ArgumentType.INTEGER` will produce no validation error. ### Expected Behavior `validate_arguments` should reject boolean values when an argument is declared as `INTEGER`, since booleans are semantically distinct types. It should produce an error like: ``` Argument flag_arg must be an integer, got bool ``` ### Actual Behavior `validate_arguments` returns an empty error list (validation passes) when `True` or `False` is provided for an `INTEGER`-typed argument. ### Suggested Fix Add an explicit `bool` exclusion before the `isinstance(value, int)` check: ```python if arg.arg_type == ArgumentType.INTEGER: if isinstance(value, bool) or not isinstance(value, int): errors.append( f"Argument {arg.name} must be an integer, got {type_name}" ) ``` This mirrors the BOOLEAN check later (line 558: `if not isinstance(value, bool)`) which correctly catches bool type checking. ### Category type-safety ### 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. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
HAL9000 added this to the v3.2.0 milestone 2026-04-09 21:09:20 +00:00
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#6391
No description provided.