TDD: fix(agents): virtual-provider budget cost is priced against the agent-level (provider, model), not the selected backend #202

Closed
opened 2026-12-02 17:12:13 +00:00 by CoreRasurae · 1 comment
Member

Metadata

Commit Message: test(agents): capture virtual-provider budget cost misattribution bug (#159)
Branch: tdd/m1-virtual-provider-cost-attribution

Background and context

Companion TDD issue for bug #159 (LLMAgent._accumulate_cost_after_invoke and _check_budget_before_invoke in agents/llm.py resolve pricing/zero-cost status via the agent-level (self.provider, self.model) anchor, even when the agent is a virtual-provider pool (ADR-2038, docs/index.md §4.4.7) whose VirtualChatModel actually selected a different backend with its own provider/model). Per the project's mandatory Bug Fix TDD Workflow, a failing test proving the bug exists must be written and merged to master BEFORE the fix is implemented. See #159 for the full root-cause analysis.

Current behavior

No automated test exists that proves a pooled (backends-configured) LLMAgent computes accumulated cost and evaluates the zero-cost budget carve-out using its agent-level (provider, model) anchor rather than the backend actually selected and invoked by VirtualChatModel for that call.

Expected behavior

Behave scenarios demonstrate the bug:

  1. A pooled agent with per-backend provider/model overrides distinct from the agent-level anchor accumulates cost at the anchor's rates instead of the selected backend's rates (#159 AC1).
  2. A pooled agent whose agent-level anchor pair is absent from the pricing table, but whose selected backend is priced, raises missing_pricing_entry instead of completing (#159 AC2).

Both assertions fail while the bug is present, and the scenarios are tagged @tdd_expected_fail so they pass CI via inversion until the real fix (#159) lands.

Acceptance criteria

  • A Behave scenario tagged @tdd_issue @tdd_issue_159 @tdd_expected_fail exists in features/ (new or extended step file) asserting accumulated cost is computed from the selected backend's rates, not the agent-level anchor's (mirrors #159 AC1).
  • A second scenario with the same three tags asserts that an unpriced agent-level anchor with a priced, selected backend does not raise missing_pricing_entry (mirrors #159 AC2).
  • Assertion steps use assert / raise AssertionError only (per project TDD rules).
  • Running the scenarios against the current (unfixed) code fails the underlying assertions (bug reproduced), which the suite reports as passing only via the @tdd_expected_fail inversion.
  • nox -s unit_tests is green; coverage unaffected or improved.
  • No mocks/fakes added outside features/mocks/.

Supporting information

  • See bug issue #159 for the full root-cause analysis (ADR-2038, docs/index.md §4.4.7, LLMAgent._accumulate_cost_after_invoke / _check_budget_before_invoke / VirtualChatModel._select in src/cleveractors/agents/llm.py and llm_virtual_provider.py).

Subtasks

  • Add a Behave scenario reproducing the virtual-provider cost-misattribution bug (AC1), tagged @tdd_issue @tdd_issue_159 @tdd_expected_fail.
  • Add a Behave scenario reproducing the unpriced-anchor/priced-backend missing_pricing_entry false failure (AC2), same tags.
  • Implement the step(s) needed to construct a pooled LLMAgent with backends overriding provider/model, drive an invocation through fake chat models (features/mocks/), and inspect the accumulated cost / raised exception.
  • Assert the accumulated cost is computed from the selected backend's rates, not the agent-level anchor; assert the unpriced-anchor run does not raise missing_pricing_entry when the selected backend is priced — both assertions fail on unfixed code.
  • Verify both scenarios fail on unfixed code (bug reproduced) and pass CI only via the @tdd_expected_fail inversion.
  • Run nox -s unit_tests, nox -s lint, and nox -s typecheck on the new files, fix any errors.

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line matches the Commit Message in Metadata exactly.
  • The commit is pushed to the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a PR to master, reviewed, and merged.
  • Bug issue #159 has a Forgejo dependency on this TDD issue (i.e. #159 depends on this issue; this issue blocks #159).
## Metadata Commit Message: `test(agents): capture virtual-provider budget cost misattribution bug (#159)` Branch: tdd/m1-virtual-provider-cost-attribution ## Background and context Companion TDD issue for bug #159 (`LLMAgent._accumulate_cost_after_invoke` and `_check_budget_before_invoke` in `agents/llm.py` resolve pricing/zero-cost status via the agent-level `(self.provider, self.model)` anchor, even when the agent is a virtual-provider pool (ADR-2038, `docs/index.md` §4.4.7) whose `VirtualChatModel` actually selected a different backend with its own `provider`/`model`). Per the project's mandatory Bug Fix TDD Workflow, a failing test proving the bug exists must be written and merged to master BEFORE the fix is implemented. See #159 for the full root-cause analysis. ## Current behavior No automated test exists that proves a pooled (`backends`-configured) `LLMAgent` computes accumulated cost and evaluates the zero-cost budget carve-out using its agent-level `(provider, model)` anchor rather than the backend actually selected and invoked by `VirtualChatModel` for that call. ## Expected behavior Behave scenarios demonstrate the bug: 1. A pooled agent with per-backend provider/model overrides distinct from the agent-level anchor accumulates cost at the **anchor's** rates instead of the **selected backend's** rates (#159 AC1). 2. A pooled agent whose agent-level anchor pair is absent from the pricing table, but whose selected backend is priced, raises `missing_pricing_entry` instead of completing (#159 AC2). Both assertions fail while the bug is present, and the scenarios are tagged `@tdd_expected_fail` so they pass CI via inversion until the real fix (#159) lands. ## Acceptance criteria - A Behave scenario tagged `@tdd_issue @tdd_issue_159 @tdd_expected_fail` exists in `features/` (new or extended step file) asserting accumulated cost is computed from the selected backend's rates, not the agent-level anchor's (mirrors #159 AC1). - A second scenario with the same three tags asserts that an unpriced agent-level anchor with a priced, selected backend does not raise `missing_pricing_entry` (mirrors #159 AC2). - Assertion steps use `assert` / `raise AssertionError` only (per project TDD rules). - Running the scenarios against the current (unfixed) code fails the underlying assertions (bug reproduced), which the suite reports as passing only via the `@tdd_expected_fail` inversion. - `nox -s unit_tests` is green; coverage unaffected or improved. - No mocks/fakes added outside `features/mocks/`. ## Supporting information - See bug issue #159 for the full root-cause analysis (ADR-2038, `docs/index.md` §4.4.7, `LLMAgent._accumulate_cost_after_invoke` / `_check_budget_before_invoke` / `VirtualChatModel._select` in `src/cleveractors/agents/llm.py` and `llm_virtual_provider.py`). ## Subtasks - [ ] Add a Behave scenario reproducing the virtual-provider cost-misattribution bug (AC1), tagged `@tdd_issue @tdd_issue_159 @tdd_expected_fail`. - [ ] Add a Behave scenario reproducing the unpriced-anchor/priced-backend `missing_pricing_entry` false failure (AC2), same tags. - [ ] Implement the step(s) needed to construct a pooled `LLMAgent` with `backends` overriding provider/model, drive an invocation through fake chat models (features/mocks/), and inspect the accumulated cost / raised exception. - [ ] Assert the accumulated cost is computed from the selected backend's rates, not the agent-level anchor; assert the unpriced-anchor run does not raise `missing_pricing_entry` when the selected backend is priced — both assertions fail on unfixed code. - [ ] Verify both scenarios fail on unfixed code (bug reproduced) and pass CI only via the `@tdd_expected_fail` inversion. - [ ] Run `nox -s unit_tests`, `nox -s lint`, and `nox -s typecheck` on the new files, fix any errors. ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the first line matches the Commit Message in Metadata exactly. - The commit is pushed to the branch matching the Branch in Metadata exactly. - The commit is submitted as a PR to master, reviewed, and merged. - Bug issue #159 has a Forgejo dependency on this TDD issue (i.e. #159 depends on this issue; this issue blocks #159).
CoreRasurae 2026-12-04 11:13:48 +00:00
Author
Member

Reopened only to assign the epic

Reopened only to assign the epic
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/cleveractors-core#202
No description provided.