Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Released versions are named in the entry title; the version on PyPI is
[deepcode-hku](https://pypi.org/project/deepcode-hku/). 中文版见
[CHANGELOG_ZH.md](CHANGELOG_ZH.md).

## 2026-11-26 · Fixes

- **Slow model calls no longer abort Paper2Code.** The implementation phase
again leaves time spent waiting on the model, and time spent before the
loop starts (such as creating the file tree), out of its five-minute stall
check, so one slow response no longer ends the run as a progress stall.

## 2026-11-23 · Community fixes

- **Test every MCP server at once.** `deepcode mcp test --all` probes each
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ DeepCode 的主要变化,最新的在前,每天一条。正式版本号写
PyPI 上的包名是 [deepcode-hku](https://pypi.org/project/deepcode-hku/)。
English: [CHANGELOG.md](CHANGELOG.md).

## 2026-11-26 · 修复

- **模型响应慢不再中断 Paper2Code。** 代码实现阶段的五分钟停滞检测重新排除等待
模型的时间,以及进入实现循环之前(例如创建文件树)花掉的时间,一次较慢的响应
不会再让整次运行以“进度停滞”结束。

## 2026-11-23 · 社区修复

- **一次测试所有 MCP 服务器。** `deepcode mcp test --all` 依次检查每个已启用的
Expand Down
58 changes: 58 additions & 0 deletions tests/test_unified_impl_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from __future__ import annotations

import asyncio
import json
import sys
from pathlib import Path
Expand Down Expand Up @@ -600,3 +601,60 @@ async def attach(_agent, **_kwargs):
await CodeImplementationWorkflow().create_file_structure("plan", str(tmp_path))

assert seen == [str(tmp_path / "generate_code")]


class SlowImplProvider(ImplScriptedProvider):
"""Each tool-loop call takes ``delay`` seconds, like a slow model."""

def __init__(self, responses: list[LLMResponse], delay: float):
super().__init__(responses)
self.delay = delay

async def chat_with_retry(self, **kwargs: Any) -> LLMResponse:
if kwargs.get("tools"):
await asyncio.sleep(self.delay)
return await super().chat_with_retry(**kwargs)


def _write_planned_files() -> list[LLMResponse]:
return [
LLMResponse(
content=f"Implementing {path}",
tool_calls=[
_tool_call(f"w{i}", "write_file", {"file_path": path, "content": "x"})
],
finish_reason="tool_calls",
)
for i, path in enumerate(PLANNED_FILES)
]


@pytest.mark.asyncio
async def test_slow_model_calls_do_not_count_as_a_stall(tmp_path, monkeypatch):
workflow = _make_workflow(monkeypatch)
workflow.loop_detector.stall_threshold = 0.2
provider = SlowImplProvider(_write_planned_files(), delay=0.3)

await _run(workflow, provider, tmp_path)

state = workflow._last_run_state
assert state["status"] == "completed", state["reason"]
assert state["files_completed"] == len(PLANNED_FILES)


@pytest.mark.asyncio
async def test_time_before_the_implementation_loop_is_not_a_stall(
tmp_path, monkeypatch
):
workflow = _make_workflow(monkeypatch)
# The detector is built with the workflow; the file-tree phase runs
# (and may take minutes) before the implementation loop starts.
detector = workflow.loop_detector
detector.last_progress_time -= detector.stall_threshold + 60
provider = ImplScriptedProvider(_write_planned_files())

await _run(workflow, provider, tmp_path)

state = workflow._last_run_state
assert state["status"] == "completed", state["reason"]
assert state["files_completed"] == len(PLANNED_FILES)
13 changes: 13 additions & 0 deletions workflows/code_implementation_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ class _ImplementationHook(AgentHook):
def __init__(self, state: _RunState):
super().__init__()
self._state = state
self._model_request_started: Optional[float] = None

async def before_model_request(self, context: AgentHookContext) -> None:
self._model_request_started = time.time()

async def on_model_response(self, context: AgentHookContext) -> None:
# A slow model round-trip is not a stalled run.
started, self._model_request_started = self._model_request_started, None
if started is not None:
self._state.loop_detector.note_llm_wait(time.time() - started)

async def before_execute_tools(self, context: AgentHookContext) -> None:
self._state.in_tools_phase = True
Expand Down Expand Up @@ -967,6 +977,9 @@ async def on_retry_wait(message: str) -> None:
llm_timeout_s=0,
)

# The detector was built with the workflow; the file-tree phase ran
# since then and is not a stall of this loop.
self.loop_detector.record_progress()
runner = AgentRunner(provider)
result = await runner.run(spec)

Expand Down