Repository navigation
fix(backends): deep-merge extra_body.chat_template_kwargs in merge_model_options - #1617
Merged
Merged
Conversation
…del_options model_options-level extra_body defaults (the pattern documented for setting a persistent thinking-mode toggle) were silently clobbered by any unrelated per-call extra_body, because merge_model_options did a flat dict.update on the whole extra_body value. Special-case extra_body to deep-merge its chat_template_kwargs sub-dict, mirroring the deep-merge OpenAIBackend._merge_user_extra_body already does; every other key still flat-overwrites as before. Adds regression tests at the merge-layer (test_model_options.py, test_options.py) and through an actual intrinsic/adapter call (test_openai_intrinsics_unit.py), plus a defensive fallback for a malformed non-dict chat_template_kwargs. Updates the openai.md docs section that previously documented this as a known limitation. Fixes generative-computing#1539 Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
Comments and test docstrings should document current behavior, not point back at the issue that motivated it. Also tightens the _merge_extra_body/merge_model_options docstrings. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
jakelorocco
reviewed
Sep 3, 2026
…THINKING extra_body passed via the generic model_options constructor dict (not the dedicated default_extra_body param) was merged with per-call extra_body inside _simplify_and_merge, then re-emerged downstream as the highest-priority layer in _merge_user_extra_body (openai.py) and the inline equivalent in litellm.py — silently outranking a per-call ModelOption.THINKING resolved separately via the sentinel key. Fold construction-time extra_body into the existing lowest-priority _default_extra_body tier at __init__ instead, and exclude extra_body from backend_defaults in _simplify_and_merge so it can no longer re-enter the per-call precedence chain. Adds the same _default_extra_body tier to litellm.py, which had none. Adds regression tests in both backends that fail without the fix. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
jakelorocco
approved these changes
Sep 4, 2026
Merged
via the queue into
generative-computing:main
with commit Sep 4, 2026
d29dc3e
11 checks passed
planetf1
added a commit
that referenced
this pull request
Sep 10, 2026
- Qualify the OpenAIBackend/LiteLLM `False` cell: real OpenAI reasoning models and non-Ollama LiteLLM targets never receive `reasoning_effort= "none"` (openai.py's server-type guard, litellm.py's ollama-prefix guard), so `False` does not actually disable thinking there. - Add an inline callout marking the LocalHFBackend string-forwarding and result.thinking claims as contingent on #1639/#1616 merging, instead of only noting it in the PR description/comment. - Correct "same mechanism as the OpenAI backend" — HF forwards through a gated chat-template variable, OpenAI sends an ungated top-level param. - Note the runtime-forwarding dependency for the cross-backend Granite claim, add a `> Full example:` link, fix the unresolvable bare "#1617" reference, add a non-determinism note to the new code block, drop the unnecessary `qualitative` marker, and fix US-English spelling in new content per CONTRIBUTING_DOCS.md. - Add cheap assertions to docs/examples/thinking_mode.py pinning the documented per-arm behaviour; reran live against granite4.2:3b, all pass. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
planetf1
added a commit
that referenced
this pull request
Sep 15, 2026
- Qualify the OpenAIBackend/LiteLLM `False` cell: real OpenAI reasoning models and non-Ollama LiteLLM targets never receive `reasoning_effort= "none"` (openai.py's server-type guard, litellm.py's ollama-prefix guard), so `False` does not actually disable thinking there. - Add an inline callout marking the LocalHFBackend string-forwarding and result.thinking claims as contingent on #1639/#1616 merging, instead of only noting it in the PR description/comment. - Correct "same mechanism as the OpenAI backend" — HF forwards through a gated chat-template variable, OpenAI sends an ungated top-level param. - Note the runtime-forwarding dependency for the cross-backend Granite claim, add a `> Full example:` link, fix the unresolvable bare "#1617" reference, add a non-determinism note to the new code block, drop the unnecessary `qualitative` marker, and fix US-English spelling in new content per CONTRIBUTING_DOCS.md. - Add cheap assertions to docs/examples/thinking_mode.py pinning the documented per-arm behaviour; reran live against granite4.2:3b, all pass. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]>
akihikokuroda
pushed a commit
to akihikokuroda/mellea
that referenced
this pull request
Sep 16, 2026
…-computing#1645) * docs: document ModelOption.THINKING behaviour for Granite and add example Adds a per-backend reasoning/thinking-mode reference table (native Ollama, OpenAI/LiteLLM, HF) to configure-model-options.md, including Granite 4.2's "low"-only effort distinction and its default-on behaviour, and cross-links it from openai.md's existing Qwen3/vLLM extra_body section as the preferred portable entry point. Adds docs/examples/thinking_mode.py demonstrating THINKING=True/False/"low" against a local Ollama Granite model, verified live against granite4.2:3b. Fixes generative-computing#1638 Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: describe THINKING doc as post-generative-computing#1639/generative-computing#1616 target state Documents ModelOption.THINKING string levels and result.thinking as supported on LocalHFBackend too, matching the state after generative-computing#1639 (HF string forwarding fix) and generative-computing#1616 (HF <think> tag parsing) merge. Both are still open — this docs PR should merge after them, or the LocalHFBackend row will describe behaviour that isn't live yet. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: address code-review findings on THINKING docs - Qualify the OpenAIBackend/LiteLLM `False` cell: real OpenAI reasoning models and non-Ollama LiteLLM targets never receive `reasoning_effort= "none"` (openai.py's server-type guard, litellm.py's ollama-prefix guard), so `False` does not actually disable thinking there. - Add an inline callout marking the LocalHFBackend string-forwarding and result.thinking claims as contingent on generative-computing#1639/generative-computing#1616 merging, instead of only noting it in the PR description/comment. - Correct "same mechanism as the OpenAI backend" — HF forwards through a gated chat-template variable, OpenAI sends an ungated top-level param. - Note the runtime-forwarding dependency for the cross-backend Granite claim, add a `> Full example:` link, fix the unresolvable bare "generative-computing#1617" reference, add a non-determinism note to the new code block, drop the unnecessary `qualitative` marker, and fix US-English spelling in new content per CONTRIBUTING_DOCS.md. - Add cheap assertions to docs/examples/thinking_mode.py pinning the documented per-arm behaviour; reran live against granite4.2:3b, all pass. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: fix stale THINKING dependency note now that generative-computing#1639 merged generative-computing#1639 (HF string-forwarding) merged 2026-09-10; only generative-computing#1616 (result.thinking parsing) remains open. Also note that generative-computing#1616's <think>-tag split is skipped for streaming (m serve) calls, per its own PR description. Assisted-by: Claude Code Signed-off-by: Nigel Jones <[email protected]> * docs: drop merged-PR references from THINKING doc generative-computing#1616 and generative-computing#1639 have both merged, so LocalHFBackend's result.thinking split is now current-main behaviour, not a future dependency. Assisted-by: Claude Code Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Nigel Jones <[email protected]> --------- Signed-off-by: Nigel Jones <[email protected]> Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
Pull Request
Issue
Fixes #1539
Description
Impact
A backend-level
extra_bodydefault (e.g. a thinking-mode toggle set at construction time) gets silently dropped, with no error or warning, the moment a per-callextra_bodyis also present — even one that's about something else entirely:This isn't a rare edge case: it fires on every intrinsic/adapter call, because
OpenAIBackend._generate_from_intrinsicalways builds its ownextra_body(to writechat_template_kwargs["adapter_name"]) — so a session that sets a thinking default and also uses any adapter loses that default the first time the adapter is called.Root cause
merge_model_optionsmerges option dicts with a flat, top-leveldict.update. That's correct for scalar options, but wrong forextra_body, whose value is itself a dict that different call sites write into independently.Fix
merge_model_optionsnow special-casesextra_body: when both sides have a dict there, theirchat_template_kwargssub-dicts deep-merge instead of one replacing the other (newModelOption._merge_extra_body, mirroring the deep-mergeOpenAIBackend._merge_user_extra_bodyalready does one layer down). Every other option key — and every other key insideextra_body— still flat-overwrites exactly as before; only the one broken case changes.Also updates
docs/docs/integrations/openai.md, which documented this exact clobbering as a known limitation — that caveat is now gone.Testing
New tests:
test_model_options.py,test_options.py— unit coverage on the merge functions: unrelated-key preservation,chat_template_kwargsdeep-merge, conflict resolution, non-mutation, non-dict fallback.test_openai_intrinsics_unit.py::test_construction_time_extra_body_default_survives_intrinsic_call— the impact scenario end to end through a real intrinsic call: a construction-time thinking default, an unrelated per-callextra_body, and the adapter's ownadapter_nameall survive together in the final request. Confirmed this test fails on pre-fix code (KeyError: 'enable_thinking') and passes post-fix.Full run:
uv run pytest test/ -m "not qualitative"→ 4286 passed, 20 skipped, 4 xpassed, 1 unrelated pre-existing flake (test_tracing_backend.py::test_stream_e2e, a live-Ollama timing assertion — passes on rerun).ruff format/ruff check/mypyclean;markdownlint-cli2clean on the docs change.Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.