Bug: SandboxManager.get_or_create_sandbox_for_resource() uses # type: ignore[assignment] — violates no-type-suppression rule #4020

Open
opened 2026-04-06 08:40:39 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/sandbox-manager-type-ignore-removal
  • Commit Message: fix(sandbox): remove type: ignore[assignment] in get_or_create_sandbox_for_resource
  • Milestone: (none — backlog)
  • Parent Epic: #397

Background

SandboxManager.get_or_create_sandbox_for_resource() in src/cleveragents/infrastructure/sandbox/manager.py uses a # type: ignore[assignment] comment on line 618, which violates the project's strict no-type-suppression rule.

Code location: src/cleveragents/infrastructure/sandbox/manager.py, line 618:

# Determine strategy from the boundary resource.
strategy: SandboxStrategyStr = "none"
if boundary_resource.sandbox_strategy is not None:
    strategy = boundary_resource.sandbox_strategy  # type: ignore[assignment]

Per CONTRIBUTING.md: "The use of # type: ignore or any other mechanism to suppress or disable type checking is strictly forbidden."

The type error occurs because boundary_resource.sandbox_strategy is typed as SandboxStrategy | None (a domain enum), while strategy is typed as SandboxStrategyStr (a Literal type alias for string values). These types are structurally compatible (both are string-based) but Pyright cannot verify the assignment without an explicit cast or type narrowing.

Actual behavior: The # type: ignore[assignment] suppresses a legitimate type mismatch that should be resolved properly. The SandboxStrategy enum values should be explicitly cast to SandboxStrategyStr using a proper type-safe conversion.

Fix approach:

if boundary_resource.sandbox_strategy is not None:
    strategy = cast(SandboxStrategyStr, boundary_resource.sandbox_strategy.value)

Or define a proper conversion function from SandboxStrategy enum to SandboxStrategyStr.

Backlog note: This issue was discovered during autonomous operation
on milestone v3.5.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.

Subtasks

  • Write a failing Behave scenario that exercises get_or_create_sandbox_for_resource() with a resource that has a non-None sandbox_strategy
  • Remove the # type: ignore[assignment] comment from manager.py line 618
  • Add a proper type-safe conversion from SandboxStrategy enum to SandboxStrategyStr (e.g., using cast() or .value)
  • Verify nox -e typecheck passes with 0 errors
  • Verify nox -e unit_tests passes
  • Verify nox -e coverage_report shows coverage >= 97%
  • Verify all nox quality gates pass

Definition of Done

  • All subtasks above are checked off
  • No # type: ignore comment remains in manager.py
  • nox -e typecheck passes with 0 errors
  • All nox stages pass
  • Coverage >= 97%
  • A Git commit is created with the exact first line: fix(sandbox): remove type: ignore[assignment] in get_or_create_sandbox_for_resource
  • The commit is pushed to branch fix/sandbox-manager-type-ignore-removal
  • A pull request is submitted, reviewed, and merged

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/sandbox-manager-type-ignore-removal` - **Commit Message**: `fix(sandbox): remove type: ignore[assignment] in get_or_create_sandbox_for_resource` - **Milestone**: *(none — backlog)* - **Parent Epic**: #397 ## Background `SandboxManager.get_or_create_sandbox_for_resource()` in `src/cleveragents/infrastructure/sandbox/manager.py` uses a `# type: ignore[assignment]` comment on line 618, which violates the project's strict no-type-suppression rule. **Code location**: `src/cleveragents/infrastructure/sandbox/manager.py`, line 618: ```python # Determine strategy from the boundary resource. strategy: SandboxStrategyStr = "none" if boundary_resource.sandbox_strategy is not None: strategy = boundary_resource.sandbox_strategy # type: ignore[assignment] ``` Per CONTRIBUTING.md: *"The use of `# type: ignore` or any other mechanism to suppress or disable type checking is strictly forbidden."* The type error occurs because `boundary_resource.sandbox_strategy` is typed as `SandboxStrategy | None` (a domain enum), while `strategy` is typed as `SandboxStrategyStr` (a `Literal` type alias for string values). These types are structurally compatible (both are string-based) but Pyright cannot verify the assignment without an explicit cast or type narrowing. **Actual behavior**: The `# type: ignore[assignment]` suppresses a legitimate type mismatch that should be resolved properly. The `SandboxStrategy` enum values should be explicitly cast to `SandboxStrategyStr` using a proper type-safe conversion. **Fix approach**: ```python if boundary_resource.sandbox_strategy is not None: strategy = cast(SandboxStrategyStr, boundary_resource.sandbox_strategy.value) ``` Or define a proper conversion function from `SandboxStrategy` enum to `SandboxStrategyStr`. > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.5.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ## Subtasks - [ ] Write a failing Behave scenario that exercises `get_or_create_sandbox_for_resource()` with a resource that has a non-None `sandbox_strategy` - [ ] Remove the `# type: ignore[assignment]` comment from `manager.py` line 618 - [ ] Add a proper type-safe conversion from `SandboxStrategy` enum to `SandboxStrategyStr` (e.g., using `cast()` or `.value`) - [ ] Verify `nox -e typecheck` passes with 0 errors - [ ] Verify `nox -e unit_tests` passes - [ ] Verify `nox -e coverage_report` shows coverage >= 97% - [ ] Verify all nox quality gates pass ## Definition of Done - [ ] All subtasks above are checked off - [ ] No `# type: ignore` comment remains in `manager.py` - [ ] `nox -e typecheck` passes with 0 errors - [ ] All nox stages pass - [ ] Coverage >= 97% - [ ] A Git commit is created with the exact first line: `fix(sandbox): remove type: ignore[assignment] in get_or_create_sandbox_for_resource` - [ ] The commit is pushed to branch `fix/sandbox-manager-type-ignore-removal` - [ ] A pull request is submitted, reviewed, and merged --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:11:58 +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.

Blocks
#397 Epic: Server & Autonomy Infrastructure
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#4020
No description provided.