Async `Compactor` protocol to replace sync↔async bridge in `LLMSummarizeCompactor`
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- python
調査の方向性
Start in mellea/stdlib/context/compactor.py, where _run_coro_blocking and LLMSummarizeCompactor.compact() live, then find the react() call site that invokes the compactor. The issue proposes an async acompact() on the Compactor protocol, so the change touches the protocol, the summarizer and react(), and the existing test_base_exceptions_propagate must keep passing. Done means react() awaits acompact(), compact() still works from sync scripts, and the Warning: docstrings can be removed. The design is still open, so confirm the approach with maintainers before coding.
索引モデルが issue の本文から書いたものです。
説明
Background
LLMSummarizeCompactor.compact() is sync but its body needs to call an async backend. We currently bridge via the private helper _run_coro_blocking in mellea/stdlib/context/compactor.py, which:
- Outside any event loop: calls
asyncio.run(coro)(fresh, disposable loop). - Inside a running event loop: spawns a worker thread running its own fresh
asyncio.run.
Surfaced during review of #996 — see the discussion thread on _run_coro_blocking for full context.
Problem
The bridge has two real failure modes that are surfaced in the docstring as Warning: paragraphs but cannot be fixed without changing the protocol:
-
Outside-loop case — cross-loop client mismatch. A backend whose
httpx.AsyncClientis bound to mellea's shared event loop (created viamellea.helpers._run_async_in_thread) cannot be used from_run_coro_blocking's fresh worker loop. The typical symptom isRuntimeError: This event loop is already runningor a hung request. -
Inside-loop case — outer loop blocking. When called from inside
react(), the worker thread blocks the calling thread — and therefore the outer event loop — for the full duration of the coroutine. Scheduled callbacks, telemetry flushers, cancellation signals, and any other concurrent tasks on the same loop are stalled until summarisation completes. Ac
Why we are not landing a smaller fix
@planetf1 and @markstur offered two interim suggestions that came up during PR #996 review and were deferred to this issue:
1. Route through _run_async_in_thread. bridge to mellea.helpers.event_loop_helper._run_async_in_thread, which would close failure mode 1 (the shared-loop bridge dispatches onto the loop where backend clients live). We tried it and reverted — it changes KeyboardInterrupt propagation semantics and broke `test_base_exc
2. Add a timeout= parameter.
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
future = pool.submit(asyncio.run, coro)
try:
return future.result(timeout=timeout)
except concurrent.futures.TimeoutError as exc:
raise TimeoutError(
f"Compactor backend call exceeded {timeout}s timeout"
) from exc
Same shape as the _allow_inside_loop discussion: it adds API surface that the async Compactor protocol obsoletes — once compact() is awaitable, callers wrap with asyncio.wait_for in one line. Backend calls already raise on network/HTTP timeouts, so the residual hang risk is small. We'd rather not land an intermediate timeout knob and remove it next cy
Proposed resolution
Add an async variant on the Compactor protocol:
class Compactor(Protocol):
def compact(self, ctx: T, *, backend: Backend | None = None) -> T: ...
async def acompact(self, ctx: T, *, backend: Backend | None = None) -> T: ...
- Sync
compact()stays for sync callers (manual invocation between turns from a.pyscript, etc.). - Async
acompact()is whatreact()and any other async caller awaits — no bridge, no loop blocking, no cross-loop client issues. LLMSummarizeCompactor.acompact()becomes the natural home for what_async_compactalready does;compact()keeps the bridge as a thin sync wrapper for backwards compatibility (or deprecates it eventually).
This obsoletes _run_coro_blocking for the inside-loop path entirely and removes the cross-loop hazard for async callers.
Acceptance criteria
-
Compactorprotocol gainsasync def acompact(...). -
LLMSummarizeCompactorimplementsacompact()natively (no_run_coro_blocking). -
react()callsawait compactor.acompact(...)instead ofcompactor.compact(...). - Sync
compact()still works for manual usage from sync scripts. - Existing tests pass, including
test_base_exceptions_propagate(Ctrl-C semantics). - Docstring
Warning:paragraphs about loop blocking and cross-loop client mismatch can be removed from_run_coro_blocking/LLMSummarizeCompactor.
Related
- PR #996 — original compaction work that introduced
_run_coro_blockingand surfaced these concerns mellea/stdlib/context/compactor.py:_run_coro_blocking— current bridgemellea/helpers/event_loop_helper.py:_run_async_in_thread— the shared bridge that motivated the discussion
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 161
- 平均マージ
- 4日 3時間
- マージ済み PR(30日)
- 45
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
generative-computing/mellea のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
generative-computing/mellea#1864 ·
メンテナーはふだん 3 日以内に返信
-
bug: instruct() and react() replay tool-call turns without tool_calls対応中かも @simonyang08 が 21 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
generative-computing/mellea#1784 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examples対応中かも @madhusudhan1260 が 18 日前に担当しました。 オープンgood first issue p2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
generative-computing/mellea#1780 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
area/telemetry enhancement p2
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
generative-computing/mellea#1210 ·
メンテナーはふだん 3 日以内に返信
-
area/requirement area/stdlib enhancement p2
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
generative-computing/mellea#31 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
generative-computing/mellea の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
OpenFreeEnergy/openfe#2371 ·
メンテナーはふだん 2 日以内に返信
-
HMDB's smiles file writes "None" for metabolites with an empty <smiles/> (file not currently used)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
NCATSTranslator/Babel#1269 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 80/100
メンテナーはふだん 1 日以内に返信
-
404 on sample dataオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
bcgov/nr-hydrometric-rating-curve#443 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100