fix(summarizer): fail loudly on a rejected model id + parallel map phase #72
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/summarizer-fail-loudly"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
The analyst produced no briefs from 2025-11-25 to 2025-12-04 (last
article_summariesrow before this fix: id 410,meituan/longcat-2.5:free, 2025-11-25 03:31Z). The model had been retired from the Nous Portal, so everyPOST /v1/chat/completionsreturned 404;nous_client.chat()swallowed anything that was not 401/5xx into"", the map phase "succeeded" with zero blocks and the pod idled for nine days.Separately, a 24h recap was far too slow: 2985 articles → 746 batches at BATCH_SIZE=4, serial, ≈3.3 h.
What changed
1. Fail loudly (
nous_client.py)status_code+ the first 500 chars of the body.400 / 404 / 422raiseNousAPIError— a retired model id or rejected payload can never succeed on a retry.chat()no longer returns""for those.429 / 5xxare retried inside the call (MAX_ATTEMPTS=3, exponential backoff,NOUS_RETRY_BACKOFF_Soverride), then still return"".2. Startup model validation (
nous_client.model_available)GET {NOUS_BASE_URL}/modelsper process (memoised per base_url+model).SUMMARY_MODELis not offered: ERROR with the configured id, the model count, and up to three near matches (difflib + same-org / same-family), andsummarize_news()returns rc=2 without issuing a single chat call./modelsitself is unreachable — chat() is loud enough on the real path.3. Bounded map phase (
summarizer.py)map_phase():ThreadPoolExecutorwith a hard cap ofSUMMARY_MAP_CONCURRENCY(default 16). Grading (parse_map_scores+ geo fill) still runs on the main thread in batch order, so the reduce input is deterministic. Reduce stays serial.NousAPIErrorcancels the queued batches and aborts the run.4. Exit codes
summarize_news() -> int,__main__doessys.exit(...).run_news_summarizer.pylogsrc != 0at ERROR.5. Map calls start at 8192 completion tokens (escalation to 16384 kept). Measured: ~60% of real batches overflowed 4096 and were regenerated at 8192, doubling their wall time for nothing. Prompts are untouched.
Verification
Unit tests:
cd news/summerizer && python -m pytest tests -q→ 182 passed (baseline master 161). New coverage: non-200 →NousAPIError, 429 retry, 5xx cap, body-slice logging, missing model (no chat calls, rc=2), near matches,/modelsfail-open, all-empty map → rc=1, API error → rc=1, unpersisted brief → rc=1, concurrency cap never exceeded (peak == N), ordered grading with out-of-order finishes, cancel-on-hard-error.Live, real backlog (2984 articles, 746 batches,
deepseek/deepseek-v4.1-flash-1017), forced recap:951 s = 15 min 51 s, 746/746 batches non-empty, zero errors. The only 8 WARNINGs are the
benign
hit max_tokens → retrying with 16384escalation (8/746 batches, 1.1%). Row 411 verified in the DB:kind='daily_recap', 4633-char brief, 10news_items, 2984article_scores.Incident replay with the retired id (
SUMMARY_MODEL=meituan/longcat-2.5:free):Notes
article_summaries.kindstaysinterval/daily_recap.BATCH_SIZE=4and every prompt are unchanged; grading/rubric logic untouched.SUMMARY_MAP_CONCURRENCY=8in the ConfigMap if the portal starts rate-limiting.osint-news-summarizer:amd64-<sha12 of this merge>insirius/homek8s apps/base/osint/(Flux), and addSUMMARY_MAP_CONCURRENCY: "16"toconfigmap.yamlosint-env.