refactor(core): unify ReactAgent context loading via TaskContextPackager - #435
Conversation
…ger (#431) ReactAgent now uses TaskContextPackager.load_context() instead of directly instantiating ContextLoader. This centralizes context loading through a single owner, reducing maintenance risk when context assembly logic changes.
WalkthroughIntroduced new public method Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
PR #435 Review: Unify ReactAgent context loading via TaskContextPackagerOverall: Clean, well-scoped refactor. Approve with minor observations. What is Working Well
Minor Observations1. The test asserts 2. Fresh packager instantiation on every The packager is created fresh on each 3. Fine within the class and consistent with existing conventions in the file. SummaryThis PR accomplishes its stated goal: Ready to merge. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/core/test_react_agent.py (1)
498-507:⚠️ Potential issue | 🟠 MajorException mocks still target the old method name.
At Line 506, Line 886, and Line 1628, the tests set
mock_ctx_loader.return_value.load.side_effect, butReactAgent.run()now callsload_context(). This means the intended exception path is not being exercised reliably.🔧 Suggested fix
- mock_ctx_loader.return_value.load.side_effect = RuntimeError("DB corrupt") + mock_ctx_loader.return_value.load_context.side_effect = RuntimeError("DB corrupt") - mock_ctx_loader.return_value.load.side_effect = RuntimeError("boom") + mock_ctx_loader.return_value.load_context.side_effect = RuntimeError("boom") - mock_ctx_loader.return_value.load.side_effect = RuntimeError("boom") + mock_ctx_loader.return_value.load_context.side_effect = RuntimeError("boom")Also applies to: 877-887, 1620-1629
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/core/test_react_agent.py` around lines 498 - 507, The tests mock TaskContextPackager but set side effects on the old method name 'load'; update all occurrences where tests set mock_ctx_loader.return_value.load.side_effect to instead set mock_ctx_loader.return_value.load_context.side_effect so the RuntimeError (e.g., "DB corrupt") is raised when ReactAgent.run() invokes load_context(); update the same change at the other test sites that target TaskContextPackager mocks to ensure the exception path is actually exercised for ReactAgent.run().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/core/test_react_agent.py`:
- Around line 498-507: The tests mock TaskContextPackager but set side effects
on the old method name 'load'; update all occurrences where tests set
mock_ctx_loader.return_value.load.side_effect to instead set
mock_ctx_loader.return_value.load_context.side_effect so the RuntimeError (e.g.,
"DB corrupt") is raised when ReactAgent.run() invokes load_context(); update the
same change at the other test sites that target TaskContextPackager mocks to
ensure the exception path is actually exercised for ReactAgent.run().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b1683767-7e1a-4b7d-bccd-88739b5da02b
📒 Files selected for processing (6)
codeframe/core/context_packager.pycodeframe/core/react_agent.pytests/core/test_context_packager.pytests/core/test_react_agent.pytests/core/test_react_agent_compaction.pytests/core/test_react_agent_escalation.py
Summary
Implements #431: [Phase 4] Unify ReactAgent context assembly with TaskContextPackager
load_context(task_id) -> TaskContextmethod toTaskContextPackagerfor internal agent useReactAgent.run()to useTaskContextPackagerinstead of directly instantiatingContextLoaderContextLoaderimport fromreact_agent.py— all context loading now goes throughTaskContextPackagerAcceptance Criteria
Test Plan
load_context()(returns TaskContext, delegates to loader, matches build())Implementation Notes
load_context()instead ofbuild_agent_context()(as in the traycer plan) becausebuild_agent_context()already exists from [Phase 4] Task Context Packager for External Agents #410 and returnsAgentContextfor external adaptersReactAgenttoTaskContextPackagerCloses #431
Summary by CodeRabbit
Release Notes
Refactor
Tests