Type Safety Mismatch in ActionArgument.default_value #8254

Open
opened 2026-04-13 06:42:49 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Commit Message: fix(core): validate ActionArgument.default_value against arg_type
  • Branch Name: bugfix/validate-default-value

Background and Context

The ActionArgument model in src/cleveragents/domain/models/core/action.py allows defining arguments for actions. These arguments have a type (arg_type) and an optional default_value.

Currently, the default_value is not validated against its arg_type. This can lead to a situation where an argument of type integer has a default value of "hello", which would cause a TypeError at runtime when the value is used — a silent failure that is difficult to debug and violates the contract of the model.

Expected Behavior

The default_value of an ActionArgument should be validated against its arg_type at construction time to ensure type safety. If the default_value does not match the arg_type, a ValueError should be raised immediately, preventing invalid model states from being created.

Steps to Reproduce:

  1. Create an ActionArgument with a mismatched default_value and arg_type:
    from cleveragents.domain.models.core.action import ActionArgument, ArgumentType
    
    argument = ActionArgument(
        name="test_arg",
        arg_type=ArgumentType.INTEGER,
        default_value="hello",
    )
    
  2. Observe that no error is raised despite the type mismatch.

Acceptance Criteria

  • The default_value of an ActionArgument is validated against its arg_type at construction time.
  • A ValueError is raised if the default_value does not match the arg_type.
  • Validation is skipped when default_value is None (i.e., no default provided).
  • All existing ActionArgument usages in the codebase remain valid after the fix.
  • The validation logic is covered by unit tests for each ArgumentType variant.

Subtasks

  • Audit all ArgumentType variants and define the expected Python type mapping for each.
  • Implement a Pydantic validator (or __post_init__ check) on ActionArgument that validates default_value against arg_type.
  • Raise a descriptive ValueError on mismatch (include arg_type, default_value, and expected type in the message).
  • Scan the codebase for existing ActionArgument instantiations and fix any that would fail the new validation.
  • Write unit tests covering:
    • Valid default_value for each ArgumentType
    • Invalid default_value raises ValueError for each ArgumentType
    • None default_value is always accepted

Definition of Done

This issue should be closed when:

  1. The ActionArgument model raises a ValueError for any default_value that does not match its arg_type.
  2. All existing usages in the codebase are compatible with the new validation.
  3. Unit tests covering valid, invalid, and None default values pass for all ArgumentType variants.
  4. The fix is merged to the target branch with the commit message fix(core): validate ActionArgument.default_value against arg_type.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(core): validate ActionArgument.default_value against arg_type` - **Branch Name**: `bugfix/validate-default-value` ## Background and Context The `ActionArgument` model in `src/cleveragents/domain/models/core/action.py` allows defining arguments for actions. These arguments have a type (`arg_type`) and an optional `default_value`. Currently, the `default_value` is not validated against its `arg_type`. This can lead to a situation where an argument of type `integer` has a default value of `"hello"`, which would cause a `TypeError` at runtime when the value is used — a silent failure that is difficult to debug and violates the contract of the model. ## Expected Behavior The `default_value` of an `ActionArgument` should be validated against its `arg_type` at construction time to ensure type safety. If the `default_value` does not match the `arg_type`, a `ValueError` should be raised immediately, preventing invalid model states from being created. **Steps to Reproduce:** 1. Create an `ActionArgument` with a mismatched `default_value` and `arg_type`: ```python from cleveragents.domain.models.core.action import ActionArgument, ArgumentType argument = ActionArgument( name="test_arg", arg_type=ArgumentType.INTEGER, default_value="hello", ) ``` 2. Observe that no error is raised despite the type mismatch. ## Acceptance Criteria - [ ] The `default_value` of an `ActionArgument` is validated against its `arg_type` at construction time. - [ ] A `ValueError` is raised if the `default_value` does not match the `arg_type`. - [ ] Validation is skipped when `default_value` is `None` (i.e., no default provided). - [ ] All existing `ActionArgument` usages in the codebase remain valid after the fix. - [ ] The validation logic is covered by unit tests for each `ArgumentType` variant. ## Subtasks - [ ] Audit all `ArgumentType` variants and define the expected Python type mapping for each. - [ ] Implement a Pydantic validator (or `__post_init__` check) on `ActionArgument` that validates `default_value` against `arg_type`. - [ ] Raise a descriptive `ValueError` on mismatch (include `arg_type`, `default_value`, and expected type in the message). - [ ] Scan the codebase for existing `ActionArgument` instantiations and fix any that would fail the new validation. - [ ] Write unit tests covering: - Valid `default_value` for each `ArgumentType` - Invalid `default_value` raises `ValueError` for each `ArgumentType` - `None` `default_value` is always accepted ## Definition of Done This issue should be closed when: 1. The `ActionArgument` model raises a `ValueError` for any `default_value` that does not match its `arg_type`. 2. All existing usages in the codebase are compatible with the new validation. 3. Unit tests covering valid, invalid, and `None` default values pass for all `ArgumentType` variants. 4. The fix is merged to the target branch with the commit message `fix(core): validate ActionArgument.default_value against arg_type`. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.2.0 milestone 2026-04-13 06:46:02 +00:00
Author
Owner

[AUTO-EPIC] Epic Linkage

This issue is a child of Epic #8043 — M3 UAT Bug Resolution — Spec Alignment Backlog (v3.2.0).

Type safety issues in ActionArgument.default_value are code quality issues that fall under the M3 UAT bug resolution scope.

Dependency direction: This issue (#8254) BLOCKS Epic #8043.


Automated by CleverAgents Bot
Supervisor: Epic Planning | Agent: epic-planning-pool-supervisor

## [AUTO-EPIC] Epic Linkage This issue is a child of **Epic #8043** — M3 UAT Bug Resolution — Spec Alignment Backlog (v3.2.0). Type safety issues in ActionArgument.default_value are code quality issues that fall under the M3 UAT bug resolution scope. **Dependency direction**: This issue (#8254) BLOCKS Epic #8043. --- **Automated by CleverAgents Bot** Supervisor: Epic Planning | Agent: epic-planning-pool-supervisor
Author
Owner

Verified — Type safety mismatch in ActionArgument.default_value can cause runtime errors. Assigning to v3.2.0 as action schema validation is core functionality. Should Have — important for correctness. Verified.


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

✅ **Verified** — Type safety mismatch in ActionArgument.default_value can cause runtime errors. Assigning to v3.2.0 as action schema validation is core functionality. **Should Have** — important for correctness. Verified. --- **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#8254
No description provided.