Skip to content

Refactor/scenario provider - #22

Merged
alanwang233233 merged 2 commits into
mainfrom
refactor/scenario_provider
Aug 27, 2026
Merged

alanwang233233 merged 2 commits into
mainfrom
refactor/scenario_provider

Conversation

@alanwang233233

Copy link
Copy Markdown
Owner

No description provided.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@alanwang233233
alanwang233233 merged commit 50ab074 into main Aug 27, 2026
1 check passed
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Align ScenarioProvider contract and enable OpenAI-backed CLI

🐞 Bug fix ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Align ScenarioProvider with the shared asynchronous provider lifecycle and configuration contract.
• Support scripted streaming and aggregated non-streaming chat responses.
• Launch the CLI with an OpenRouter-backed OpenAI provider instead of the offline scenario.
Diagram

classDiagram
class SampleChatProvider {
  <<abstract>>
  +factory()
  +init()
  +get_model_list()
  +chat()
}
class ScenarioProvider {
  +factory()
  +init()
  +chat()
}
class ChatProviderOpenAI {
  +init()
  +chat()
}
class MitoCodeCLI {
  +main()
}
class AgentOrchestrator {
  +create_agent()
}
ScenarioProvider --|> SampleChatProvider : extends
ChatProviderOpenAI --|> SampleChatProvider : extends
MitoCodeCLI --> ChatProviderOpenAI : creates
MitoCodeCLI --> AgentOrchestrator : configures
AgentOrchestrator --> SampleChatProvider : uses
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Configurable provider selection
  • ➕ Preserves offline ScenarioProvider demos and enables live OpenAI-compatible chat when requested.
  • ➕ Moves model, endpoint, and credentials out of source code.
  • ➕ Allows the existing speed option to remain meaningful for scripted playback.
  • ➖ Requires CLI flags or configuration loading and explicit validation.
  • ➖ Adds provider-selection branches at application startup.

Recommendation: Keep the provider-contract refactor, but select the runtime provider through configuration or CLI flags. Read credentials from environment or a secret store, default to ScenarioProvider for deterministic offline startup, and opt into ChatProviderOpenAI for live service access.

Files changed (2) +101 / -24

Enhancement (1) +26 / -1
__main__.pyUse an OpenRouter-backed OpenAI provider at CLI startup +26/-1

Use an OpenRouter-backed OpenAI provider at CLI startup

• Replaces the scripted ScenarioProvider with an asynchronously initialized ChatProviderOpenAI configured for an OpenRouter model. The file also adds unused imports and retains a commented manual chat probe; the existing speed argument no longer configures the selected provider.

src/mitocode/main.py

Bug fix (1) +75 / -23
scenario_provider.pyConform ScenarioProvider to the shared async provider contract +75/-23

Conform ScenarioProvider to the shared async provider contract

• Makes ScenarioProvider inherit from _SampleChatProvider and adds common constructor defaults, asynchronous factory and initialization hooks, model discovery, and delay validation. The chat method now matches the shared signature and can return either streamed chunks or an aggregated completion dictionary.

src/mitocode/backend/chat_provider/scenario_provider.py

@github-actions

Copy link
Copy Markdown
Contributor

CI 检查结果汇总

  • pytest: ✅ 通过 — 144 个测试,
    errors=0, failures=0, skipped=0
  • 覆盖率: ✅ 通过 — 81.26%(720/886 行)
  • gitleaks: ✅ 通过 — 发现 0 条潜在泄露
  • black: ✅ 已应用格式化 — 已自动格式化代码
  • pylint: ✅ 通过 — 评分 9.6/10,共 56 条问题

信息展示

  • pyright: 31 个 error, 0 个 warning
📋 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 输出
/home/runner/work/MitoCode/MitoCode/src/mitocode/backend/agent/agent_runtime.py
  /home/runner/work/MitoCode/MitoCode/src/mitocode/backend/agent/agent_runtime.py:91:32 - error: "Dict[Unknown, Unknown]" is not iterable
    "__aiter__" method not defined (reportGeneralTypeIssues)
/home/runner/work/MitoCode/MitoCode/src/mitocode/backend/agent/agent_session.py
  /home/runner/work/MitoCode/MitoCode/src/mitocode/backend/agent/agent_session.py:133:41 - error: Type "Unknown | None" is not assignable to declared type "_SampleChatProvider"
    Type "Unknown | None" is not assignable to type "_SampleChatProvider"
      "None" is not assignable to "_SampleChatProvider" (reportAssignmentType)
/home/runner/work/MitoCode/MitoCode/src/mitocode/backend/workspace/migration.py
  /home/runner/work/MitoCode/MitoCode/src/mitocode/backend/workspace/migration.py:75:35 - error: Parameter declaration "path" is obscured by a declaration of the same name (reportRedeclaration)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/backend/workspace/migration.py:92:54 - error: Operator "/" not supported for types "Path | str" and "Literal['.mitocode']"
    Operator "/" not supported for types "str" and "Literal['.mitocode']" (reportOperatorIssue)
/home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:286:13 - error: Argument of type "VisualType" cannot be assigned to parameter "renderable" of type "RenderableType" in function "__init__"
    Type "VisualType" is not assignable to type "RenderableType"
      Type "SupportsVisual" is not assignable to type "RenderableType"
        "SupportsVisual" is incompatible with protocol "ConsoleRenderable"
          "__rich_console__" is not present
        "SupportsVisual" is incompatible with protocol "RichCast"
          "__rich__" is not present
        "SupportsVisual" is not assignable to "str" (reportArgumentType)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:326:15 - error: Type "reactive[str]" is not assignable to declared type "property"
    "reactive[str]" is not assignable to "property" (reportAssignmentType)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:330:9 - error: Operator "+=" not supported for types "VisualType" and "str"
    Operator "+" not supported for types "ConsoleRenderable" and "str"
    Operator "+" not supported for types "RichCast" and "str"
    Operator "+" not supported for types "SupportsVisual" and "str"
    Operator "+" not supported for types "Visual" and "str" (reportOperatorIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:330:14 - error: "content" incorrectly overrides property of same name in class "Static" (reportIncompatibleMethodOverride)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:334:26 - error: Argument of type "VisualType" cannot be assigned to parameter "markup" of type "str" in function "__init__"
    Type "VisualType" is not assignable to type "str"
      "ConsoleRenderable" is not assignable to "str" (reportArgumentType)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:346:15 - error: Type "reactive[str]" is not assignable to declared type "property"
    "reactive[str]" is not assignable to "property" (reportAssignmentType)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:350:9 - error: Operator "+=" not supported for types "VisualType" and "str"
    Operator "+" not supported for types "ConsoleRenderable" and "str"
    Operator "+" not supported for types "RichCast" and "str"
    Operator "+" not supported for types "SupportsVisual" and "str"
    Operator "+" not supported for types "Visual" and "str" (reportOperatorIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:350:14 - error: "content" incorrectly overrides property of same name in class "Static" (reportIncompatibleMethodOverride)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:354:26 - error: Argument of type "VisualType" cannot be assigned to parameter "markup" of type "str" in function "__init__"
    Type "VisualType" is not assignable to type "str"
      "ConsoleRenderable" is not assignable to "str" (reportArgumentType)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:428:35 - error: Cannot access attribute "append" for class "Static"
    Attribute "append" is unknown (reportAttributeAccessIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:441:35 - error: Cannot access attribute "append" for class "Static"
    Attribute "append" is unknown (reportAttributeAccessIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:483:35 - error: Cannot access attribute "append_code" for class "Static"
    Attribute "append_code" is unknown (reportAttributeAccessIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:495:23 - error: Cannot access attribute "finalize" for class "Static"
    Attribute "finalize" is unknown (reportAttributeAccessIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:497:23 - error: Cannot access attribute "end" for class "Static"
    Attribute "end" is unknown (reportAttributeAccessIssue)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:756:17 - error: "root" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:756:31 - error: "root" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:757:32 - error: "root" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:758:18 - error: "select_node" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:759:18 - error: "scroll_to_node" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:822:25 - error: "select_node" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:823:25 - error: "scroll_to_node" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:902:31 - error: "value" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:908:33 - error: "value" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:931:29 - error: "value" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:991:24 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:993:31 - error: "get" is not a known attribute of "None" (reportOptionalMemberAccess)
  /home/runner/work/MitoCode/MitoCode/src/mitocode/tui/ui_main.py:997:25 - error: "set_widgets" is not a known attribute of "None" (reportOptionalMemberAccess)
31 errors, 0 warnings, 0 informations

自动提交状态: 已自动提交 ✅


由 CI 自动生成

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. CLI requires live model discovery 🐞 Bug ☼ Reliability
Description
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.
Code

src/mitocode/main.py[R72-74]

+    provider = asyncio.run(ChatProviderOpenAI.factory(
+        default_model= "nvidia/nemotron-3.5-lightning:free",
+        default_model_list= None,
Evidence
The new main path passes default_model_list=None into the asynchronous factory. The base factory
immediately calls init; OpenAI init calls get_model_list, and its exception path raises
MitoCodeChatProviderModelError whenever model_list is None.

src/mitocode/main.py[72-83]
src/mitocode/backend/chat_provider/sample_chat_provider.py[23-36]
src/mitocode/backend/chat_provider/chat_provider_openai.py[56-71]
src/mitocode/backend/chat_provider/chat_provider_openai.py[81-96]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


2. Non-streaming drops tool calls 🐞 Bug ≡ Correctness
Description
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.
Code

src/mitocode/backend/chat_provider/scenario_provider.py[R270-273]

+        full_content = ""
+        for c in chunks:
+            if c.choices[0].delta.content:
+                full_content += c.choices[0].delta.content
Evidence
Turns 0–2 explicitly emit fragmented tool-call chunks and finish with tool_calls, while the new
aggregation reads only content and returns no tool_calls field with finish_reason stop. The provider
contract requires a full OpenAI-format completion for non-streaming responses.

src/mitocode/backend/chat_provider/scenario_provider.py[233-260]
src/mitocode/backend/chat_provider/scenario_provider.py[267-286]
src/mitocode/backend/chat_provider/sample_chat_provider.py[112-131]
src/mitocode/backend/agent/agent_runtime.py[108-178]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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



Remediation recommended

3. Speed option is ignored 🐞 Bug ≡ Correctness
Description
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.
Code

src/mitocode/main.py[68]

-    provider = ScenarioProvider(delay=args.speed)
+    provider = asyncio.run(ChatProviderOpenAI.factory(
+        default_model= "nvidia/nemotron-3.5-lightning:free",
+        default_model_list= None,
+        default_messages= None,
+        default_tools= None,
+        stream= True,
+        settings={
+            "api_key": "sk-别看了这次我不会再把key提交到仓库了!",
+            "base_url": "https://openrouter.ai/api/v1",
+            "timeout": 60,
+        })
+    )
+
+    # print(asyncio.run(provider.chat(
+    #     model ="nvidia/nemotron-3.5-lightning:free",
+    #     tools =None,
+    #     messages = [
+    #         {"role": "system", "content": "You are a helpful assistant."},
+    #         {"role": "user", "content": "Hello!"}
+    #     ],
+    #     stream = False
+    # )))
Evidence
The parser describes --speed as an inter-chunk delay, while the new construction does not reference
args.speed. The only repository reference to --speed is this parser, and ChatProviderOpenAI forwards
streamed chunks without applying a delay.

src/mitocode/main.py[61-83]
src/mitocode/backend/chat_provider/chat_provider_openai.py[98-110]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


4. Factory discards delay argument 🐞 Bug ≡ Correctness
Description
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.
Code

src/mitocode/backend/chat_provider/scenario_provider.py[R209-212]

+    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
Evidence
The constructor stores the delay argument at line 177, factory always awaits init, and init resets
_delay to 0.03 unless settings contains delay. The stream then sleeps using this overwritten value.

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]
src/mitocode/backend/chat_provider/scenario_provider.py[262-265]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This changes the provider interface and runtime startup path, including async streaming/non-streaming behavior and a hardcoded API key, with enough independent logic that a careful single-pass review is warranted.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/mitocode/__main__.py
Comment on lines +72 to +74
provider = asyncio.run(ChatProviderOpenAI.factory(
default_model= "nvidia/nemotron-3.5-lightning:free",
default_model_list= None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Comment thread src/mitocode/__main__.py
tool_manager = ToolManager()
_register_tools(tool_manager)

provider = ScenarioProvider(delay=args.speed)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

Comment on lines +209 to +212
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

Comment on lines +270 to +273
full_content = ""
for c in chunks:
if c.choices[0].delta.content:
full_content += c.choices[0].delta.content

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant