Skip to content

fix(server): forward request body params (ctx_size etc.) during auto-load#2673

Closed
bong-water-water-bong wants to merge 9 commits into
lemonade-sdk:mainfrom
bong-water-water-bong:fix/2662-anthropic-system-role-thinking
Closed

fix(server): forward request body params (ctx_size etc.) during auto-load#2673
bong-water-water-bong wants to merge 9 commits into
lemonade-sdk:mainfrom
bong-water-water-bong:fix/2662-anthropic-system-role-thinking

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Contributor

Fixes #2663

Problem
When the server auto-loads a model via /v1/chat/completions (or any API endpoint), auto_load_model_if_needed() was passing json::object() to RecipeOptions, ignoring all per-request parameters from the request body — including ctx_size.

This caused the model to load with recipe_options.json defaults (e.g. ctx_size=4096), even when the client explicitly requested ctx_size=128000. Any request with a prompt larger than the default context size would fail with:

request (X tokens) exceeds the available context size

Fix

  • Changed auto_load_model_if_needed() to accept an optional request_options parameter (defaults to empty JSON for backward compatibility).
  • Updated all call sites that have access to request_json to pass it through as request options.
  • The RecipeOptions constructor already safely extracts only recipe-relevant keys from the options JSON — matching the pattern already used by the /v1/load endpoint.
  • Also applied the same fix to OllamaApi::auto_load_model() for consistency.

Testing
Build succeeds cleanly. The change is purely additive (default parameter) — no existing call site changes behavior unless explicitly updated.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

bong-water-water-bong and others added 8 commits July 11, 2026 22:57
Auto-syncs every 5AM UTC via fast-forward merge. Manual trigger
available via workflow_dispatch.
…on (lemonade-sdk#2579)

Adds get_hf_endpoint() helper that reads the HF_ENDPOINT environment
variable at runtime and falls back to https://huggingface.co when unset.
Trailing slashes are automatically stripped.

Replaces all 11 hardcoded 'https://huggingface.co' URL constructions
across 6 source files with calls to get_hf_endpoint():

  - model_manager.cpp (5 sites): API model lookups, tree listing,
    file URL construction
  - hf_variants.cpp (2 sites): variant enumeration, manifest fetching
  - vllm_server.cpp (1 site): config.json fetch for quant method detection
  - whispercpp_server.cpp (1 site): whisper model download
  - hf_pull.cpp (1 site + prefix stripping): CLI URL prefix normalization
    also recognizes the configured mirror endpoint

Usage:
  HF_ENDPOINT=https://hf-mirror.com lemond
  docker run -e HF_ENDPOINT=https://hf-mirror.com ghcr.io/lemonade-sdk/lemonade-server:latest

Fully backward compatible when HF_ENDPOINT is unset.
…mits

The daily sync used git merge --ff-only which fails when the fork
has local commits (e.g. HF_ENDPOINT, MLX backend). Changed to a
regular merge with a descriptive message so the daily sync creates
a merge commit that keeps both upstream and fork history intact.
Avoids unnecessary merge commits when the fork has no local changes.
Only creates a merge commit when local commits (like PR branches on
main) prevent a clean fast-forward.
…king

Two bugs in the Anthropic /v1/messages endpoint that break Claude Code:

1. System role messages inside the messages array were silently dropped.
   Claude Code puts sub-agent definitions as role:system messages.
   When skipped, the model received a malformed prompt and returned
   empty responses.

   Fix: Collect system messages from both the top-level system field
   AND inline role:system messages in a first pass, then emit them as
   a single combined system message.

2. thinking.type: 'adaptive' was treated as unsupported. This is the
   standard Anthropic mode that lets the model decide when to use
   thinking. Treated the same as 'enabled'.

Fixes lemonade-sdk#2662
The scheduled Publish Containers workflow pushes build environment
container images to ghcr.io/lemonade-sdk/lemonade/build-environment.
When running from a fork, the auto-generated GITHUB_TOKEN lacks
write permission to the upstream org's package namespace, causing:

  denied: permission_denied: The requested installation does not exist.

Fix: gate the workflow with 'if: github.repository ==
"lemonade-sdk/lemonade"' so it only executes in the upstream repo.

Issue #4
The auto-label workflow uses ANTHROPIC_API_KEY for LLM-based
classification, which is only available in the upstream repo.
Forks trigger the workflow on PR open/edit but fail immediately
because the secret isn't set.

Gate with if: github.repository == 'lemonade-sdk/lemonade'
to match the build-container.yml fix.
…load

When the server auto-loads a model via /v1/chat/completions (or any
API endpoint), it was passing an empty json::object() to RecipeOptions,
ignoring all per-request parameters like ctx_size from the request body.

This caused models to always load with their recipe_options.json defaults
(e.g. ctx_size=4096), even when the client explicitly requested a larger
context like ctx_size=128000. Requests exceeding the default context
would fail with 'request (X tokens) exceeds the available context size'.

The /v1/load endpoint already correctly passes the request body to
RecipeOptions -- this fix brings auto-load in line with that behavior.

Fixes: lemonade-sdk#2663
@bong-water-water-bong bong-water-water-bong force-pushed the fix/2662-anthropic-system-role-thinking branch from 0338d8d to 78ec27c Compare July 12, 2026 01:58
@github-actions github-actions Bot added bug Something isn't working area::api HTTP REST API surface and route handlers labels Jul 12, 2026
@fl0rianr

Copy link
Copy Markdown
Collaborator

Thank you for your effort and the time you invested in this pull request.

However, I am closing this PR in favor of #2664 as we need to take a different approach for this issue.

Here is a breakdown of why this specific patch is not the preferred solution:

  • Architecture: The complete request is still being passed down to RecipeOptions.
  • Scope: The PR contains numerous unrelated changes (including Workflow, Hugging Face, and Anthropic updates)
  • Size: With 15 files changed, the patch is too large and broad for this specific fix.
  • Documentation: The PR description incorrectly states that passing the full request is secure.

Thank you again for your time.

@fl0rianr fl0rianr closed this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area::api HTTP REST API surface and route handlers bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto_load_model ignores ctx_size in chat request body

2 participants