Skip to content

[codex] Resolve renderer thinking retention at init - #93

Merged
eligotts merged 7 commits into
refactor/thinking-retentionfrom
codex/qwen-user-query-boundary
Jun 25, 2026
Merged

eligotts merged 7 commits into
refactor/thinking-retentionfrom
codex/qwen-user-query-boundary

Conversation

@eligotts

@eligotts eligotts commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make thinking_retention=None the unset state so renderers derive bridge behavior from their own template knobs
  • keep template as an internal resolved policy only; public thinking_retention accepts explicit tool_cycle / all bridge-policy overrides
  • resolve effective retention at renderer initialization and use that simple policy at bridge time
  • derive all for no-thinking generation configs, while still allowing explicit conservative tool_cycle
  • keep template/generic contradiction validation in typed configs, while the resolver only chooses explicit or implied
  • remove token-marker lookback and per-renderer retention support lists from bridge decisions
  • remove generic render-time thinking preservation; full render() stays faithful to the Python chat-template implementation
  • expose/map real template knobs for Qwen3.6 preserve_thinking, Harmony auto_drop_analysis, GLM/Nemotron history toggles, and Kimi K2.5 thinking

Why

The previous PR mixed bridge behavior with runtime token inspection and treated generic thinking_retention like 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 -q
  • pytest tests/test_preserve_thinking.py -q
  • pytest tests/test_bridge.py -q
  • pytest tests/test_renderer_config_parity.py -q
  • pytest tests/test_preserve_thinking.py tests/test_bridge.py tests/test_renderer_config.py -q
  • pytest tests/test_renderer_config.py tests/test_preserve_thinking.py tests/test_bridge.py -q
  • ruff 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.py
  • ruff check renderers/qwen3.py renderers/qwen35.py renderers/glm5.py renderers/glm45.py renderers/nemotron3.py tests/test_preserve_thinking.py
  • git diff --check
  • manual DeepSeek R1 smoke: explicit tool_cycle / all leave full render unchanged; default/tool_cycle decline user-boundary bridge; all bridges across it when structurally valid

Note

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_retention as bridge-only policy, not something that changes full render() history. Unset (None) derives effective_thinking_retention at construction from each renderer’s template knobs (clear_thinking, preserve_thinking, auto_drop_analysis, enable_thinking, etc.); explicit values only choose when bridge_to_next_turn must fall back to a full re-render (template / tool_cycle / all).

Centralizes bridge decisions in resolve_thinking_retention and should_rerender_for_thinking_retention, replacing per-bridge token-marker scans and should_preserve_past_thinking / reject_thinking_strip_in_extension. Hand-coded render paths now emit historical reasoning only via their chat-template logic; Qwen3.6 gains preserve_thinking, gpt-oss gains auto_drop_analysis, with stricter config conflict validation.

Docs and tests align with the split: generic retention must not alter full-render token streams; DefaultRenderer rejects explicit retention; bridge tests expect tool_cycle to 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

  • Introduces resolve_thinking_retention in base.py to compute an effective_thinking_retention (one of 'template', 'tool_cycle', 'all') once at construction time, replacing per-message should_preserve_past_thinking calls scattered across renderers.
  • Adds ThinkingRetention (user-facing: 'tool_cycle' | 'all') and ResolvedThinkingRetention (internal, also includes 'template') type aliases; None on config now means "defer to template" instead of the removed 'template' literal.
  • Replaces reject_thinking_strip_in_extension token-marker scanning in all renderers (Qwen3, Qwen3.5, Kimi K2/K2.5, GLM4.5/5, MiniMax M2, Nemotron3, etc.) with should_rerender_for_thinking_retention, causing extension bridges to return None (force full re-render) when retention semantics differ across a user-query boundary.
  • Removes the preserve_thinking override parameter from assistant-rendering helpers across affected renderers; full renders no longer force-emit historical reasoning_content based on thinking_retention—bridge policy and full render are now decoupled.
  • Adds preserve_thinking to Qwen36RendererConfig and auto_drop_analysis to GptOssRendererConfig, each validated against thinking_retention via the extended _reject_thinking_retention_conflict util.
  • Behavioral Change: thinking_retention is now a bridge-only policy; setting 'tool_cycle' or 'all' no longer changes full render output. DefaultRenderer now raises ValueError (was NotImplementedError) for explicit retention values.

Macroscope summarized 7a4013f.

@eligotts
eligotts marked this pull request as ready for review June 25, 2026 03:25
@macroscopeapp

macroscopeapp Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

Approvability

Verdict: 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.

@eligotts
eligotts merged commit 14fa8cc into refactor/thinking-retention Jun 25, 2026
4 checks passed
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