fix(context-compression): make extract_task_goal fire-and-forget (#1909)#1922
Merged
fix(context-compression): make extract_task_goal fire-and-forget (#1909)#1922
Conversation
aed7116 to
8ba1749
Compare
Previously, `maybe_refresh_task_goal()` called `extract_task_goal()` with a blocking 5-second `.await` during every Soft tier compaction. On cloud providers (OpenAI, Claude) where inference latency exceeds 5s under concurrent load, this always timed out — adding 5s of user-visible latency and leaving `current_task_goal = None`, making `task_aware`/`mig`/`task_aware_mig` strategies functionally identical to `reactive`. Fix: two-phase non-blocking design (mirrors `maybe_sidequest_eviction`): - Phase 1 (apply): if the background task spawned last compaction has finished, apply its result to `current_task_goal` via `JoinHandle::is_finished()` + `now_or_never()`. - Phase 2 (schedule): if the user message hash changed and no task is in-flight, spawn a new background `tokio::spawn`. Current compaction uses the cached goal from the previous turn — zero blocking. Also raises the background task timeout from 5s to 30s, giving cloud providers a realistic window to respond without ever blocking the agent loop.
b9a8f57 to
f2b5c94
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
maybe_refresh_task_goal()blocked Soft tier compaction for up to 5s on every event, makingtask_aware/mig/task_aware_migstrategies non-functional for cloud LLM providers (closes fix(context-compression): extract_task_goal blocks Soft tier for 5s on every compaction — task_aware/mig strategies effectively broken for cloud LLMs #1909)async fn+.awaitwith a two-phase non-blocking design mirroringmaybe_sidequest_evictionpending_task_goal: Option<JoinHandle<Option<String>>>field toAgent; background task is spawned when user message hash changes; result applied at start of next Soft compaction viais_finished()+now_or_never()Root cause
extract_task_goal()calledsummary_or_primary_provider().chat()with a hardcoded 5s timeout inside the Soft compaction hot path. Cloud API latency regularly exceeds 5s under concurrent inference, so it always timed out — leavingcurrent_task_goal = Noneand falling back toprune_tool_outputs_oldest_first().Test plan
cargo +nightly fmt --check— cleancargo clippy --features full --workspace -- -D warnings— cleancargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins— 6047 passed, 12 skippedpruning_strategy = "task_aware"and a cloud provider to verify no timeout log entries and goal is populated after the second compaction