fix: give lesson preparation and grading room for reasoning models

Source selection asks for at most 1800 output tokens and grading for 2200.
Reasoning models count hidden reasoning against max_tokens. On a real course
page set, nvidia/nemotron-3.5-super-vl (OpenRouter) stopped with
finish_reason=length in 5 of 5 runs after spending all 1800 tokens on
reasoning, so the reply had no JSON and preparation failed with "invalid
source-selection response". The #2367 retry lowers reasoning_effort to "low",
which this model does not honour: on a small probe it reasoned more, not less,
and in the app the retry failed the same way.

Raise both caps to 8192. Replaying the same request with an 8000-token cap
finished in 3 of 3 runs (2.4k-4.1k reasoning tokens), and full preparation
then completed for 4 of 4 objectives. max_tokens is a ceiling, so models that
answer briefly are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
elvisgraho
2026-11-10 21:03:44 +01:00
parent 60fb3bdfdd
commit 3bfdb0fc29
3 changed files with 4 additions and 4 deletions

View File

@@ -504,7 +504,7 @@ async def _ask(
{"role": "system", "content": instruction},
{"role": "user", "content": content},
],
max_tokens=1800,
max_tokens=8192,
allow_image_fallback=False,
)
except LessonUnavailable:

View File

@@ -157,7 +157,7 @@ async def _request(config, instruction, payload, sources=None, native_images=Non
# Do not impose a shorter assessment timeout on a reasoning provider.
return await _complete_json(
config or get_llm_config(),
max_tokens=2200,
max_tokens=8192,
messages=messages,
allow_image_fallback=False,
)

View File

@@ -75,7 +75,7 @@ def test_ask_retries_once_with_reasoning_turned_down(monkeypatch):
async def complete(**kwargs):
efforts.append(kwargs["config"].reasoning_effort)
assert kwargs["max_tokens"] == 1800
assert kwargs["max_tokens"] == 8192
# The first reply spent its budget thinking and returned no answer.
return "<think>Considering the objective" if len(efforts) == 1 else '{"queries": ["a"]}'
@@ -126,7 +126,7 @@ def test_assessment_requests_share_the_parser_and_retry(monkeypatch):
async def complete(**kwargs):
efforts.append(kwargs["config"].reasoning_effort)
assert kwargs["max_tokens"] == 2200
assert kwargs["max_tokens"] == 8192
if len(efforts) == 1:
return ""
return 'Verdicts follow.\n```json\n{"verdicts": []}\n```'