Skip to content

fix(llm): keep a graph build alive when the output limit is reached - #98

Merged
akozak-gd merged 1 commit into
mainfrom
fix/llm-warm-up-output-limit
Nov 9, 2026
Merged

akozak-gd merged 1 commit into
mainfrom
fix/llm-warm-up-output-limit

Conversation

@akozak-gd

Copy link
Copy Markdown
Contributor

Problem

After the AWS deployment, a graph build of a small file failed with:

"error_code": "llm_fatal", "error_fields": {"call_class": "extraction", "prompt": "nodes.warmup.1",
"model": "openai/gpt-5.6-terra", "status": 400, "provider_code": null}

Bifrost logged: Could not finish the message because max_tokens or model output limit was reached.

Causes:

  • The prompt-cache warm-up (Gateway.warm_up) allowed only 16 output tokens. A reasoning model spends those on reasoning before it writes any answer.
  • With a strict json_schema, OpenAI rejects a cut-off answer with a 400 instead of returning finish_reason="length".
  • _raise_unless_retryable treats 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 400 → truncation. A 400 whose message reports the output limit (OUTPUT_LIMIT_MARKERS) now raises LLMError("truncated"). Extraction then splits the window the same way it does for finish_reason="length".
  • Best-effort warm-up. If a warm-up fails, it is logged as 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.
  • Warm-up output limit 16 → 400 tokens, so reasoning models can finish the warm-up.

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 in tests/test_mcp_qa_lib.py (*_kills_the_whole_process_group). Those 3 fail the same way on unchanged main in my local environment and don't touch this code.

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.
@akozak-gd
akozak-gd merged commit 57ad7ad into main Nov 9, 2026
15 checks passed
@akozak-gd
akozak-gd deleted the fix/llm-warm-up-output-limit branch November 9, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants