Zero Budget Ignored by Strategy Stubs in ACMS Module #8149

Open
opened 2026-04-13 04:03:58 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: fix(acms): honor zero token budget in strategy stubs
  • Branch name: bugfix/acms-zero-budget-ignored

Background and Context

The _budget_fragments helper in src/cleveragents/domain/models/acms/strategy_stubs.py is responsible for ensuring that the number of tokens in the context fragments does not exceed the specified budget.

Currently, the helper ignores a zero token budget. If the budget is less than or equal to 0, the helper returns all fragments rather than an empty list, which can lead to token overallocation and violates the contract expected by callers that pass budget=0 to signal "no tokens available."

Steps to Reproduce:

uv run python -c "
from cleveragents.domain.models.acms.strategy_stubs import SimpleKeywordStrategy
from cleveragents.domain.models.acms.strategy import BackendSet, PlanContext
from cleveragents.domain.models.acms.crp import ContextRequest

class FakeTextBackend:
    def search(self, query, *, scope, max_results=20):
        class Result:
            def __init__(self):
                self.uko_uri = 'uko://code/module/example'
                self.content = 'Example content'
                self.score = 0.9
                self.metadata = {'source': 'test'}
        return [Result()]

strategy = SimpleKeywordStrategy()
request = ContextRequest(query='example')
backends = BackendSet(text=FakeTextBackend())
fragments = strategy.assemble(request, backends, budget=0, plan_context=PlanContext())
print(len(fragments), [f.token_count for f in fragments])
"

Actual Output: 1 [3] — a fragment is emitted even though the budget is zero.

Expected Behavior

The _budget_fragments helper should honor a zero (or negative) token budget and return an empty list of fragments. When budget <= 0, no fragments should be returned, ensuring strict adherence to the token budget contract.

Acceptance Criteria

  • The _budget_fragments helper in src/cleveragents/domain/models/acms/strategy_stubs.py is updated to return an empty list when budget <= 0.
  • Unit tests are added to cover the budget=0 case (and ideally budget < 0 as well).
  • All strategy calls are verified to handle the updated behavior correctly.
  • No regressions in existing ACMS strategy tests.

Subtasks

  • Locate the _budget_fragments helper in src/cleveragents/domain/models/acms/strategy_stubs.py.
  • Add an early-return guard: if budget <= 0: return [].
  • Write a unit test asserting assemble(..., budget=0) returns an empty list.
  • Write a unit test asserting assemble(..., budget=-1) returns an empty list.
  • Run the full ACMS test suite and confirm no regressions.
  • Update any docstrings or inline comments to document the zero-budget behavior.

Definition of Done

This issue should be closed when:

  1. The _budget_fragments helper returns [] for any budget <= 0.
  2. Unit tests covering budget=0 and budget<0 pass.
  3. All existing ACMS strategy tests continue to pass.
  4. The fix is merged to the appropriate branch.

Parent Epic: #8497


Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor


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

## Metadata - **Commit message**: `fix(acms): honor zero token budget in strategy stubs` - **Branch name**: `bugfix/acms-zero-budget-ignored` ## Background and Context The `_budget_fragments` helper in `src/cleveragents/domain/models/acms/strategy_stubs.py` is responsible for ensuring that the number of tokens in the context fragments does not exceed the specified budget. Currently, the helper ignores a zero token budget. If the `budget` is less than or equal to 0, the helper returns all fragments rather than an empty list, which can lead to token overallocation and violates the contract expected by callers that pass `budget=0` to signal "no tokens available." **Steps to Reproduce:** ```bash uv run python -c " from cleveragents.domain.models.acms.strategy_stubs import SimpleKeywordStrategy from cleveragents.domain.models.acms.strategy import BackendSet, PlanContext from cleveragents.domain.models.acms.crp import ContextRequest class FakeTextBackend: def search(self, query, *, scope, max_results=20): class Result: def __init__(self): self.uko_uri = 'uko://code/module/example' self.content = 'Example content' self.score = 0.9 self.metadata = {'source': 'test'} return [Result()] strategy = SimpleKeywordStrategy() request = ContextRequest(query='example') backends = BackendSet(text=FakeTextBackend()) fragments = strategy.assemble(request, backends, budget=0, plan_context=PlanContext()) print(len(fragments), [f.token_count for f in fragments]) " ``` **Actual Output:** `1 [3]` — a fragment is emitted even though the budget is zero. ## Expected Behavior The `_budget_fragments` helper should honor a zero (or negative) token budget and return an empty list of fragments. When `budget <= 0`, no fragments should be returned, ensuring strict adherence to the token budget contract. ## Acceptance Criteria - [ ] The `_budget_fragments` helper in `src/cleveragents/domain/models/acms/strategy_stubs.py` is updated to return an empty list when `budget <= 0`. - [ ] Unit tests are added to cover the `budget=0` case (and ideally `budget < 0` as well). - [ ] All strategy calls are verified to handle the updated behavior correctly. - [ ] No regressions in existing ACMS strategy tests. ## Subtasks - [ ] Locate the `_budget_fragments` helper in `src/cleveragents/domain/models/acms/strategy_stubs.py`. - [ ] Add an early-return guard: `if budget <= 0: return []`. - [ ] Write a unit test asserting `assemble(..., budget=0)` returns an empty list. - [ ] Write a unit test asserting `assemble(..., budget=-1)` returns an empty list. - [ ] Run the full ACMS test suite and confirm no regressions. - [ ] Update any docstrings or inline comments to document the zero-budget behavior. ## Definition of Done This issue should be closed when: 1. The `_budget_fragments` helper returns `[]` for any `budget <= 0`. 2. Unit tests covering `budget=0` and `budget<0` pass. 3. All existing ACMS strategy tests continue to pass. 4. The fix is merged to the appropriate branch. **Parent Epic**: #8497 --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor --- **Automated by CleverAgents Bot** Supervisor: Epic Planning Pool | Agent: epic-planning-pool-supervisor
HAL9000 added this to the v3.4.0 milestone 2026-04-13 04:04:03 +00:00
Author
Owner

Verified — Critical bug: ACMS strategy stubs ignore zero budget constraint, violating budget enforcement requirements. MoSCoW: Must-have. Priority: High — budget enforcement is a core v3.4.0 acceptance criterion.


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

✅ **Verified** — Critical bug: ACMS strategy stubs ignore zero budget constraint, violating budget enforcement requirements. MoSCoW: Must-have. Priority: High — budget enforcement is a core v3.4.0 acceptance criterion. --- **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.

Reference
cleveragents/cleveragents-core#8149
No description provided.