runner: unit 의 호출이 끝나는 즉시 저장 — 중간에 끊어도 그때까지 끝난 unit 은 남는다
기존엔 프로그램의 호출을 전부 받은 뒤 한꺼번에 저장해서, 마지막 호출이 느리면 앞의 것도 잃었다 (고객사 실측: [8/9] 까지 ok 인 상태에서 9번째 대기). 저장은 여전히 메인 스레드에서만 한다. Ctrl+C 는 남은 호출을 취소하고 올라간다. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
ce459ba8f0
commit
5df8595fe2
@@ -204,3 +204,26 @@ def test_reload_keeps_chunks_for_unchanged_units(ingested, monkeypatch):
|
||||
assert con.execute("SELECT summary_status FROM program WHERE name='ZRUNNER_T1'").fetchone()[0] == "stale"
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
|
||||
|
||||
def test_run_calls_parallel_saves_each_call_on_main_thread_as_it_finishes():
|
||||
"""on_done 은 호출이 끝나는 대로, 메인 스레드에서 불린다 (중간 저장의 전제)."""
|
||||
import threading
|
||||
import time as _t
|
||||
from summarize import runner
|
||||
|
||||
class SlowLLM:
|
||||
usage = {}
|
||||
def complete_json(self, system, user):
|
||||
_t.sleep(0.3 if user == "slow" else 0.01)
|
||||
return {"unit_purpose_ko": user, "chunks": []}
|
||||
|
||||
calls = [{"prompt": "slow"}, {"prompt": "a"}, {"prompt": "b"}]
|
||||
seen = []
|
||||
main = threading.get_ident()
|
||||
runner._run_calls_parallel(SlowLLM(), calls, 3, on_done=lambda c: seen.append((c["prompt"], threading.get_ident())))
|
||||
assert [p for p, _ in seen][-1] == "slow" # 느린 호출이 끝나기 전에 빠른 것들이 먼저 저장된다
|
||||
assert {p for p, _ in seen} == {"slow", "a", "b"}
|
||||
assert all(tid == main for _, tid in seen)
|
||||
assert all("raw" in c for c in calls)
|
||||
|
||||
Reference in New Issue
Block a user