Repository navigation
Refactor/scenario provider - #22
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
PR Summary by QodoAlign ScenarioProvider contract and enable OpenAI-backed CLI
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
CI 检查结果汇总
信息展示
📋 pytest 详细============================= test session starts ==============================
platform linux -- Python 3.14.7, pytest-9.1.1, pluggy-1.6.0
rootdir: /home/runner/work/MitoCode/MitoCode
configfile: pyproject.toml
plugins: anyio-4.14.2, cov-7.1.0, asyncio-1.4.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 144 items
test/test_agent_runtime.py ............................ [ 19%]
test/test_agent_session.py ............................................. [ 50%]
............ [ 59%]
test/test_main.py . [ 59%]
test/test_orchestrator_and_bridge.py ............ [ 68%]
test/test_tool_manager.py ...... [ 72%]
test/test_workspace.py ...................................... [ 98%]
test/test_workspace_async.py .. [100%]
------ generated xml file: /home/runner/work/MitoCode/MitoCode/report.xml ------
================================ tests coverage ================================
_______________ coverage: platform linux, python 3.14.7-final-0 ________________
Name Stmts Miss Cover
--------------------------------------------------------------------------------
src/mitocode/__init__.py 4 0 100%
src/mitocode/backend/__init__.py 3 0 100%
src/mitocode/backend/agent/__init__.py 8 0 100%
src/mitocode/backend/agent/agent_node.py 10 0 100%
src/mitocode/backend/agent/agent_orchestrator.py 115 35 70%
src/mitocode/backend/agent/agent_runtime.py 91 0 100%
src/mitocode/backend/agent/agent_session.py 133 1 99%
src/mitocode/backend/agent/agent_state.py 8 0 100%
src/mitocode/backend/agent/session_factory.py 6 0 100%
src/mitocode/backend/bridge/__init__.py 2 0 100%
src/mitocode/backend/bridge/event_adapter.py 25 0 100%
src/mitocode/backend/chat_provider/__init__.py 4 0 100%
src/mitocode/backend/chat_provider/chat_provider_openai.py 50 34 32%
src/mitocode/backend/chat_provider/sample_chat_provider.py 39 18 54%
src/mitocode/backend/exception/__init__.py 2 0 100%
src/mitocode/backend/exception/mitocode_exception.py 19 0 100%
src/mitocode/backend/tool/__init__.py 2 0 100%
src/mitocode/backend/tool/tool_manager.py 105 28 73%
src/mitocode/backend/workspace/__init__.py 3 0 100%
src/mitocode/backend/workspace/migration.py 77 39 49%
src/mitocode/backend/workspace/snapshot.py 0 0 100%
src/mitocode/backend/workspace/workspace.py 180 11 94%
--------------------------------------------------------------------------------
TOTAL 886 166 81%
Coverage XML written to file coverage.xml
Required test coverage of 80% reached. Total coverage: 81.26%
============================= 144 passed in 1.57s ==============================
🔒 gitleaks 详细[]📝 pyright 输出自动提交状态: 已自动提交 ✅ 由 CI 自动生成 |
Code Review by Qodo
1. CLI requires live model discovery
|
| provider = asyncio.run(ChatProviderOpenAI.factory( | ||
| default_model= "nvidia/nemotron-3.5-lightning:free", | ||
| default_model_list= None, |
There was a problem hiding this comment.
1. Cli requires live model discovery 🐞 Bug ☼ Reliability
The CLI now constructs ChatProviderOpenAI with no fallback model list, whose factory performs a live model-list request and raises when that request fails. A network outage, unreachable OpenRouter endpoint, or authentication failure therefore prevents the TUI from launching instead of retaining the previous offline scenario behavior.
Agent Prompt
## Issue description
CLI startup now requires successful live OpenRouter model discovery, so provider initialization failure prevents the TUI from launching.
## Issue Context
The previous ScenarioProvider was offline. ChatProviderOpenAI.factory calls init, and init fetches models; without a fallback model list, failures are raised.
## Fix Focus Areas
- src/mitocode/__main__.py[72-83]
- src/mitocode/backend/chat_provider/chat_provider_openai.py[56-96]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| tool_manager = ToolManager() | ||
| _register_tools(tool_manager) | ||
|
|
||
| provider = ScenarioProvider(delay=args.speed) |
There was a problem hiding this comment.
2. Speed option is ignored 🐞 Bug ≡ Correctness
The CLI still advertises --speed as the delay between chunks, but the replacement provider construction no longer uses args.speed. Every supplied value is silently ignored, so the option cannot affect streaming as documented.
Agent Prompt
## Issue description
The documented --speed argument is parsed but no longer affects the selected provider.
## Issue Context
The removed ScenarioProvider construction passed args.speed; ChatProviderOpenAI has no equivalent delay behavior.
## Fix Focus Areas
- src/mitocode/__main__.py[61-83]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| async def init(self) -> None: | ||
| """No-op initialization hook kept for provider interface parity.""" | ||
| pass | ||
| delay = self.settings.get("delay", 0.03) if self.settings else 0.03 | ||
| self._delay = delay |
There was a problem hiding this comment.
3. Factory discards delay argument 🐞 Bug ≡ Correctness
ScenarioProvider.factory(delay=x) stores x in the constructor and then init immediately overwrites it with settings.delay or 0.03. Callers using the provider's standard factory lifecycle therefore cannot configure the stream delay through the explicit delay parameter.
Agent Prompt
## Issue description
Factory initialization overwrites the explicit delay constructor argument with the default settings value.
## Issue Context
The constructor assigns self._delay from delay, after which factory invokes init and resets it.
## Fix Focus Areas
- src/mitocode/backend/chat_provider/scenario_provider.py[151-177]
- src/mitocode/backend/chat_provider/scenario_provider.py[179-184]
- src/mitocode/backend/chat_provider/scenario_provider.py[209-212]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| full_content = "" | ||
| for c in chunks: | ||
| if c.choices[0].delta.content: | ||
| full_content += c.choices[0].delta.content |
There was a problem hiding this comment.
4. Non-streaming drops tool calls 🐞 Bug ≡ Correctness
For scripted turns 0–2, the new non-streaming branch copies only delta.content, omits message.tool_calls, and hardcodes finish_reason to stop. Consumers requesting stream=False receive a false normal completion and cannot execute the scenario's bash, write_file, or read_file calls.
Agent Prompt
## Issue description
Non-streaming scenario completions discard fragmented tool calls and return the wrong finish reason.
## Issue Context
Turns 0–2 generate tool-call deltas ending in tool_calls. Reconstruct their IDs, names, and arguments into message.tool_calls and preserve the actual finish reason.
## Fix Focus Areas
- src/mitocode/backend/chat_provider/scenario_provider.py[233-260]
- src/mitocode/backend/chat_provider/scenario_provider.py[267-286]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.