NemoClaw icon indicating copy to clipboard operation
NemoClaw copied to clipboard

[Bug/DX] Local Inference Gateway silently returns null content on token exhaustion instead of standard finish_reason

Open stanford-dr-tsai-yi-lin opened this issue 6 months ago • 4 comments

Description

What happened?

When querying https://inference.local/v1/chat/completions from within the sandbox, if the max_tokens limit is reached mid-generation (especially when generating structured outputs like Markdown tables), the OpenShell L7 Gateway/Proxy returns an empty or null payload for the content field.

Instead of returning the partial generation with "finish_reason": "length", the silent null return causes standard Python parsers to throw unexpected NoneType exceptions downstream.

What did you expect to happen?

The gateway claims to be OpenAI-compatible. I expected the gateway to either:

  1. Pass through the partially generated string with the correct "finish_reason": "length".
  2. Or, if the output is deemed malformed and must be blocked, return a proper HTTP 400/500 API error (e.g., Token limit exceeded during structured generation) rather than a silent HTTP 200 OK with null content.

This severely harms Developer Experience (DX) and breaks graceful degradation in Agentic workflows.

Reproduction Steps

  1. Launch the NemoClaw sandbox (nemoclaw onboard).
  2. Run a Python script inside the sandbox targeting https://inference.local/v1/chat/completions.
  3. Force a complex generation task (e.g., "Generate a markdown table of GitHub issues").
  4. Artificially restrict max_tokens (e.g., max_tokens: 350) to force token exhaustion mid-generation.
  5. Parse the response:
# When max_tokens is exhausted mid-generation
raw_content = response.json()['choices'][0]['message']['content']
# raw_content evaluates to None, causing downstream string concatenation to crash

Environment

  • OS: Ubuntu 24.04 (Host) / Linux Landlock Sandbox
  • Model: nvidia/nemotron-3-super-120b-a12b via local gateway
  • Runtime: OpenShell Gateway Proxy

Debug Output

# Downstream Application Crash Log caused by the silent null:
Scheduler main loop exception caught: can only concatenate str (not "NoneType") to str

Logs


Checklist

  • [x] I confirmed this bug is reproducible
  • [x] I searched existing issues and this is not a duplicate

stanford-dr-tsai-yi-lin avatar May 28 '26 03:05 stanford-dr-tsai-yi-lin

✨ Thanks for submitting this detailed issue about the Local Inference Gateway silently returning null content on token exhaustion. This identifies a bug where the gateway does not handle token limits correctly, and the provided steps to reproduce help clarify the issue.

wscurran avatar May 28 '26 18:05 wscurran

@wscurran Thanks for the quick review! Glad the repro steps helped. Fixing this silent null will definitely help agentic workflows inside the sandbox handle token limits and degrade gracefully. Let me know if you need any more logs or further testing!

stanford-dr-tsai-yi-lin avatar May 29 '26 16:05 stanford-dr-tsai-yi-lin

Hi @stanford-dr-tsai-yi-lin, thanks again for the detailed report. inference.local is served by the OpenShell-managed gateway proxying to the model server, and NemoClaw only writes the route config, so the content:null on token exhaustion needs to be smoothed in the gateway passthrough or the model server rather than in NemoClaw.

I filed an upstream issue with the repro and diagnosis: NVIDIA/OpenShell#2118. As an interim guard, downstream code can treat content == null on finish_reason == "length" as an empty completion before concatenating. Cheers!

latenighthackathon avatar Jul 02 '26 03:07 latenighthackathon

Hi @stanford-dr-tsai-yi-lin—thanks again for the report. We re-reviewed this against the upstream nullable content contract and your application’s public history. Could you clarify:

  • The exact application commit and complete traceback from the failing run.
  • A redacted raw response including content, finish_reason, reasoning_content/reasoning, and usage.
  • Whether a maintained SDK or common client failed independently, or whether the failure was limited to custom application concatenation.
  • Whether the current fallback in agent_core.py fully resolves the problem and whether it still reproduces with current NemoClaw.

The public revision present before this issue was filed already routed falsy content through a fallback, and the later #4398 guard handles it explicitly, so we cannot currently reproduce the reported NoneType failure from the available code. If there is no independent affected client or current reproduction, this appears to be downstream handling of a nullable API field rather than a NemoClaw or OpenShell defect.

apurvvkumaria avatar Jul 06 '26 20:07 apurvvkumaria