Repository navigation
[codex] Resolve renderer thinking retention at init - #93
Merged
eligotts merged 7 commits intoJun 25, 2026
Merged
Conversation
eligotts
marked this pull request as ready for review
June 25, 2026 03:25
ApprovabilityVerdict: Needs human review This PR refactors thinking_retention from a render-time flag to a bridge-policy-only flag, changing when bridges are attempted vs full re-renders across all thinking-capable renderers. The test changes explicitly demonstrate altered runtime behavior, and the scope (17+ files touching all renderer implementations) represents a major refactor of shared infrastructure. You can customize Macroscope's approvability policy. Learn more. |
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.
Summary
thinking_retention=Nonethe unset state so renderers derive bridge behavior from their own template knobstemplateas an internal resolved policy only; publicthinking_retentionaccepts explicittool_cycle/allbridge-policy overridesallfor no-thinking generation configs, while still allowing explicit conservativetool_cycleexplicit or impliedrender()stays faithful to the Python chat-template implementationpreserve_thinking, Harmonyauto_drop_analysis, GLM/Nemotron history toggles, and Kimi K2.5thinkingWhy
The previous PR mixed bridge behavior with runtime token inspection and treated generic
thinking_retentionlike it could change full-render history. This keeps the axes separate: unset derives from template knobs and fixed run-level no-thinking config, explicit generic values only choose bridge vs rerender policy, conflicts fail loudly at config construction, and a full rerender always runs the Python chat template.Validation
pytest tests/test_renderer_config.py -qpytest tests/test_preserve_thinking.py -qpytest tests/test_bridge.py -qpytest tests/test_renderer_config_parity.py -qpytest tests/test_preserve_thinking.py tests/test_bridge.py tests/test_renderer_config.py -qpytest tests/test_renderer_config.py tests/test_preserve_thinking.py tests/test_bridge.py -qruff check README.md renderers/base.py renderers/configs.py renderers/qwen3.py renderers/qwen35.py renderers/glm5.py renderers/glm45.py renderers/minimax_m2.py renderers/nemotron3.py renderers/kimi_k25.py renderers/gpt_oss.py renderers/deepseek_v3.py renderers/deepseek_r1.py tests/test_preserve_thinking.py tests/test_renderer_config.py tests/test_bridge.pyruff check renderers/qwen3.py renderers/qwen35.py renderers/glm5.py renderers/glm45.py renderers/nemotron3.py tests/test_preserve_thinking.pygit diff --checktool_cycle/allleave full render unchanged; default/tool_cycle decline user-boundary bridge;allbridges across it when structurally validNote
Medium Risk
Behavior of multi-turn bridging changes across many model families at user-query boundaries; mistakes would force extra full re-renders or unsafe extensions, though parity and bridge tests were updated heavily.
Overview
Redefines
thinking_retentionas bridge-only policy, not something that changes fullrender()history. Unset (None) deriveseffective_thinking_retentionat construction from each renderer’s template knobs (clear_thinking,preserve_thinking,auto_drop_analysis,enable_thinking, etc.); explicit values only choose whenbridge_to_next_turnmust fall back to a full re-render (template/tool_cycle/all).Centralizes bridge decisions in
resolve_thinking_retentionandshould_rerender_for_thinking_retention, replacing per-bridge token-marker scans andshould_preserve_past_thinking/reject_thinking_strip_in_extension. Hand-coded render paths now emit historical reasoning only via their chat-template logic; Qwen3.6 gainspreserve_thinking, gpt-oss gainsauto_drop_analysis, with stricter config conflict validation.Docs and tests align with the split: generic retention must not alter full-render token streams;
DefaultRendererrejects explicit retention; bridge tests expecttool_cycleto decline on new user queries without inspecting prior thinking tokens (Qwen still uses a narrower user-query predicate for folded tool responses).Reviewed by Cursor Bugbot for commit 7a4013f. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Resolve thinking retention policy at renderer init across all renderer types
resolve_thinking_retentionin base.py to compute aneffective_thinking_retention(one of'template','tool_cycle','all') once at construction time, replacing per-messageshould_preserve_past_thinkingcalls scattered across renderers.ThinkingRetention(user-facing:'tool_cycle'|'all') andResolvedThinkingRetention(internal, also includes'template') type aliases;Noneon config now means "defer to template" instead of the removed'template'literal.reject_thinking_strip_in_extensiontoken-marker scanning in all renderers (Qwen3,Qwen3.5,Kimi K2/K2.5,GLM4.5/5,MiniMax M2,Nemotron3, etc.) withshould_rerender_for_thinking_retention, causing extension bridges to returnNone(force full re-render) when retention semantics differ across a user-query boundary.preserve_thinkingoverride parameter from assistant-rendering helpers across affected renderers; full renders no longer force-emit historicalreasoning_contentbased onthinking_retention—bridge policy and full render are now decoupled.preserve_thinkingtoQwen36RendererConfigandauto_drop_analysistoGptOssRendererConfig, each validated againstthinking_retentionvia the extended_reject_thinking_retention_conflictutil.thinking_retentionis now a bridge-only policy; setting'tool_cycle'or'all'no longer changes full render output.DefaultRenderernow raisesValueError(wasNotImplementedError) for explicit retention values.Macroscope summarized 7a4013f.