Repository navigation
fix(llm): keep a graph build alive when the output limit is reached - #98
Merged
Merged
Conversation
On an OpenAI model behind Bifrost a graph build failed with llm_fatal on the
nodes warm-up. With a strict json_schema, OpenAI answers a cut-off response
with a 400 ("Could not finish the message because max_tokens or model output
limit was reached") instead of finish_reason "length", and the gateway took
any unknown 400 for a configuration error. The warm-up allowed only 16 output
tokens, which a reasoning model spends before it writes any answer.
- A 400 that reports the output limit is now LLMError("truncated"), so
extraction splits the window as it does for finish_reason "length".
- The warm-up is best effort: a failed one is logged
(graph.llm.warm_up_failed) and the calls run without it; LLMFatalError
(credentials, model, endpoint) still raises.
- The warm-up output limit is 400 tokens instead of 16.
mlkonopelski
approved these changes
Nov 9, 2026
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
After the AWS deployment, a graph build of a small file failed with:
Bifrost logged: Could not finish the message because max_tokens or model output limit was reached.
Causes:
Gateway.warm_up) allowed only 16 output tokens. A reasoning model spends those on reasoning before it writes any answer.json_schema, OpenAI rejects a cut-off answer with a 400 instead of returningfinish_reason="length"._raise_unless_retryabletreats any unrecognized 400 as a configuration error (LLMFatalError), so the whole build failed, even though the warm-up's answer is discarded anyway.Change
All in
backend/src/graph/core/llm/gateway.py:OUTPUT_LIMIT_MARKERS) now raisesLLMError("truncated"). Extraction then splits the window the same way it does forfinish_reason="length".graph.llm.warm_up_failed(with the reason) and counted as a failed call, and the real calls run without it.LLMFatalError(401/403/404, wrong credentials, model or endpoint) still stops the build.How I checked it
tests/test_graph_gateway.py: all 110 pass, including new cases for the output-limit 400 (truncated, not fatal) and for a failed warm-up that does not raise.make validate: passes.make check: 8494 passed; 3 failed intests/test_mcp_qa_lib.py(*_kills_the_whole_process_group). Those 3 fail the same way on unchangedmainin my local environment and don't touch this code.