fix(extraction): cap concurrent LLM calls to stop aegis-burst timeout cascade#86
Merged
Merged
Conversation
… cascade When aegis intelligence (worker/.../intelligence.py) pushes its daily arxiv batch (~30–50 summaries in seconds), every ingestion job hits qwen3:14b at once. Ollama on asif serves ~2–4 in parallel, so the tail queues inside Ollama past the 600s read timeout, retries (KS ×2, LiteLLM ×2) snowball back into the same queue, and the whole class falls to 0 triples. Prod signature: 11+ ReadTimeouts clustered in ~2s about 10 min after a burst. Fix: ExtractionClient now holds an asyncio.Semaphore around the LLM POST, sized via settings.extraction_max_concurrent (default 4, env EXTRACTION_MAX_CONCURRENT). The semaphore wraps just the request, not the retry backoff, so a failing call doesn't hog a slot. This moves the queue from Ollama-side (where read_timeout fires) to KS-side (where it doesn't). Repro mirrored prod: 30 concurrent realistic prompts via KS's exact httpx config → median 313s, max 593s, 2 ReadTimeouts at 600.1s, zero PoolTimeouts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
ExtractionClientholds anasyncio.Semaphorearound the LLM POST, sized viasettings.extraction_max_concurrent(default4, envEXTRACTION_MAX_CONCURRENT). The semaphore wraps just the request, not the retry backoff, so a failing call doesn't hog a slot during its exponential sleep. This shifts the queue from Ollama-side (where read_timeout fires) to KS-side (where it doesn't).What this is not
num_retries: 2. That's a multiplier on top of this cap and worth dropping later, but a separate change in homelab-gitops.Reproduction
Local repro mirroring KS's exact
httpx.Timeout(connect=5, read=600, write=10, pool=5)against prod LiteLLM, 30 concurrent realistic extraction prompts:Median per-call latency at burst = 313s (>5 min). 2 calls hit the 10-min boundary. Zero
PoolTimeout— it's pure queueing on qwen3.Test plan
TestConcurrencyCap::test_inflight_never_exceeds_cap— fires 12 concurrent_post_chatcalls at a slow stub and asserts max-in-flight ≤ cap. Fails onmain, passes here.TestConcurrencyCap::test_default_cap_is_set— guards against accidentally removing the semaphore.pytest tests/ -v— 703 passed.ruff check .— clean.ruff format --check .— clean.aegis_knowledgelogs after the next aegis intelligence batch; expect the burst tail to take ~2 min instead of timing out. NoLLM API request timed outclusters.🤖 Generated with Claude Code