BUG-HUNT: [boundary] Hardcoded Limits in Context Analysis Agent #1904

Open
opened 2026-04-03 00:10:50 +00:00 by freemo · 2 comments
Owner

Metadata

  • Branch: fix/boundary-hardcoded-limits-context-analysis-agent
  • Commit Message: fix(agents): make dependency and context file limits configurable in ContextAnalysisAgent
  • Milestone: v3.6.0
  • Parent Epic: To be linked — see orphan note below

Background and Context

The ContextAnalysisAgent in src/cleveragents/agents/graphs/context_analysis.py contains hardcoded numeric limits in two methods: _parse_dependencies caps the returned dependency list at 10 items, and _format_context_summary processes only the first 5 context files. These magic numbers are baked directly into the implementation with no mechanism for callers or users to override them.

Any project with more than 10 dependencies or more than 5 context files will silently receive an incomplete analysis result, with no warning or error surfaced to the caller. This is a boundary violation: the agent's behaviour changes abruptly at an undocumented threshold.

Current Behavior

# src/cleveragents/agents/graphs/context_analysis.py
def _parse_dependencies(self, llm_output: str) -> list[str]:
    ...
    return deps[:10]  # hardcoded cap — silently drops deps beyond index 9

def _format_context_summary(self, contexts: list[Context]) -> str:
    ...
    for ctx in contexts[:5]:  # hardcoded cap — silently ignores files beyond index 4
        ...

Expected Behavior

The limits for the number of dependencies and context files processed should be configurable. Callers should be able to adjust them based on project size and complexity, either via the agent's constructor parameters or via the agent state. The defaults may remain at 10 and 5 respectively, but they must not be hardcoded magic numbers.

Acceptance Criteria

  • _parse_dependencies uses a configurable max_dependencies limit (default: 10) instead of a hardcoded slice.
  • _format_context_summary uses a configurable max_context_files limit (default: 5) instead of a hardcoded slice.
  • Both limits are exposed as constructor parameters on ContextAnalysisAgent with explicit type annotations.
  • All public/protected methods validate their arguments as the first step of execution (fail-fast).
  • No # type: ignore suppressions are introduced.
  • A TDD issue-capture Behave scenario tagged @tdd_expected_fail demonstrates the boundary violation before the fix.

Subtasks

  • Write a failing Behave BDD scenario (@tdd_expected_fail) that demonstrates the hardcoded-limit boundary violation in _parse_dependencies and _format_context_summary
  • Add max_dependencies: int and max_context_files: int constructor parameters to ContextAnalysisAgent with appropriate defaults and argument validation
  • Replace the hardcoded [:10] slice in _parse_dependencies with the configurable limit
  • Replace the hardcoded [:5] slice in _format_context_summary with the configurable limit
  • Update or add Behave BDD unit tests covering the new configurable behaviour (both default and custom values)
  • Ensure all nox quality gates pass (nox -e lint, nox -e typecheck, nox -e unit_tests, nox -e coverage_report)

Definition of Done

  • Failing TDD capture test committed and tagged @tdd_expected_fail
  • ContextAnalysisAgent constructor accepts max_dependencies and max_context_files parameters
  • Both limits are used in place of the hardcoded slices
  • Argument validation added to the constructor (fail-fast on invalid values)
  • Behave BDD unit tests updated/added to cover configurable limits
  • All nox stages pass
  • Coverage >= 97%
  • Commit created with message: fix(agents): make dependency and context file limits configurable in ContextAnalysisAgent
  • Branch pushed and PR merged

⚠️ Orphan Notice: No parent Epic was found for BUG-HUNT: [boundary] issues at the time of creation. This issue must be manually linked to an appropriate parent Epic before work begins.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/boundary-hardcoded-limits-context-analysis-agent` - **Commit Message**: `fix(agents): make dependency and context file limits configurable in ContextAnalysisAgent` - **Milestone**: v3.6.0 - **Parent Epic**: _To be linked — see orphan note below_ ## Background and Context The `ContextAnalysisAgent` in `src/cleveragents/agents/graphs/context_analysis.py` contains hardcoded numeric limits in two methods: `_parse_dependencies` caps the returned dependency list at 10 items, and `_format_context_summary` processes only the first 5 context files. These magic numbers are baked directly into the implementation with no mechanism for callers or users to override them. Any project with more than 10 dependencies or more than 5 context files will silently receive an incomplete analysis result, with no warning or error surfaced to the caller. This is a boundary violation: the agent's behaviour changes abruptly at an undocumented threshold. ## Current Behavior ```python # src/cleveragents/agents/graphs/context_analysis.py def _parse_dependencies(self, llm_output: str) -> list[str]: ... return deps[:10] # hardcoded cap — silently drops deps beyond index 9 def _format_context_summary(self, contexts: list[Context]) -> str: ... for ctx in contexts[:5]: # hardcoded cap — silently ignores files beyond index 4 ... ``` ## Expected Behavior The limits for the number of dependencies and context files processed should be configurable. Callers should be able to adjust them based on project size and complexity, either via the agent's constructor parameters or via the agent state. The defaults may remain at 10 and 5 respectively, but they must not be hardcoded magic numbers. ## Acceptance Criteria - `_parse_dependencies` uses a configurable `max_dependencies` limit (default: 10) instead of a hardcoded slice. - `_format_context_summary` uses a configurable `max_context_files` limit (default: 5) instead of a hardcoded slice. - Both limits are exposed as constructor parameters on `ContextAnalysisAgent` with explicit type annotations. - All public/protected methods validate their arguments as the first step of execution (fail-fast). - No `# type: ignore` suppressions are introduced. - A TDD issue-capture Behave scenario tagged `@tdd_expected_fail` demonstrates the boundary violation before the fix. ## Subtasks - [ ] Write a failing Behave BDD scenario (`@tdd_expected_fail`) that demonstrates the hardcoded-limit boundary violation in `_parse_dependencies` and `_format_context_summary` - [ ] Add `max_dependencies: int` and `max_context_files: int` constructor parameters to `ContextAnalysisAgent` with appropriate defaults and argument validation - [ ] Replace the hardcoded `[:10]` slice in `_parse_dependencies` with the configurable limit - [ ] Replace the hardcoded `[:5]` slice in `_format_context_summary` with the configurable limit - [ ] Update or add Behave BDD unit tests covering the new configurable behaviour (both default and custom values) - [ ] Ensure all nox quality gates pass (`nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e coverage_report`) ## Definition of Done - [ ] Failing TDD capture test committed and tagged `@tdd_expected_fail` - [ ] `ContextAnalysisAgent` constructor accepts `max_dependencies` and `max_context_files` parameters - [ ] Both limits are used in place of the hardcoded slices - [ ] Argument validation added to the constructor (fail-fast on invalid values) - [ ] Behave BDD unit tests updated/added to cover configurable limits - [ ] All nox stages pass - [ ] Coverage >= 97% - [ ] Commit created with message: `fix(agents): make dependency and context file limits configurable in ContextAnalysisAgent` - [ ] Branch pushed and PR merged --- > ⚠️ **Orphan Notice**: No parent Epic was found for `BUG-HUNT: [boundary]` issues at the time of creation. This issue must be manually linked to an appropriate parent Epic before work begins. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.6.0 milestone 2026-04-03 00:12:07 +00:00
Author
Owner

⚠️ Orphan Issue — Manual Action Required

This issue was created without a parent Epic because no suitable open Epic was found for BUG-HUNT: [boundary] issues at the time of creation. Per CONTRIBUTING.md, all issues (except Epics and Legendaries) must be linked to a parent Epic.

Action needed: A project maintainer must:

  1. Identify or create an appropriate parent Epic for boundary-category bug hunt issues.
  2. Link this issue as a child by running:
    curl -s -X POST "https://git.cleverthis.com/api/v1/repos/cleveragents/cleveragents-core/issues/1904/blocks" \
      -H "Authorization: token <FORGEJO_PAT>" \
      -H "Content-Type: application/json" \
      -d '{"dependency_id": <PARENT_EPIC_NUMBER>}'
    

Note: A sibling issue in the same file — #1890 BUG-HUNT: [security] Path traversal vulnerability in ContextAnalysisAgent — is also currently an orphan and may benefit from the same parent Epic.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

⚠️ **Orphan Issue — Manual Action Required** This issue was created without a parent Epic because no suitable open Epic was found for `BUG-HUNT: [boundary]` issues at the time of creation. Per `CONTRIBUTING.md`, all issues (except Epics and Legendaries) must be linked to a parent Epic. **Action needed**: A project maintainer must: 1. Identify or create an appropriate parent Epic for boundary-category bug hunt issues. 2. Link this issue as a child by running: ```bash curl -s -X POST "https://git.cleverthis.com/api/v1/repos/cleveragents/cleveragents-core/issues/1904/blocks" \ -H "Authorization: token <FORGEJO_PAT>" \ -H "Content-Type: application/json" \ -d '{"dependency_id": <PARENT_EPIC_NUMBER>}' ``` Note: A sibling issue in the same file — [#1890 BUG-HUNT: [security] Path traversal vulnerability in ContextAnalysisAgent](https://git.cleverthis.com/cleveragents/cleveragents-core/issues/1890) — is also currently an orphan and may benefit from the same parent Epic. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • MoSCoW: MoSCoW/Should Have — bug or error handling improvement.

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

Issue triaged by project owner: - **State**: Verified - **MoSCoW**: MoSCoW/Should Have — bug or error handling improvement. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
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#1904
No description provided.