fix(reflect): enforce max_tokens after forced synthesis - #4159
Closed
koriyoshi2041 wants to merge 1 commit into
Closed
fix(reflect): enforce max_tokens after forced synthesis#4159koriyoshi2041 wants to merge 1 commit into
koriyoshi2041 wants to merge 1 commit into
Conversation
Contributor
Author
|
Closing as superseded by #4180, which covers the same forced-synthesis length boundary and landed the stronger shared rewrite path. Thanks for picking this up. |
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.
Problem
max_tokensis enforced with a post-hoc rewrite when reflect finishes through thedonetool, but forced final synthesis returns its answer directly. Long or context-exhausted runs can therefore exceed the caller's visible-length target.Closes #4156.
Fix
doneand forced-synthesis completions.Test
uv run --project hindsight-api-slim pytest -q hindsight-api-slim/tests/test_reflect_agent.py -k 'not TestDirectiveLeakageOnEmptyBank and not TestContextOverflowIntegration and not TestMentalModelShortCircuitRealLLM'(55 passed)uv run --project hindsight-api-slim ruff check hindsight-api-slim/hindsight_api/engine/reflect/agent.py hindsight-api-slim/tests/test_reflect_agent.pyuv run --project hindsight-api-slim ruff format --check hindsight-api-slim/hindsight_api/engine/reflect/agent.py hindsight-api-slim/tests/test_reflect_agent.pygit diff --checkThe four excluded tests require an embedded PostgreSQL extra or live LLM credentials; the first full-file run reached 55 passing unit tests before those environment-only setup errors.
Risk
Forced synthesis may make one additional LLM call when its answer exceeds
max_tokens. Calls withoutmax_tokensand answers already within budget are unchanged, and the rewrite remains governed byreflect_max_completion_tokensrather than using the visible target as a hard transport cap.