Missing KeyError handling in get_or_create_sandbox_for_resource #10548

Open
opened 2026-04-18 17:08:46 +00:00 by HAL9000 · 0 comments
Owner

Metadata

Commit: Latest commit in repository
Branch: main

Background and Context

The get_or_create_sandbox_for_resource method in src/cleveragents/infrastructure/sandbox/manager.py (line 614) accesses the resource_registry dictionary without checking if the boundary resource ID exists. This can occur when the resource registry is incomplete or corrupted, or when resolve_sandbox_key() returns a boundary ID that hasn't been registered yet.

Expected Behavior

When a boundary resource ID is not found in the registry, the method should:

  1. Detect the missing resource gracefully
  2. Raise a clear, descriptive error message
  3. Allow the caller to handle the error appropriately
  4. Provide debugging information about which resource ID was missing

Acceptance Criteria

  • get_or_create_sandbox_for_resource checks if boundary_id exists in resource_registry before accessing it
  • A descriptive ValueError is raised with the missing boundary ID when the resource is not found
  • Error message includes the boundary ID and context for debugging
  • Unit tests verify the error handling path
  • No unhandled KeyError exceptions are raised from this method
  • Integration tests confirm sandbox creation fails gracefully with missing resources

Subtasks

  • Add null/existence check for boundary_resource lookup
  • Replace direct dictionary access with .get() method
  • Implement proper error handling with descriptive message
  • Add unit tests for missing boundary resource scenario
  • Add integration tests for resource registry corruption scenarios
  • Update error handling documentation

Definition of Done

This issue is complete when:

  1. The KeyError exception is no longer possible from this code path
  2. A clear ValueError with descriptive message is raised instead
  3. All unit and integration tests pass
  4. Code review approved
  5. Changes merged to main branch

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit:** Latest commit in repository **Branch:** main ## Background and Context The `get_or_create_sandbox_for_resource` method in `src/cleveragents/infrastructure/sandbox/manager.py` (line 614) accesses the `resource_registry` dictionary without checking if the boundary resource ID exists. This can occur when the resource registry is incomplete or corrupted, or when `resolve_sandbox_key()` returns a boundary ID that hasn't been registered yet. ## Expected Behavior When a boundary resource ID is not found in the registry, the method should: 1. Detect the missing resource gracefully 2. Raise a clear, descriptive error message 3. Allow the caller to handle the error appropriately 4. Provide debugging information about which resource ID was missing ## Acceptance Criteria - [ ] `get_or_create_sandbox_for_resource` checks if `boundary_id` exists in `resource_registry` before accessing it - [ ] A descriptive `ValueError` is raised with the missing boundary ID when the resource is not found - [ ] Error message includes the boundary ID and context for debugging - [ ] Unit tests verify the error handling path - [ ] No unhandled `KeyError` exceptions are raised from this method - [ ] Integration tests confirm sandbox creation fails gracefully with missing resources ## Subtasks - [ ] Add null/existence check for `boundary_resource` lookup - [ ] Replace direct dictionary access with `.get()` method - [ ] Implement proper error handling with descriptive message - [ ] Add unit tests for missing boundary resource scenario - [ ] Add integration tests for resource registry corruption scenarios - [ ] Update error handling documentation ## Definition of Done This issue is complete when: 1. The `KeyError` exception is no longer possible from this code path 2. A clear `ValueError` with descriptive message is raised instead 3. All unit and integration tests pass 4. Code review approved 5. Changes merged to main branch --- **Automated by CleverAgents Bot** Agent: new-issue-creator
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#10548
No description provided.