Repository navigation
Studio: stop cutting Claude answers at 1,024 tokens without a limit - #16953
Conversation
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3c30ba047
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| response = await _client().get( | ||
| f"{self.base_url}/models/{model}", | ||
| headers = self._auth_headers(), | ||
| timeout = self._timeout, |
There was a problem hiding this comment.
Give optional model discovery a short independent timeout
If an Anthropic-compatible endpoint serves /messages but its optional /models/{id} route stalls, this awaited GET can delay a no-limit completion by the default 120-second client timeout before generation even starts. HTTP failures return without populating the cache, so subsequent requests and tool continuations repeat that wait. Use a short, independently bounded metadata timeout so falling back to 1,024 tokens does not impose a multi-minute delay on an otherwise working connection.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: gateways without the route answer 404 quickly and we fall back to 1024, a stalled metadata route is a broken endpoint, not a correctness bug here.
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8cb624f156
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "model": model, | ||
| "messages": filtered, | ||
| "max_tokens": max_tokens or 1024, # required by Anthropic | ||
| "max_tokens": max_tokens or await self._anthropic_output_cap(model) or 1024, |
There was a problem hiding this comment.
Bound the default output budget by the remaining context
For older Claude models or Anthropic-compatible gateways that validate input_tokens + max_tokens against the context window, a no-limit request with a 180,000-token prompt in a 200,000-token window now receives a 32,000-token output budget when the reported cap is at least that large. This exceeds the window, although the previous 1,024-token default fit. The fixed ceiling does not account for prompt length, and requests without compaction—the API default—are forwarded without a budget adjustment or overflow retry. Bound the resolved default by the remaining context, or retry with a smaller budget when the upstream rejects the combined size.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: Claude 4.5 and newer accept input plus max_tokens over the window and stop with model_context_window_exceeded, so this only affects older models with prompts over about 168k tokens.
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ain (#17040) ## Summary Two tests have been red on main since this morning's merges. Every PR based on main now inherits them: #17010, which changes only the Windows bash tool, fails both. Both reproduce on main locally: ``` (Python 3.13, a-f) studio/backend/tests/test_custom_provider_api_type.py::test_base_url_query_survives_native_provider_calls At index 0 diff: ('/v1/models/claude-sonnet-4-5', 'tenant=a') != ('/v1/messages', 'tenant=a') Repo tests (CPU, studio) tests/studio/test_model_picker_contracts.py::test_batch_sizes_reach_an_api_load_through_the_server_mirror assert 'strip_batch = "n_batch" in kwargs,' in '...openai_auto_switch_settings.py...' ``` In both cases the product change is correct and the test is out of date. - **#16951 and #16953.** #16951 (keep the base URL query string on provider calls) added a test that lists every request the three native providers make. #16953 merged four minutes later. It looks up the model's output cap with `GET /v1/models/<model>` before a Messages API stream that sets no `max_tokens`, so that provider now makes one more request. That request goes through `_append_provider_path`, so it keeps `?tenant=a`, which is the invariant #16951 cares about. The test simply predates it. Each PR was green on its own. - **#16927.** It moved the llama.cpp flag stripping into `strip_args_shadowed_by(args, fields)`, so the line now reads `strip_batch = "n_batch" in fields,` and is called with the same kwargs. What gets stripped is unchanged. The contract test grepped for the old source line. ## Change Tests only: - `test_base_url_query_survives_native_provider_calls` expects the output-cap lookup first, with its query string kept. It also empties `_anthropic_output_caps` first, so the lookup happens whatever ran earlier in the worker. That cache is module-global, and with an entry already cached the request list would change with test order. - `test_batch_sizes_reach_an_api_load_through_the_server_mirror` stops grepping that line. It calls the real `model_override_load_kwargs`, imported the same way as the lookup-ladder helper already in that file: - a stored `-b` is dropped when the override has `n_batch`; - a stored `-ub` is dropped when the override has `n_ubatch`; - both stay when neither field is set. ## Testing | | main | this branch | |---|---|---| | `test_custom_provider_api_type.py` + `test_anthropic_default_max_tokens.py` | 1 failed | 29 passed, in either file order | | `tests/studio/test_model_picker_contracts.py` | 1 failed | 203 passed | | the batch test with `strip_batch = False` planted in `strip_args_shadowed_by` | | fails |
When an Anthropic connection model is used through the API without a max_tokens value, Studio asked Anthropic for at most 1,024 tokens. Long answers stopped mid-sentence with finish_reason "length". This hits /v1/chat/completions and /v1/responses with an external connection model (for example coding agents set up by unsloth start, some of which never send a limit) and scheduled tasks that run on a Claude connection. The chat page was not affected because it always sends a limit.
Studio now asks the connection for the model's own output limit (Anthropic's model listing reports it), remembers it, and sends that instead. Other providers already leave the limit to the model when none is given, so Claude now behaves the same way. A limit sent by the client is still used as is, and a connection whose endpoint does not report a limit keeps the old 1,024 default.