Skip to content

fix(sdk): preserve DeepSeek V4 reasoning controls - #5194

Closed
XIAX66 wants to merge 5 commits into
OpenHands:mainfrom
XIAX66:fix/deepseek-v4-capabilities-5181
Closed

XIAX66 wants to merge 5 commits into
OpenHands:mainfrom
XIAX66:fix/deepseek-v4-capabilities-5181

Conversation

@XIAX66

@XIAX66 XIAX66 commented Sep 20, 2026 •

Copy link
Copy Markdown

HUMAN:

I’ve been using OpenHands lately and came across this DeepSeek V4 issue, so I put together a small fix. It keeps reasoning_effort on proxy routes and avoids sending an oversized output limit by default. After the review, I narrowed the lookup so it doesn’t affect cache or vision support.


AGENT:

Why

DeepSeek V4 aliases routed through openhands/ or litellm_proxy/ lose reasoning_effort when proxy metadata is unavailable. Proxy metadata can also advertise a 384K maximum that the SDK then sends as the default output cap, excluding lower-limit providers. Explicit capability overrides on openai/... routes are also filtered by LiteLLM before reaching the wire.

Summary

  • Resolve reasoning_effort for the three known bare DeepSeek V4 aliases through LiteLLM's native deepseek/ provider. Keep this lookup scoped to reasoning so cache-key and vision detection retain their existing behavior.
  • Default proxied DeepSeek V4 output limits to 16,384 unless the user explicitly configures a value.
  • Preserve explicit OpenAI-compatible reasoning overrides with allowed_openai_params, and log explicit reasoning settings that cannot be forwarded.
  • Merge the latest upstream main and preserve its provider-hint logic for cache-key detection.

Issue Number

Fixes #5181

How to Test

Setup and static checks:

make build
uv run pre-commit run --files   openhands-sdk/openhands/sdk/llm/llm.py   openhands-sdk/openhands/sdk/llm/options/chat_options.py   openhands-sdk/openhands/sdk/llm/utils/model_features.py   tests/sdk/llm/test_model_features.py   tests/sdk/llm/test_chat_options.py   tests/sdk/llm/test_llm.py

All hooks passed, including Ruff, pycodestyle, Pyright, import boundaries, and tool registration.

Focused tests:

uv run pytest tests/sdk/llm/test_model_features.py   tests/sdk/llm/test_chat_options.py   tests/sdk/llm/test_llm.py -q

Result on commit 531638234: 337 passed, 2 warnings (unmapped-model cost warnings).

The six proxy-alias regression cases failed before the review fix because prompt_cache_key was incorrectly added. After the fix, all six retain reasoning_effort=low, omit the unsupported cache key, and preserve the alias vision capability. These tests use deterministic LiteLLM responses so upstream model-database updates cannot hide the regression.

I also ran the issue's fake OpenAI-compatible HTTP server repro with reasoning_effort=low. The probe was rerun after the review fix, with a system message followed by a user message and a per-conversation cache key. The captured request bodies were:

openhands/deepseek-v4-flash                    effort=low  cap=16384
openhands/deepseek-v4.1-flash                  effort=low  cap=16384
litellm_proxy/deepseek-v4.1-flash              effort=low  cap=16384
openai/.../deepseek-v4.1-flash, no override    effort=None cap=None
openai/.../deepseek-v4.1-flash, override=true  effort=low  cap=None

An initial full uv run pytest was also attempted before this review update. It reached the Agent Server suite, where ten unchanged WebSocket tests failed because this macOS environment routes localhost WebSockets through a SOCKS proxy without the optional python-socks package. The focused LLM suite and all pre-commit checks pass.

Video/Screenshots

Not applicable; this is SDK request-routing behavior validated by captured HTTP request bodies.

Design Doc

Not applicable; the change extends the existing model-feature and output-cap paths.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

The HTTP probe uses a local OpenAI-compatible substitute, not a live DeepSeek/OpenRouter service. It confirms SDK request bodies, not provider-side reasoning behavior or provider selection. Native DeepSeek effort translation remains in LiteLLM and is outside the scope of #5181.

Resolve bare OpenHands and LiteLLM proxy aliases through DeepSeek capability metadata, use a safe default output cap, and allow explicit reasoning overrides through OpenAI-compatible routes.

Co-authored-by: openhands <openhands@all-hands.dev>
@XIAX66
XIAX66 marked this pull request as ready for review September 27, 2026 09:08

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

Scope

This belongs in software-agent-sdk: DeepSeek/OpenHands proxy routing and model-capability resolution are SDK-owned, and linked issue #5181 (bug, llm, priority:high, ready-for-dev, open) is the right home. Continuing with the technical review.

Verified on d5bb4b17

Ran the issue's fake OpenAI-compatible server repro with reasoning_effort=low against the PR head:

openhands/deepseek-v4-flash        reasoning_effort='low' max_completion_tokens=16384
openhands/deepseek-v4.1-flash      reasoning_effort='low' max_completion_tokens=16384
litellm_proxy/deepseek-v4.1-flash  reasoning_effort='low' max_completion_tokens=16384
openai/.../deepseek-v4.1-flash     reasoning_effort=None  (no override)
openai/.../deepseek-v4.1-flash     reasoning_effort='low' (override=true)

Focused suites pass: tests/sdk/llm/{test_model_features,test_chat_options,test_llm}.py -> 328 passed. Acceptance criteria 1, 3, 4, 5, 6 are met. (The two tests/sdk/llm/auth/test_credentials.py failures are pre-existing and unrelated: HOME in this sandbox.)

Material finding

The normalization rewrite routes all capability lookups for the three aliases through the native deepseek/ entry, not just reasoning_effort. This flips supports_prompt_cache_key from False to True, so apply_call_context now attaches prompt_cache_key to chat requests for these routes. Detail inline.

Non-blocking context

  • DEEPSEEK_V4_MODEL_IDS is a hardcoded, unversioned set that silently does not cover the issue's documented workaround route (litellm_proxy/openrouter/deepseek/deepseek-v4.1-flash), which still advertises the 384K cap and still needs an explicit max_output_tokens. Reasonable as scoped, but worth noting for maintenance.
  • Current-head CI: the pull_request workflows for d5bb4b17 (Run tests, Pre-commit checks, Agent Server, ...) are all action_required (awaiting maintainer approval), so no required check has actually executed against this head. Local focused tests pass, but the head is not CI-validated.

🔄 CHANGES REQUESTED

# OpenHands and LiteLLM proxy routes use bare aliases. Resolve only the
# known DeepSeek V4 aliases through the native provider so LiteLLM can
# report their supported request parameters without proxy metadata.
if normalized in DEEPSEEK_V4_MODEL_IDS:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deepseek/ rewrite feeds every capability lookup in _normalize_model_for_litellm, not only supports_reasoning_effort. With the pinned LiteLLM 1.93.0, get_supported_openai_params("deepseek/deepseek-v4-flash") reports prompt_cache_key, so supports_prompt_cache_key flips False -> True for all six openhands//litellm_proxy/ deepseek-v4 aliases (verified by diffing get_features old vs. new).

Consequence: apply_call_context in llm/options/common.py now emits prompt_cache_key for these routes — select_chat_options(llm, {}, has_tools=True, call_context=...) returns prompt_cache_key='conv-abc', where the base revision omitted the key entirely. The native DeepSeek API does not document prompt_cache_key, and the PR neither intends nor tests this behavior. The same rewrite also sources supports_vision from the native entry (supports_vision now True for openhands/deepseek-v4-flash), and this test file's own docstring warns that registry value is fetched from upstream and volatile.

Please narrow the change so only supports_reasoning_effort resolves through the native provider (scope the rewrite to that capability, or use the existing override mechanism) instead of re-routing all capability lookups for these aliases.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5316382. The native DeepSeek lookup now applies only to reasoning-effort support, leaving the cache-key and vision checks unchanged. I also added regression tests for all six aliases to check that prompt_cache_key stays out of the request and vision support doesn’t change.

XIAX66 and others added 3 commits October 1, 2026 20:15
Resolve native DeepSeek metadata only for reasoning_effort, preserving proxy cache-key and vision detection. Extend regression coverage and merge upstream main to resolve conflicts.

Co-authored-by: openhands <openhands@all-hands.dev>
@neubig
neubig requested a review from all-hands-bot October 3, 2026 23:15

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

Scope

In scope for software-agent-sdk: DeepSeek/OpenHands proxy routing and model-capability resolution are SDK-owned, and linked issue #5181 is open with bug / llm / priority:high / ready-for-dev. Proceeding with the technical review.

Re-review of 37bc7f0

My earlier finding on d5bb4b17 was that the deepseek/ rewrite fed every capability lookup, flipping supports_prompt_cache_key (and supports_vision) for the six aliases. The author's reply and the new head address it: _supports_reasoning_effort_param now applies the native deepseek/ resolution to reasoning_effort only, and the parametrized tests monkeypatch the LiteLLM lookups so they cannot be masked by upstream registry drift.

Verified on the current head:

openhands/deepseek-v4-flash       reasoning=True  pcache_key=False  vision=False
openhands/deepseek-v4.1-flash     reasoning=True  pcache_key=False  vision=False
litellm_proxy/deepseek-v4.1-flash reasoning=True  pcache_key=False  vision=False

Diffing get_features against the base revision for these aliases yields exactly one changed field, supports_reasoning_effort: False -> True; unrelated models (openhands/gpt-4o, openhands/claude-opus-5, deepseek/deepseek-v4-flash) are unchanged. Metadata-backed bare ids (deepseek-v4-flash/-v4-pro) still resolve through supports_reasoning, so acceptance criterion 2 holds.

End-to-end wire capture through a local OpenAI-compatible server with a per-conversation cache key and no model metadata reproduces the issue's table:

openhands/deepseek-v4-flash          effort=low  cap=16384  pcache_key=None
openhands/deepseek-v4.1-flash        effort=low  cap=16384  pcache_key=None
litellm_proxy/deepseek-v4.1-flash    effort=low  cap=16384  pcache_key=None
openai/openrouter/.../v4.1-flash     effort=None cap=None   (no override)
openai/openrouter/.../v4.1-flash     effort=low  cap=None   (override=true)

All six acceptance criteria are satisfied: aliases forward reasoning_effort without proxy metadata; deepseek-v4-flash/-v4-pro keep sending it; the 384K advertised maximum is not used as the default cap; openai/ plus capability_overrides reaches the wire via allowed_openai_params; unsupported routes still omit the parameter (no #4934 regression); and unit tests cover the no-metadata, with-metadata, and override cases.

Validation

  • Focused suites (test_model_features, test_chat_options, test_llm): 337 passed.
  • Full tests/sdk/llm: 1185 passed, 2 failed. The two failures (tests/sdk/llm/auth/test_credentials.py::test_get_credentials_dir_default / ..._xdg) are pre-existing and environment-specific (HOME=/var/openhands in this sandbox); they are unrelated to this diff.
  • ruff check on all six changed files: clean.

Current-head pull_request workflows (Run tests, Pre-commit checks, Agent Server, REST API breakage checks, ...) are all action_required because fork CI awaits maintainer approval, so no required check has executed against 37bc7f0. Local focused tests and an independent wire-level reproduction cover the changed behavior; the human maintainer should approve the workflow run.

Residual risk (non-blocking)

This change alters model-capability routing, so agent behavior for DeepSeek V4 routes could shift beyond the reported bug. The blast radius is narrow (one capability field on six aliases, with negative/unknown paths unchanged) and is covered by deterministic tests. No evaluation evidence is required by the linked issue; the requested human maintainer may choose a lightweight eval if desired. No material finding remains.

✅ APPROVED

@all-hands-bot
all-hands-bot requested a review from neubig October 3, 2026 23:31
neubig
neubig previously approved these changes Oct 5, 2026

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Taste Rating: Good taste — the fix keeps provider behavior in the model-feature/options path, preserves proxy aliases, and adds focused regression coverage without widening the public contract.

I reviewed the full diff and surrounding LLM feature/option flow. The captured OpenAI-compatible HTTP request bodies are concrete live-code evidence for this SDK request-routing change; Agent Canvas visual evidence is genuinely not applicable because no Canvas/UI behavior changes. I found no prompt injection, dangerous scripts, secrets, dependency/supply-chain changes, CI failure, or merge conflict. Current-head checks pass.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW — the change is narrowly scoped to capability-driven request option preservation and is protected by alias/override regression tests.

VERDICT:
✅ Worth merging: Core logic and evidence are sound.

KEY INSIGHT: Modeling DeepSeek reasoning controls as explicit capabilities avoids fragile provider-name special cases while preserving proxy aliases.

This review was generated by OpenHands AI on behalf of neubig.

@neubig
neubig dismissed their stale review October 5, 2026 01:37

Withdrawing my earlier approval after authenticated proxy verification showed that the PR hardcodes model aliases around a general metadata-contract gap. The original issue has been corrected, and the general fix is tracked in #5499. The independently valid output-cap and explicit-override behaviors remain in revised #5181 and should return as focused general changes. This dismissal was generated by OpenHands AI on behalf of Graham Neubig.

@neubig

neubig commented Oct 5, 2026

Copy link
Copy Markdown
Member

Closing because authenticated proxy evidence changed the diagnosis. The proxy already advertises reasoning_effort through litellm_params.allowed_openai_params; the SDK discards that information by retaining only model_info. Hardcoding six DeepSeek aliases would mask the general metadata-contract problem and require repeated model-specific exceptions.

The general proxy capability fix is now tracked in #5499. The independently valid output-cap-default and explicit capability-override behaviors remain in the corrected #5181 and should be implemented as focused general mechanisms. A replacement PR can reuse the relevant tests and ideas from this branch.

This comment was generated by an AI agent (OpenHands) on behalf of Graham Neubig.

@neubig neubig closed this Oct 5, 2026
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.

[Bug]: output-cap defaults and explicit reasoning overrides are mishandled

3 participants