fix(run_agent): shut down background review memory providers#15289
Closed
mrhwick wants to merge 4 commits into
Closed
fix(run_agent): shut down background review memory providers#15289mrhwick wants to merge 4 commits into
mrhwick wants to merge 4 commits into
Conversation
Temporary background review agents can initialize Hindsight-backed memory clients, but close() alone skips provider teardown. Shut the memory provider down before closing so aiohttp sessions do not leak at process exit. Made-with: Cursor
Review: Fix background review memory provider shutdown\n\n✅ Critical bug fix - well done!\n\nThe problem:\n- Background review agents could leave client sessions open\n- Resulted in / warnings\n- Only happened with memory providers like Hindsight that manage their own network clients\n\nThe fix:\n- Explicitly call before \n- Matches the existing session-boundary cleanup pattern\n- Narrowly scoped to just the temporary review agent path\n\nTest coverage:\n- Perfect regression test verifying cleanup order\n- Confirms is called before \n\nQuestion: Should we consider updating documentation to explicitly state it doesn't shut down memory providers, so future contributors don't make the same mistake?\n\nThis fixes a real resource leak that users were seeing. Approved! 🐛🔧 |
|
Critical fix for resource leak. Explicit shutdown_memory_provider call before close is the right pattern. Approved! |
Contributor
|
Merged via salvage PR #16204. Your three commits were rebase-merged onto current main with your authorship preserved in git log (2d86e97, 36e352a, aa7b5ac). We added one follow-up commit (45bfcb9) extending the test's bare-agent helper so it covers |
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?
This fixes a cleanup gap in the temporary background review agent spawned by
_spawn_background_review()inrun_agent.py.That review agent can initialize memory providers such as Hindsight, but its teardown path only called
close().AIAgent.close()does not shut down memory providers, so Hindsight-ownedaiohttpclient sessions could survive until GC or process exit and emitUnclosed client session/Unclosed connectorwarnings.This change explicitly calls
shutdown_memory_provider()beforeclose()for the background review agent, which matches the existing explicit session-boundary cleanup pattern used elsewhere in the codebase. It also adds a regression test that verifies the cleanup order.Related Issue
Fixes #
Type of Change
Changes Made
run_agent.pyso the temporary review agent in_spawn_background_review()callsshutdown_memory_provider()beforeclose().tests/run_agent/test_background_review.pyto verify the background review teardown path shuts down the memory provider before closing the agent.AIAgent.close().How to Test
scripts/run_tests.sh tests/run_agent/test_background_review.py.aiohttpwarnings such asUnclosed client sessionorUnclosed connector.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs