fix: deduplicate Work execution batches

This commit is contained in:
wuyang
2026-07-26 14:11:57 +08:00
parent 44fe0b3dd7
commit ae5f940a5d
2 changed files with 76 additions and 12 deletions
+47
View File
@@ -433,6 +433,53 @@ async def test_unchanged_failed_command_is_blocked_until_a_repair(settings) -> N
await store.close()
async def test_duplicate_commands_in_one_model_response_execute_once(settings) -> None:
batch = {
"choices": [
{
"message": {
"role": "assistant",
"tool_calls": [
tool_call("1", "write_file", {"path": "sort.py", "content": "print('ok')"}),
tool_call("2", "exec", {"command": "python3 sort.py"}),
tool_call("3", "exec", {"command": "python3 sort.py"}),
tool_call("4", "exec", {"command": "python3 sort.py"}),
],
},
"finish_reason": "tool_calls",
}
]
}
final = {"choices": [{"message": {"role": "assistant", "content": "完成"}, "finish_reason": "stop"}]}
provider = ScriptedProvider([batch, final])
registry = RecordingRegistry()
store = RuntimeStore(settings.database_url)
await store.initialize()
async def callback(event_type, payload):
return None
try:
answer = await AgentLoop(provider, registry, store, max_tool_output_chars=10_000).run(
spec=get_model_spec("work-light"),
messages=[{"role": "user", "content": "写脚本并运行"}],
identity=UserIdentity("u1", "", "", "user"),
raw_user_jwt="jwt",
chat_id="c1",
callback=callback,
)
assert answer == "完成"
assert [name for name, _ in registry.calls] == ["write_file", "exec"]
duplicate_results = [
message
for message in provider.requests[1]["messages"]
if message.get("role") == "tool" and "duplicate command" in message.get("content", "")
]
assert len(duplicate_results) == 2
finally:
await store.close()
async def test_script_delivery_requires_successful_execution(settings) -> None:
write = {
"choices": [