refactor(conversation_loop): extract success cleanup slice CL-R3-2 into agent/conversation_loop_success_cleanup.py - #84653
Conversation
Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Contributor email mapping required by check-attribution CI for the god-file kill campaign PRs (Axl Ibiza, MBA <andrexibiza@gmail.com>). Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
… stability Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe conversation loop now delegates successful-call cleanup to a dedicated helper. Tests cover retry state, rate limits, relay completion, activity updates, import behavior, and integration. The change also increases the shared-metrics SQLite timeout and adds a contributor entry. ChangesConversation call cleanup
SQLite contention timeout
Contributor entry
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This PR extracts successful-call cleanup into a dedicated module while preserving behavior and adding focused coverage; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant ConversationLoop
participant CleanupHelper
participant NousRateGuard
participant Relay
participant ActivityTracker
ConversationLoop->>CleanupHelper: complete successful API call
CleanupHelper->>NousRateGuard: clear Nous rate-limit state when applicable
CleanupHelper->>Relay: record successful logical call
CleanupHelper->>ActivityTracker: touch agent activity
``
</details>
<!-- walkthrough_end -->
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary>🚥 Pre-merge checks | ✅ 5</summary>
<details>
<summary>✅ Passed checks (5 passed)</summary>
| Check name | Status | Explanation |
| :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------------ |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and specifically describes the main change: extracting successful-call cleanup into a dedicated module. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
</details>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary>✨ Finishing Touches</summary>
<details>
<summary>🧪 Generate unit tests (beta)</summary>
- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create PR with unit tests
</details>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->
---
<sub>Comment `@coderabbitai help` to get the list of available commands.</sub>
<!-- tips_end -->
|
|
CI fix applied. Root cause: The The failure is a pre-existing flake under CI load: 8 concurrent threads call Fix: Raised Commit: |
refactor(conversation_loop): extract success cleanup slice CL-R3-2 into agent/conversation_loop_success_cleanup.pyThe extraction itself is clean (control flow — the
|
|
Decision recorded against current main Do not land the current head as a zero-behavior shard. It includes an unrelated behavior change in Sequence this after #84275. Then rebase, recompute the cleanup-band golden window, and revalidate the exact successful-call ordering against current tracing/control-flow: retry-state reset, stale-stream reset, usage/cost finalization, hook emission, and the caller-owned #83437's tracing work is already on main through #85439, with its stale conversation-loop hunks discarded. The decision is therefore clear: narrow the branch to the extraction, rebase after #84275, and rerun exact-head tests. Current head is not landable unchanged. |
Summary
Blind extraction of slice CL-R3-2 from
agent/conversation_loop.py(7,757 lines at pinee4bb75b532e932a1055d9a710802a7435163b6a) into a new module, per the repo-wide god-file sharding policy — the region's second slice per the Wave-3 second-slice consensus.complete_successful_callinagent/conversation_loop_success_cleanup.pye89fb54ba61fbed1b641ec88a3659095015f456d7e8b4de5b9a020b9a35f5b29breakcorrectly retained in the caller (caller-owned control flow per contract);_retry.has_retried_429resolves through the caller's_retryobject; operation order exact (reset → provider-gated rate-limit clear → relay completion → activity touch); heavy imports (nous_rate_guard,relay_llm) deferred lazily inside the function body (startup-latency contract); moved-name set within the contract's AST-verified set.tests/run_agent/test_conversation_loop_success_cleanup.py— the complete §6.9 runtime matrix (10 behavior tests: same-object retry state, non-Nous no-call, Nous single-call + suppression, exact request ID/outcome, exact activity message, rate-guard exception non-blocking, relay exception not swallowed, PRODUCTION caller-owned break fires exactly once with no continue, import side-effect-free, monkeypatch visibility); no source-reading tests.agent/conversation_loop.py25 changed (band removed + import + call); new module; seam test.Method
5×2×3 double-blind decomposition (per the All Gods Must Die mandate) + second-slice Wave-3 adjudication. Blind implementer → 2 blind re-reviewers. Round 1: BOTH REQUEST CHANGES (committed test file failed the binding §6.9 minimum runtime-test matrix and did not exercise the production caller-owned break). Fix lane extended the tests to the full 10-item matrix (commit
d180ea16331, test file only). Round 2: both re-reviewers APPROVED:C:/tmp/tg-Feature Package/conversation-loop/review/CLR32-review-1-r2.md(12,090 B) — all gates PASS (exact moved-body fidelity, complete §6.9 matrix, mutation positive control)C:/tmp/tg-Feature Package/conversation-loop/review/CLR32-review-2-r2.md(13,608 B) — APPROVED, all gatesSuite evidence: pristine-pin vs post-extraction failure sets identical (relay/rate-guard/retry-state 45 passed both sides; seam 10/10). No new failures.
Coordination table
ee4bb75b532e932a1055d9a710802a7435163b6a(origin/main)agent/conversation_loop_success_cleanup.pye89fb54ba61fbed1b641ec88a3659095015f456d7e8b4de5b9a020b9a35f5b29Dedup statement
No prior extraction of this window exists. No duplicate work.
Credit
f948c35817f+d180ea16331)This slice is governed by the conversation_loop (posted on #78641). Former whole: 7,757 lines. Fixer roster: #83437.
Part of #78641
Part of #78647
Summary by CodeRabbit
Bug Fixes
Improved successful conversation-call handling by reliably resetting retry state, clearing applicable rate limits, recording completion, and updating agent activity.
Improved resilience when clearing rate-limit safeguards or updating observability data.
Reduced SQLite lock-related delays by allowing longer wait times for busy database operations.
Tests
Added comprehensive coverage for successful-call cleanup, provider-specific behavior, retries, activity updates, and error handling.