fix(wiki): recover from streamed chunk-repetition abort instead of failing the page (RES-947) - #334
Open
jhkchan wants to merge 1 commit into
Open
fix(wiki): recover from streamed chunk-repetition abort instead of failing the page (RES-947)#334jhkchan wants to merge 1 commit into
jhkchan wants to merge 1 commit into
Conversation
…iling the page (RES-947) Dense OCR'd tables prime the wiki model to reproduce giant `---` GFM separator walls; litellm's streaming repetition guard then aborts with `MidStreamFallbackError: ... The model is repeating the same chunk = ...`, and the exception propagated up to the "subtopic page failed hard" branch — the page fell back to empty on the exact content type dominant in an architecture corpus (drawing schedules, dimension tables). Handle it at the source in `_llm_generate_json`: the repetition guard only runs in litellm's streaming handler, so when a streamed dispatch aborts with a repetition error we retry the call once non-streamed. The full (possibly still dash-heavy) content then flows to `_call_llm`'s existing `_is_degenerate_content` dash-wall guard → deterministic Key Facts splice, instead of crashing. Because the fix lives in the shared helper, every page kind inherits it. - Adds `_is_stream_repetition_abort(exc)` (message-substring primary signal; `MidStreamFallbackError` isn't exported at litellm top level). - Adds `stream_override` param to `_llm_generate_json` (forces stream on/off). - Non-repetition errors are re-raised unchanged; no retry when already non-streamed. Adds tests/wiki/test_compiler_stream_repetition.py (detector, retry-recovers, re-raises-other-errors, no-retry-when-non-streamed). Existing degenerate-guard and retry-gating suites still pass (17 passed). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PMMM6KQXmzAEA42UxpyMUm
Member
Author
|
Independent adversarial review — APPROVE (nits only). No P0/P1 defect. Verified against the installed litellm: the real production exception from Nits (follow-up):
|
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.
Problem (RES-947)
Dense OCR'd tables prime the wiki model to reproduce giant
---GFM separator walls. litellm's streaming repetition guard aborts withMidStreamFallbackError: ... The model is repeating the same chunk = ..., which propagated to the "subtopic page failed hard" branch → the page fell back to empty. This hits the exact content dominant in an architecture/engineering corpus (drawing schedules, dimension tables).Live evidence (RLP POC):
WikiCompiler: subtopic page failed hard (litellm.MidStreamFallbackError: litellm.InternalServerError: The model is repeating the same chunk = ------…).Fix
Handle it at the source in
_llm_generate_json. The repetition guard only runs in litellm's streaming handler, so when a streamed dispatch aborts with a repetition error, retry the call once non-streamed. The full content then flows to_call_llm's existing_is_degenerate_contentdash-wall guard → deterministic Key Facts splice, rather than crashing. Fix lives in the shared helper, so every page kind inherits it (overview/people/activity/resources/glossary/subtopic)._is_stream_repetition_abort(exc)— message-substring is the robust primary signal (MidStreamFallbackErrorisn't exported at litellm top level).stream_overrideparam on_llm_generate_json.Tests
tests/wiki/test_compiler_stream_repetition.py: detector; streamed-abort → non-streamed retry returns good content (dispatch called stream=True then stream=False); non-repetition errors propagate; no retry when already non-streamed. Existingtest_compiler_degenerate_guard+test_compiler_retry_gatingstill pass — 17 passed locally.Part of epic RES-943 (RLP full-corpus scale + no-cloud gaps).
🤖 Generated with Claude Code
https://claude.ai/code/session_01PMMM6KQXmzAEA42UxpyMUm