fix(summarizer): fail loudly on a rejected model id + parallel map phase #72

Merged
sirius merged 1 commit from fix/summarizer-fail-loudly into master 2026-12-05 04:56:31 +00:00
Owner

Why

The analyst produced no briefs from 2025-11-25 to 2025-12-04 (last article_summaries row 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 every POST /v1/chat/completions returned 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)

  • Every non-200 logs status_code + the first 500 chars of the body.
  • 400 / 404 / 422 raise NousAPIError — a retired model id or rejected payload can never succeed on a retry. chat() no longer returns "" for those.
  • 429 / 5xx are retried inside the call (MAX_ATTEMPTS=3, exponential backoff, NOUS_RETRY_BACKOFF_S override), then still return "".
  • 401 keeps its old empty-return contract (the run fails loudly downstream instead).

2. Startup model validation (nous_client.model_available)

  • One GET {NOUS_BASE_URL}/models per process (memoised per base_url+model).
  • If SUMMARY_MODEL is not offered: ERROR with the configured id, the model count, and up to three near matches (difflib + same-org / same-family), and summarize_news() returns rc=2 without issuing a single chat call.
  • Fails open with a WARNING if /models itself is unreachable — chat() is loud enough on the real path.

3. Bounded map phase (summarizer.py)

  • map_phase(): ThreadPoolExecutor with a hard cap of SUMMARY_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.
  • Per-call retry/timeout unchanged (60 s text / 120 s json).
  • A NousAPIError cancels the queued batches and aborts the run.

4. Exit codes

  • summarize_news() -> int, __main__ does sys.exit(...).
  • Non-zero when: no API key (1), model missing (2), zero parsed map blocks (1), empty reduce (1), brief not persisted (1). Intentional skips stay 0.
  • run_news_summarizer.py logs rc != 0 at 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, /models fail-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:

NEWS_RECAP=1 NEWS_SUMMARIZE_FORCE=1 python summarizer.py
23:18:31 map phase: 746 batches (2984 articles), concurrency=16
23:34:17 summarize done kind=daily_recap summary_id=411 model=deepseek/deepseek-v4.1-flash-1017 batches=746/746 articles=2984 ticker=5 map=5 elapsed=950.5s
RC=0 ELAPSED_S=951

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 16384 escalation (8/746 batches, 1.1%). Row 411 verified in the DB: kind='daily_recap', 4633-char brief, 10 news_items, 2984 article_scores.

Incident replay with the retired id (SUMMARY_MODEL=meituan/longcat-2.5:free):

ERROR SUMMARY_MODEL='meituan/longcat-2.5:free' is not offered by .../v1 (413 models listed).
      Near matches: stepfun/step-3.7-flash:free. Runs are skipped until the model exists.
RC=2   (0.85 s, zero chat calls)

Notes

  • No schema change: article_summaries.kind stays interval / daily_recap.
  • BATCH_SIZE=4 and every prompt are unchanged; grading/rubric logic untouched.
  • Default concurrency is 16, not 8. Each call is ~20 s of wall time, so throughput tracks concurrency: a 5-batch probe at 8 took 39.6 s (7.9 s/batch → 746 batches projects to ~98 min, projection not a run), while the full run at 16 measured 951 s (0.78 batches/s). Set SUMMARY_MAP_CONCURRENCY=8 in the ConfigMap if the portal starts rate-limiting.
  • Deployment: pin osint-news-summarizer:amd64-<sha12 of this merge> in sirius/homek8s apps/base/osint/ (Flux), and add SUMMARY_MAP_CONCURRENCY: "16" to configmap.yaml osint-env.
  • The verification run already wrote today's real 24h recap (row 411), so the deployed pod's next recap will skip via the daily idempotency check.
## Why The analyst produced no briefs from 2025-11-25 to 2025-12-04 (last `article_summaries` row 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 every `POST /v1/chat/completions` returned 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`)** - Every non-200 logs `status_code` + the first 500 chars of the body. - `400 / 404 / 422` raise `NousAPIError` — a retired model id or rejected payload can never succeed on a retry. `chat()` no longer returns `""` for those. - `429 / 5xx` are retried inside the call (`MAX_ATTEMPTS=3`, exponential backoff, `NOUS_RETRY_BACKOFF_S` override), then still return `""`. - 401 keeps its old empty-return contract (the run fails loudly downstream instead). **2. Startup model validation (`nous_client.model_available`)** - One `GET {NOUS_BASE_URL}/models` per process (memoised per base_url+model). - If `SUMMARY_MODEL` is not offered: ERROR with the configured id, the model count, and up to three near matches (difflib + same-org / same-family), and `summarize_news()` returns **rc=2** without issuing a single chat call. - Fails open with a WARNING if `/models` itself is unreachable — chat() is loud enough on the real path. **3. Bounded map phase (`summarizer.py`)** - `map_phase()`: `ThreadPoolExecutor` with a hard cap of `SUMMARY_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. - Per-call retry/timeout unchanged (60 s text / 120 s json). - A `NousAPIError` cancels the queued batches and aborts the run. **4. Exit codes** - `summarize_news() -> int`, `__main__` does `sys.exit(...)`. - Non-zero when: no API key (1), model missing (2), zero parsed map blocks (1), empty reduce (1), brief not persisted (1). Intentional skips stay 0. - `run_news_summarizer.py` logs `rc != 0` at 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, `/models` fail-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: ``` NEWS_RECAP=1 NEWS_SUMMARIZE_FORCE=1 python summarizer.py 23:18:31 map phase: 746 batches (2984 articles), concurrency=16 23:34:17 summarize done kind=daily_recap summary_id=411 model=deepseek/deepseek-v4.1-flash-1017 batches=746/746 articles=2984 ticker=5 map=5 elapsed=950.5s RC=0 ELAPSED_S=951 ``` **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 16384` escalation (8/746 batches, 1.1%). Row 411 verified in the DB: `kind='daily_recap'`, 4633-char brief, 10 `news_items`, 2984 `article_scores`. Incident replay with the retired id (`SUMMARY_MODEL=meituan/longcat-2.5:free`): ``` ERROR SUMMARY_MODEL='meituan/longcat-2.5:free' is not offered by .../v1 (413 models listed). Near matches: stepfun/step-3.7-flash:free. Runs are skipped until the model exists. RC=2 (0.85 s, zero chat calls) ``` ## Notes - No schema change: `article_summaries.kind` stays `interval` / `daily_recap`. - `BATCH_SIZE=4` and every prompt are unchanged; grading/rubric logic untouched. - Default concurrency is **16**, not 8. Each call is ~20 s of wall time, so throughput tracks concurrency: a 5-batch probe at 8 took 39.6 s (7.9 s/batch → 746 batches projects to ~98 min, projection not a run), while the full run at 16 measured 951 s (0.78 batches/s). Set `SUMMARY_MAP_CONCURRENCY=8` in the ConfigMap if the portal starts rate-limiting. - Deployment: pin `osint-news-summarizer:amd64-<sha12 of this merge>` in `sirius/homek8s apps/base/osint/` (Flux), and add `SUMMARY_MAP_CONCURRENCY: "16"` to `configmap.yaml` `osint-env`. - The verification run already wrote today's real 24h recap (row 411), so the deployed pod's next recap will skip via the daily idempotency check.
The analyst produced no briefs for nine days because SUMMARY_MODEL had been
retired: every chat completion returned 404, nous_client.chat() swallowed it
into "", and the map phase "succeeded" with zero blocks.

- nous_client.chat(): log status_code + a 500-char body slice for every
  non-200. 400/404/422 now raise NousAPIError (bad model id / payload cannot
  succeed on a retry); 429/5xx are retried with backoff inside the call;
  401/other keep the old empty-return contract.
- Startup validation: one GET /models per process; if SUMMARY_MODEL is absent
  the run logs an ERROR with the configured id plus near matches and returns
  rc=2 before issuing any chat call. Fails open (warning) when /models itself
  is unreachable.
- Map phase: ThreadPoolExecutor fan-out capped by SUMMARY_MAP_CONCURRENCY
  (default 16). Grading still runs in batch order on the main thread; reduce
  stays serial; the 60 s per-call timeout is unchanged.
- summarize_news() now returns an exit code and __main__ sys.exit()s it:
  zero parsed map blocks, an empty reduce, or an unpersisted brief all exit
  non-zero. The scheduler logs rc at ERROR when it is not 0.
- Map calls start at 8192 completion tokens (they escalate to 16384): ~60% of
  real batches overflowed 4096 and were regenerated at 8192, doubling their
  wall time for no benefit.

Measured on the real backlog: NEWS_RECAP=1 NEWS_SUMMARIZE_FORCE=1
python summarizer.py over 2984 articles / 746 batches finished in 951 s
(15m51s), rc=0, 746/746 batches non-empty, 0 warnings.

Prompts, BATCH_SIZE=4, grading/rubric behaviour and the DB schema are
untouched (article_summaries.kind stays interval / daily_recap).
sirius merged commit fb5285df7f into master 2026-12-05 04:56:31 +00:00
sirius deleted branch fix/summarizer-fail-loudly 2026-12-05 04:56:31 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/osint-dashboard!72
No description provided.