Skip to content

fix: avoid blocking Reactor scheduler thread during AutoContext compression#1079

Open
zhangliyuangit wants to merge 3 commits intoagentscope-ai:mainfrom
zhangliyuangit:fix/autocontext-compress-blocks-reactor-thread-1
Open

fix: avoid blocking Reactor scheduler thread during AutoContext compression#1079
zhangliyuangit wants to merge 3 commits intoagentscope-ai:mainfrom
zhangliyuangit:fix/autocontext-compress-blocks-reactor-thread-1

Conversation

@zhangliyuangit
Copy link
Copy Markdown

When compression is triggered in handlePreReasoning, compressIfNeeded() internally calls .block() for LLM-based summarization. Running this on the Reactor scheduler thread stalls downstream streaming chunk dispatch, causing all chunks to be flushed at once instead of incrementally.

Fix: wrap compressIfNeeded() in Mono.fromCallable(...).subscribeOn(Schedulers.boundedElastic()) so blocking work runs on the elastic thread pool.

@zhangliyuangit zhangliyuangit requested a review from a team March 30, 2026 10:21
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…ession

When AutoContextMemory compression is triggered in handlePreReasoning,
compressIfNeeded() internally calls .block() for LLM-based summarization.
Running this on the Reactor scheduler thread causes the thread to be
occupied until compression completes, preventing downstream streaming
chunks from being dispatched. This results in all chunks being flushed
at once after the entire Mono chain completes, breaking incremental
streaming.

Fix: wrap compressIfNeeded() in Mono.fromCallable(...).subscribeOn(
Schedulers.boundedElastic()) so the blocking work runs on the elastic
thread pool, keeping the Reactor scheduler thread free to dispatch
streaming chunks incrementally.

Also extract the event-building logic into a dedicated buildUpdatedEvent()
method for clarity.
@zhangliyuangit zhangliyuangit force-pushed the fix/autocontext-compress-blocks-reactor-thread-1 branch from 505a996 to b199c2d Compare March 30, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant