{"record":{"id":"451f41e892f321aa","repo":"zylon-ai/private-gpt","slug":"condensed-history-exceeds-maximum-length-after-app","errorCode":null,"errorMessage":"Condensed history exceeds maximum length after applying condensation strategy.","messagePattern":"Condensed history exceeds maximum length after applying condensation strategy\\.","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"private_gpt/components/chat/processors/chat_history/memory/tldr_processor.py","lineNumber":159,"sourceCode":"        condensation_timeout,\n        **kwargs,\n    )\n\n    # 4. Build final history with TLDR\n    condensed_history, condense_blocks = await asyncio.to_thread(\n        build_condensed_history,\n        system_messages=system_messages,\n        conversation_history=conversation_history,\n    )\n\n    current_token_count = await estimate_token_count(\n        condensed_history,\n        tokenizer_fn=tokenizer_fn,\n        message_to_input=message_to_input,\n        **kwargs,\n    )\n    if current_token_count > max_length:\n        raise ValueError(\n            \"Condensed history exceeds maximum length after applying condensation strategy.\"\n        )\n\n    logger.debug(\n        \"Applied condensation strategy '%s' to conversation history. \"\n        \"Current token count: %d, Available max length: %d, Max length: %d\",\n        strategy_type,\n        current_token_count,\n        remaining_max_length,\n        max_length,\n    )\n    yield CondenseResponse(\n        is_condensed=True,\n        chat_history=condensed_history,\n        condense_blocks=condense_blocks,\n    )\n\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/chat/processors/chat_history/memory/tldr_processor.py#L141-L177","documentation":"Post-condition check in the TLDR processor: after build_condensed_history assembled system messages + condensed conversation history, the final token count still exceeds max_length. The chosen strategy produced a summary/trimmed history that, together with the always-kept system messages, is too large for the budget.","triggerScenarios":"Running the tldr condense flow where system_token_count < max_length (passes error 41) but system + condensed history > max_length; the remaining_max_length given to the strategy is too small for the summary it generates.","commonSituations":"Large system prompt leaving a tiny remaining budget; an LLM-generated TLDR summary longer than the space left; aggressive keep-last-N strategy with many retained turns.","solutions":["Increase max_length so remaining budget after system messages fits a typical summary","Lower the number of recent messages retained by the strategy","Cap the summary output length in the strategy's LLM prompt","Shrink the system prompt to free budget (see also error 41)"],"exampleFix":"# before\ncondensed = build_condensed_history(system_messages, strategy_result)\n# may exceed max_length\n\n# after\ncondensed = build_condensed_history(system_messages, strategy_result)\nassert await estimate_token_count(condensed, ...) <= max_length","handlingStrategy":"fallback","validationCode":"remaining = max_length - system_token_count\nif remaining < min_summary_budget:\n    raise ConfigError(f\"only {remaining} tokens left for condensed history\")","typeGuard":null,"tryCatchPattern":"try:\n    async for resp in condense(...):\n        ...\nexcept ValueError as e:\n    if \"exceeds maximum length after applying\" in str(e):\n        # fall back to hard truncation of the condensed history\n        condensed = condensed[:keep_last_n]\n    else:\n        raise","preventionTips":["Cap summary length in the strategy's prompt","Retain fewer recent turns when the system prompt grows","Monitor remaining_max_length vs actual condensed size in debug logs"],"tags":["chat-history","condensation","token-limit","summary"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}