Repository navigation
fix(models): refuse max_tokens the model cannot produce; default to gpt-4.1-mini - #360
Open
thestumonkey wants to merge 1 commit into
Open
thestumonkey wants to merge 1 commit into
thestumonkey wants to merge 1 commit into
Conversation
Timeline days failed with OpenAI HTTP 400 ("max_tokens is too large: 32000.
This model supports at most 16384") because the shipped 32K timeline
allowance was sent unchanged to the default gpt-4o-mini. Timeline runs only
on explicit authorization, so the failure looked like the cron not running.
- ModelDef gains max_output_tokens. Unset means unknown and is not checked.
- get_llm_operation, the Pi memory agent, the Pi timeline executor and the
operating-memory optimizer raise OutputLimitExceeded instead of sending a
request the provider will reject. The message names the setting, the model
and both numbers, and says to choose a larger-output model.
- POST /api/timeline/reconciliation/day/{date} checks first and returns 409,
so the day is not queued. The Timeline page shows the error with a
"Change model" link (mutation errors were not shown before).
- Config diagnostics report each mismatch as an error System Event.
- explain_llm_operation still works on a misconfigured operation.
- Default openai-llm moves from gpt-4o-mini (16384) to gpt-4.1-mini (32768),
so the shipped 32K timeline allowance fits. fallback-llm (gpt-5-nano)
declares 128000. The config.yml template carries the limit too, because a
user entry replaces the default entry by name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This branch has not been deployed
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.
The problem
Timeline days stopped appearing on a k8s deployment, so it looked as if the cron jobs did not run there. The scheduler was fine. The real cause was in the model settings:
POST /api/timeline/reconciliation/day/{date}).rolling_reconciliation_scanonly dispatches days that were asked for.max_tokens is too large: 32000. This model supports at most 16384.llm_operations.timeline_segmentation.max_tokensandtimeline.pi.max_tokens). The shipped default model isgpt-4o-mini, and it can produce only 16384.So the defaults did not work together, and a bad model choice failed silently.
The fix
1. Models declare their output limit.
ModelDefgainsmax_output_tokens. If it is not set, the limit is unknown and nothing is checked. This keeps local and custom models working as before.2. Refuse, do not shrink.
If an operation asks for more output than its model can produce, Chronicle raises
OutputLimitExceededbefore it sends the request. It does not cutmax_tokensdown silently, because a timeline cut down to half its allowance gives poor results that look correct. The message names the setting, the model, and both numbers, and it tells the user to choose a larger-output model:Checked in:
get_llm_operation, the Pi memory agent, the Pi timeline executor (timeline.pi.max_tokensoverride), and the operating-memory optimizer's minimum.3. Show it to the user.
config) with a resolution.explain_llm_operation(the model-routes view) still works on a misconfigured operation, so the user can see what to fix.4. Better defaults.
openai-llm:gpt-4o-mini(16384) →gpt-4.1-mini(32768). The shipped 32K timeline allowance now fits, so a fresh install works.fallback-llm(gpt-5-nano) declares128000.config/config.yml.templatecarriesmax_output_tokenstoo. A user's model entry replaces the default entry with the same name completely, so without the limit in the template, new installs would skip the check.For existing deployments
If your
config.ymldefines its ownopenai-llmentry, it still uses the old model and has no limit. So nothing is checked, and the 400 still happens. Update that entry (model andmax_output_tokens), or pointtimeline_segmentationat a model that can produce 32000 tokens. After that change, the diagnostics tell you if the settings still do not fit.Tests
backend/tests/test_model_output_limits.py(11 tests): refusal and its message, operations that fit, models with no declared limit, explain on a bad operation, findings for each setting, the Pi timeline override (refused for a small model, kept for a large one), the endpoint preflight (and that it skips the codex executor), the shipped limits indefaults.yml, and the diagnostics error with its resolution.Full backend suite run locally (macOS): 2802 passed, 262 skipped. The 31 failures and 101 errors are all environment problems on that machine, not this change: no MongoDB on :27018, no
rg, no Pi install, an Opus/ffmpeg build problem, timezone, andchronicle_setupnot installed. None of them involveOutputLimitExceeded. The WebUI type-check was not run locally becausenode_modulesis not installed.🤖 Generated with Claude Code