From 3bfdb0fc29b640e53320a6ea4e35394df72e5909 Mon Sep 17 00:00:00 2001 From: elvisgraho Date: Tue, 10 Nov 2026 21:03:44 +0100 Subject: [PATCH] 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 --- deeptutor/learning/lesson_evidence.py | 2 +- deeptutor/learning/semantic_assessment.py | 2 +- deeptutor/learning/tests/test_lesson_json_response.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deeptutor/learning/lesson_evidence.py b/deeptutor/learning/lesson_evidence.py index 57b6f04af..afd59c237 100644 --- a/deeptutor/learning/lesson_evidence.py +++ b/deeptutor/learning/lesson_evidence.py @@ -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: diff --git a/deeptutor/learning/semantic_assessment.py b/deeptutor/learning/semantic_assessment.py index ec9d313f6..52cdb1dde 100644 --- a/deeptutor/learning/semantic_assessment.py +++ b/deeptutor/learning/semantic_assessment.py @@ -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, ) diff --git a/deeptutor/learning/tests/test_lesson_json_response.py b/deeptutor/learning/tests/test_lesson_json_response.py index 5502360ed..71c387bd2 100644 --- a/deeptutor/learning/tests/test_lesson_json_response.py +++ b/deeptutor/learning/tests/test_lesson_json_response.py @@ -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 "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```'