Skip to content

Community labeling returns empty content with reasoning models (reasoning consumes the completion budget; split-retry reduces the budget further) #3747

Open

Description

@sitechfromgeorgia

What happens

Community labeling (graphify label) returns empty completions and falls back to Community N placeholders when the backend is an OpenAI-compatible reasoning model (custom provider via graphify provider add). Every batch fails, including after the adaptive split-retries:

[graphify label] batch of 2 still unparseable at depth 3 (cids=[0, 1]): label response is not parseable JSON: ''
[graphify label] batch 1/1 (20 communities) failed: label response is not parseable JSON: ''
[graphify label] warning: community labeling failed (...); using Community N placeholders.

Environment

  • graphify 0.9.65 (uv tool install "graphifyy[openai]", Linux, Python 3.11, Node not involved)
  • Custom provider: graphify provider add myendpoint --base-url https://api.commandcode.ai/provider/v1 --default-model deepseek/deepseek-v4.1-flash --env-key COMMANDCODE_API_KEY
  • Model: deepseek/deepseek-v4.1-flash (a reasoning model: long chain-of-thought returned separately from content)
  • Corpus: small Next.js repo, 20 communities

Root cause (traced)

Instrumenting graphify.llm._call_llm shows the retries make decreasing budgets: 1216 -> 736 -> 496 -> 352 tokens, all returning an empty string. Replaying the exact saved prompts through the OpenAI SDK against the same endpoint/model:

max_tokens finish_reason content reasoning chars completion_tokens
1216 length '' (empty) ~4,300 1216
8192 stop full JSON ~11,300 3112
1216, fast non-reasoning model stop full JSON - -

So the model spends its entire completion budget on the reasoning chain and returns finish_reason=length with empty content. _parse_label_response correctly cannot salvage an empty string, but the adaptive retry (#1278) splits the batch, which only shrinks min(256 + 48 * n, 8192) - the retry moves in the wrong direction for a budget-exhaustion failure, so it can never recover.

Suggested fix

  • Treat empty content / finish_reason == "length" distinctly in _label_batch_with_retry: first retry with a larger max_tokens (e.g. x2, capped at 8192), and only split the batch if the larger budget still fails.
  • Consider disabling thinking for the labeling call via extra_body (like the moonshot default {"thinking": {"type": "disabled"}}) or passing reasoning_effort: "low".
  • Optionally expose an env/CLI override for the labeling budget.

Workaround

Using a fast/non-reasoning model labels all communities successfully at the same budget:
graphify label . --backend myendpoint --model deepseek/deepseek-v4-flash-fast

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions