Async `Compactor` protocol to replace sync↔async bridge in `LLMSummarizeCompactor`
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- python
- Lĩnh vực
- ai-infra-agents
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 1.8k
- Fork
- 161
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 45
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của generative-computing/mellea
-
bug: `mellea.plugins.builtin_debug.generation.log_generation_post_call` shows model as unknownĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
generative-computing/mellea#1864 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug: instruct() and react() replay tool-call turns without tool_callsCó thể đã có người làm @simonyang08 đã nhận 21 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
generative-computing/mellea#1784 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examplesCó thể đã có người làm @madhusudhan1260 đã nhận 18 ngày trước. Đang mởgood first issue p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
generative-computing/mellea#1780 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
area/telemetry enhancement p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
generative-computing/mellea#1210 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Add requirement priorityĐang mởarea/requirement area/stdlib enhancement p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
generative-computing/mellea#31 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của generative-computing/mellea
Issue tương tự
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
jxxghp/MoviePilot#7576 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
jbaruch/software-factory#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày