fix(agents): drive inline agent sessions via run_agent_session, not the phantom create_agent_session#341
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughAll four inline agent modules ( ChangesAgent Session API Migration
Sequence Diagram(s)sequenceDiagram
participant Caller
participant AgentModule
participant SDKClient
participant run_agent_session as agents.session.run_agent_session
Caller->>AgentModule: run_*_session(starting_message, spec_dir)
AgentModule->>AgentModule: session_message = prompt + starting_message
AgentModule->>SDKClient: async with client (connect)
AgentModule->>run_agent_session: await run_agent_session(client, session_message, spec_dir, phase)
run_agent_session-->>AgentModule: (status, response_text, session_name, ...)
SDKClient-->>AgentModule: async with exit (disconnect)
alt status == "error"
AgentModule-->>Caller: {success: False, error: response_text, output: None}
else success
AgentModule-->>Caller: {success: True, output: {response, agent_type, session_name}}
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…he phantom create_agent_session ClaudeSDKClient (claude_agent_sdk) has no `create_agent_session` method, so every inline call site raised `'ClaudeSDKClient' object has no attribute 'create_agent_session'` at runtime. The shared generator boilerplate (agents/_generator_base) was fixed in #339; this covers the remaining inline call sites it called out as a follow-up: - documentation_generator.run_documentation_generator_session - migration_assistant.run_migration_assistant - test_generator.run_test_generator_session (writer + coverage-improvement) - agent_subprocess.run_agent_session (isolated-subprocess wrapper) Each now drives the session through run_agent_session() (agents/session.py) inside `async with client` — the same API the planner/coder/qa phases use — and treats a returned status == "error" as failure. The agent role prompt is delivered as the leading message since the SDK client only carries the generic base system prompt. agent_subprocess imports the helper under an alias so it does not shadow its own run_agent_session() wrapper. Add tests/test_inline_generator_sessions.py (mirrors tests/test_fixture_generator_session.py: a fake async-context-manager client with no create_agent_session attribute, agents.session.run_agent_session patched as an AsyncMock, asserting it is awaited and the client is entered). Update the existing migration/test-generation suites that mocked the phantom method to drive the shared session helper instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Oleg Miagkov <mrobenner@gmail.com>
48a2f3f to
6f92d11
Compare
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|



Problem
ClaudeSDKClient(fromclaude_agent_sdk) has nocreate_agent_sessionmethod, so every inline call site raised'ClaudeSDKClient' object has no attribute 'create_agent_session'at runtime. The shared generator boilerplate (agents/_generator_base) was fixed in #339, which explicitly called out these remaining inline call sites as a follow-up. This is that follow-up.Fix
Each inline session now drives the client through
run_agent_session()(agents/session.py) insideasync with client— the same session API the planner/coder/qa phases use — and treats a returnedstatus == "error"as failure. The agent role prompt is delivered as the leading message (the SDK client only carries the generic base system prompt).run_documentation_generator_sessionrun_migration_assistantrun_test_generator_session(writer and coverage-improvement sessions)run_agent_session(isolated-subprocess wrapper)Notes:
agent_subprocessimports the helper under an alias (run_agent_session as run_sdk_session) so it does not shadow that module's ownrun_agent_session()wrapper; the JSON output shape consumed byrun_agent_session_isolatedis preserved.test_generator's two sessions each run in their ownasync with clientblock (create_clientreturns an options-based, reconnectable client). The improvement message is self-contained and the agent re-reads its earlier output from disk.documentation_generator,migration_assistant,test_generator) are already registered inAGENT_CONFIGS;agent_subprocessreceives its type from the caller (coder→run_agent_session_isolated).Tests
tests/test_inline_generator_sessions.pymirrorstests/test_fixture_generator_session.py— a fake async-context-manager client with nocreate_agent_sessionattribute,agents.session.run_agent_sessionpatched as anAsyncMock, asserting it is awaited, the client is entered/exited, and the role prompt leads the message. Covers all four modules plus error propagation and the test_generator two-session (writer + improvement) path.tests/test_migration_assistant.py,tests/test_test_generation.py,tests/integration/test_migration_workflow.py, and a dead-mock cleanup intests/e2e/test_qa_test_generation_flow.py.Rebased onto current
develop(includes #339). All affected files run green together (98 passed locally, including #339'stest_fixture_generator_session.py):(One pre-existing
RuntimeWarning: coroutine 'run_migration_assistant' was never awaitedremains inTestMigrationCLIIntegration— a class this PR does not touch.)🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests