Extract and preserve provider-specific headers (llm_provider-*) when
handling error responses from LLM providers. This ensures that useful
debugging information from providers is available even when requests
fail with BadRequestError or similar exceptions.
Gemini API rejects JSON schemas with $defs/$ref references anywhere in
the conversation, including in function_response content. This causes
errors when tools return JSON containing schemas (e.g., toolbelt_inspect_tool
returning tool definitions).
The fix:
1. Apply unpack_defs() to all JSON tool responses before sending to Gemini
2. Recursively remove $defs sections after inlining references
3. Replace any remaining $ref (circular refs, external URLs) with placeholders
Edge cases handled:
- Circular $ref (self-referential types like TreeNode.left -> TreeNode)
- External $ref (URL-based like https://...)
- Deeply nested $ref in anyOf/oneOf/allOf
This ensures function_response content is clean before being sent to the
Gemini API.
Related issues:
- https://github.com/google-gemini/gemini-cli/issues/13326
- FastMCP #1372, #1426
OpenAI's 400k context window is split between input and output:
- GPT-5/5.1/5.2 models: 272k input + 128k output = 400k context
- GPT-5-pro models: 128k input + 272k output = 400k context
Reference: https://openai.com/index/introducing-gpt-5-for-developers/
"In the API, all GPT-5 models can accept a maximum of 272,000 input
tokens and emit a maximum of 128,000 reasoning & output tokens"
Fixes incorrect 400k max_input_tokens values across 32 models.
- Add cerebras/zai-glm-4.7 with same specs as 4.6 (128K context, $2.25/M input, $2.75/M output)
- Mark cerebras/zai-glm-4.6 with deprecation_date: 2026-01-20
- Both models support function calling, reasoning, and tool choice
* Optimize _get_model_cost_key to avoid expensive scans
- Remove expensive O(n) scan fallback that was causing 42.87% CPU overhead
- Only scan when size mismatch detected (O(1) check)
- Add warning in docstring: Only O(1) lookup operations are acceptable
- Clean up comments to be more concise
- Keep stale entry rebuild for pop() case (only triggers when stale entry found)
This fixes the performance issue where the scan was being triggered on every
failed lookup, causing severe CPU overhead during router operations.
* Add code quality check to enforce O(1) operations in _get_model_cost_key
- Add check_get_model_cost_key_performance.py to statically analyze _get_model_cost_key
- Detects O(n) operations (loops, comprehensions, problematic function calls)
- Recursively checks called functions to find nested O(n) operations
- Allows conditional O(n) rebuilds in helper functions (_rebuild_model_cost_lowercase_map, _handle_stale_map_entry_rebuild, _handle_new_key_with_scan)
* Integrate _get_model_cost_key performance check into CI pipeline
- Add check_get_model_cost_key_performance.py to check_code_and_doc_quality job
- Ensures O(1) requirement is enforced in CI to prevent performance regressions
* Remove unused performance test and clean up utils.py
- Remove test_get_model_info_performance.py (no longer needed)
- Remove extra blank line in utils.py
* Document allowed helper functions and exception process in _get_model_cost_key
- Add documentation listing allowed helper functions with O(n) operations
- Explain why these are acceptable (conditionally called)
- Add instructions for adding new exceptions to check_get_model_cost_key_performance.py
* Fix docstring detection and type checker error in performance check
- Add proper docstring tracking to skip docstring content (fixes false positive for 'map' in docstring)
- Add None check for docstring_quote to fix type checker error
- Restore _handle_new_key_with_scan to allowed_helpers list
* Remove check_get_model_cost_key_performance from CI pipeline
- Temporarily remove the performance check from CI to avoid blocking builds
* Restore performance check and remove memory leak tests from CI
- Add back check_get_model_cost_key_performance.py to CI pipeline
- Remove memory_leak_tests job that was causing port conflicts
* Remove extra blank line in CI config