Skip to content

fix(models): refuse max_tokens the model cannot produce; default to gpt-4.1-mini - #360

Open
thestumonkey wants to merge 1 commit into
SimpleOpenSoftware:devfrom
Ushadow-io:fix/model-output-limits
Open

thestumonkey wants to merge 1 commit into
SimpleOpenSoftware:devfrom
Ushadow-io:fix/model-output-limits

Conversation

@thestumonkey

Copy link
Copy Markdown
Contributor

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:

  • A timeline day runs only after someone asks for it (POST /api/timeline/reconciliation/day/{date}). rolling_reconciliation_scan only dispatches days that were asked for.
  • The last day that was asked for failed. OpenAI returned HTTP 400: max_tokens is too large: 32000. This model supports at most 16384.
  • The shipped config asks for 32000 output tokens (llm_operations.timeline_segmentation.max_tokens and timeline.pi.max_tokens). The shipped default model is gpt-4o-mini, and it can produce only 16384.
  • Nothing checked this before the request was sent. The failure appeared only in the job's logs. The Timeline page did not show errors from the button that starts a day, so nobody saw it.

So the defaults did not work together, and a bad model choice failed silently.

The fix

1. Models declare their output limit.
ModelDef gains max_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 OutputLimitExceeded before it sends the request. It does not cut max_tokens down 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:

timeline.pi.max_tokens needs 32000 output tokens, but model 'openai-llm' accepts at most 16384. Choose a model that supports at least 32000 output tokens for this operation (Settings > AI Model Settings), or lower timeline.pi.max_tokens.

Checked in: get_llm_operation, the Pi memory agent, the Pi timeline executor (timeline.pi.max_tokens override), and the operating-memory optimizer's minimum.

3. Show it to the user.

  • The reconcile-day endpoint checks first and returns 409 with that message. The day is not queued.
  • The Timeline page shows a red "Could not start analysis" banner with the server's reason. For a 409 it also shows a Change model link to Settings. Before this change, errors from this button were not shown anywhere.
  • Config diagnostics report each mismatch as an error. This makes it appear in System Events (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) declares 128000.
  • config/config.yml.template carries max_output_tokens too. 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.yml defines its own openai-llm entry, it still uses the old model and has no limit. So nothing is checked, and the 400 still happens. Update that entry (model and max_output_tokens), or point timeline_segmentation at 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 in defaults.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, and chronicle_setup not installed. None of them involve OutputLimitExceeded. The WebUI type-check was not run locally because node_modules is not installed.

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 09d2d404-af23-4bde-a8b9-14a360397d05

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant