Conversation
run_conversation increments api_call_count optimistically at the top of each loop iteration, before the API call is actually made. When a call fails after exhausting all retries (and no transport recovery or fallback is available), the terminal return path reported that failed attempt as a successful API call, leaving the logged/returned/persisted count one too high. Refund the optimistic bump on the max-retries-exhausted path (decrement api_call_count and update the agent._api_call_count mirror) before the count is logged, persisted, and returned. This mirrors the refund the Ollama-context abort path already performs. Adds a regression test that drives run_conversation with a mocked LLM that always raises a retryable transport error, asserting api_calls is refunded to 0. Fixes NousResearch#38445 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
14 tasks
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
In
run_conversation,api_call_countis incremented optimistically at the top of each loop iteration, before the API call actually succeeds. When a call fails after exhausting all retries — with no transport recovery and no fallback provider available — the terminal path counted that failed attempt as a successful API call, so the logged / returned / persisted count was one too high.Related Issue
Fixes #38445
Type of Change
Changes Made
agent/conversation_loop.py— on the exhausted-retries terminal path, refund the optimistic bump before the count is logged, persisted, and returned (api_call_count -= 1; agent._api_call_count = api_call_count). Mirrors the refund the Ollama-context abort path already performs (conversation_loop.py:1102).tests/run_agent/test_api_call_count_refund_on_exhausted_retries.py— new regression test.How to Test
pytest tests/run_agent/test_api_call_count_refund_on_exhausted_retries.py -q→ 2 passing. Drivesrun_conversationwith a mocked LLM that always raises a retryable transport error and assertsapi_calls == 0(plus a case verifying the count stays accurate after a prior successful call).mainand pass with the fix.Checklist
Code
pytest tests/ -qand all tests pass — ran the new module (2 passed) +py_compile; full suite not run in my Windows dev envDocumentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.md/AGENTS.md— N/ANotes
Intentionally scoped to the exhausted-retries terminal path the issue describes; other terminal/abort paths in
run_conversationwere left untouched (focused-PR rule). If any has a similar off-by-one it would be a separate issue.