TDD: examples/test_app.py: LLM request/response logging wrapper re-wraps chat_model.ainvoke/astream on every chat_model access, duplicating LLM REQUEST/RESPONSE log lines #174

Closed
opened 2026-11-19 16:14:44 +00:00 by CoreRasurae · 0 comments
Member

Metadata

Commit Message: test(examples): capture duplicate LLM request/response log entries bug (#173)
Branch: tdd/m1-llm-request-log-duplication

Background and context

Companion TDD issue for bug #173 (examples/test_app.py's AOP logging wrapper re-wraps chat_model.ainvoke/astream on every _ensure_chat_model() call, duplicating LLM REQUEST/RESPONSE log lines). 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.

Current behavior

No automated test exists that proves _setup_request_logging's chat-model wrap in examples/test_app.py stacks a new logging layer on chat_model.ainvoke/astream every time _ensure_chat_model() runs, so one real LLM call ends up logged multiple times (see #173 for full root-cause analysis and captured evidence).

Expected behavior

A Behave scenario demonstrates the bug: after calling the patched _ensure_chat_model() twice on the same LLMAgent/chat_model instance (using a fake/stub chat model and a canned fake response -- no real network call), invoking ainvoke() once results in the request/response being logged more than once. The assertion fails while the bug is present, and the scenario is tagged @tdd_expected_fail so it passes CI via inversion until the real fix (#173) lands.

Acceptance criteria

  • A Behave scenario tagged @tdd_issue @tdd_issue_173 @tdd_expected_fail exists in features/ (new or extended step file).
  • The scenario's assertion step uses assert / raise AssertionError only (per project TDD rules) and asserts that exactly one request/response pair is logged per real ainvoke call after _ensure_chat_model() has been invoked twice on the same instance.
  • Running the scenario against the current (unfixed) code fails the underlying assertion (bug reproduced), which the suite reports as passing only because of the @tdd_expected_fail inversion.
  • nox -s unit_tests is green; coverage unaffected or improved.
  • No mocks/fakes are added outside features/mocks/.

Supporting information

  • See bug issue #173 for the full root-cause analysis, the duplication mechanism, and the captured log evidence.

Subtasks

  • Add a Behave scenario reproducing the duplicate-logging behavior, tagged @tdd_issue @tdd_issue_173 @tdd_expected_fail.
  • Add a fake/stub chat model (in features/mocks/ if new) with a canned response, to exercise _setup_request_logging's wrap logic twice without a real network call.
  • Implement the step(s) needed to count resulting log lines for one real ainvoke call after two _ensure_chat_model() invocations.
  • Verify the scenario fails on unfixed code (bug reproduced) and passes 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 #173 has a Forgejo dependency on this TDD issue (i.e. #173 depends on this issue; this issue blocks #173).
## Metadata Commit Message: `test(examples): capture duplicate LLM request/response log entries bug (#173)` Branch: tdd/m1-llm-request-log-duplication ## Background and context Companion TDD issue for bug #173 (`examples/test_app.py`'s AOP logging wrapper re-wraps `chat_model.ainvoke`/`astream` on every `_ensure_chat_model()` call, duplicating LLM REQUEST/RESPONSE log lines). 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. ## Current behavior No automated test exists that proves `_setup_request_logging`'s chat-model wrap in `examples/test_app.py` stacks a new logging layer on `chat_model.ainvoke`/`astream` every time `_ensure_chat_model()` runs, so one real LLM call ends up logged multiple times (see #173 for full root-cause analysis and captured evidence). ## Expected behavior A Behave scenario demonstrates the bug: after calling the patched `_ensure_chat_model()` twice on the same `LLMAgent`/`chat_model` instance (using a fake/stub chat model and a canned fake response -- no real network call), invoking `ainvoke()` once results in the request/response being logged more than once. The assertion fails while the bug is present, and the scenario is tagged `@tdd_expected_fail` so it passes CI via inversion until the real fix (#173) lands. ## Acceptance criteria - A Behave scenario tagged `@tdd_issue @tdd_issue_173 @tdd_expected_fail` exists in `features/` (new or extended step file). - The scenario's assertion step uses `assert` / `raise AssertionError` only (per project TDD rules) and asserts that exactly one request/response pair is logged per real `ainvoke` call after `_ensure_chat_model()` has been invoked twice on the same instance. - Running the scenario against the current (unfixed) code fails the underlying assertion (bug reproduced), which the suite reports as passing only because of the `@tdd_expected_fail` inversion. - `nox -s unit_tests` is green; coverage unaffected or improved. - No mocks/fakes are added outside `features/mocks/`. ## Supporting information - See bug issue #173 for the full root-cause analysis, the duplication mechanism, and the captured log evidence. ## Subtasks - [ ] Add a Behave scenario reproducing the duplicate-logging behavior, tagged `@tdd_issue @tdd_issue_173 @tdd_expected_fail`. - [ ] Add a fake/stub chat model (in `features/mocks/` if new) with a canned response, to exercise `_setup_request_logging`'s wrap logic twice without a real network call. - [ ] Implement the step(s) needed to count resulting log lines for one real `ainvoke` call after two `_ensure_chat_model()` invocations. - [ ] Verify the scenario fails on unfixed code (bug reproduced) and passes 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 #173 has a Forgejo dependency on this TDD issue (i.e. #173 depends on this issue; this issue blocks #173).
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#174
No description provided.