Skip to content

feat(translator,executor): preserve Kimi reasoning as canonical reasoning_content - #222

Open
warelik wants to merge 4 commits into
kaitranntt:mainfrom
warelik:ao/airouters-16-kimi-reasoning
Open

feat(translator,executor): preserve Kimi reasoning as canonical reasoning_content#222
warelik wants to merge 4 commits into
kaitranntt:mainfrom
warelik:ao/airouters-16-kimi-reasoning

Conversation

@warelik

@warelik warelik commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Preserves Kimi reasoning as canonical reasoning_content when translating Claude requests to OpenAI-compatible targets.

  • internal/translator/openai/claude/openai_claude_request.go shouldMapClaudeThinkingToReasoning: when target is a Kimi model, degrade Claude thinking blocks to unsigned reasoning_content instead of dropping foreign or unsigned signed blocks. GPT and unknown targets keep existing strict behavior.
  • internal/runtime/executor/helps/codex_multi_agent_v2.go TranslateRequestWithAPIKeyModelCompatibility: skip CarryOverThinkingToSystem for Kimi targets so prior reasoning_content stays in assistant messages rather than being moved into a system message.
  • internal/runtime/executor/helps/carry_over.go: carry-over helper for reasoning and plugin-payload doc comment.
  • internal/runtime/executor/kimi_executor.go fallbackAssistantReasoning: do not copy visible assistant content into reasoning_content for tool-call messages; fabricates hidden reasoning and risks self-reflection loops.

Dependency note

The Kimi preservation work is built on top of the carry-over feature:

  • c75a7d6b feat(executor): carry prior reasoning into system instructions — adds CarryOverThinkingInSystem, internal/runtime/executor/helps/carry_over.go, and the TranslatorConfig struct in internal/config.
  • 0d97093d refactor(helps): route claude carry-over through registry — refactors carry-over through carryOverClaudeSource and updates codex_multi_agent_v2.go.
  • ff4aeeb2 feat(translator,executor): preserve Kimi reasoning as canonical reasoning_content — adds Kimi-aware thinking mapping and the carry-over skip.
  • 70f7a097 fix(executor): do not fabricate Kimi reasoning from visible content — removes the content-to-reasoning fallback for tool-call messages.

e0e1d512 (prompt-cache context in openai_claude_request.go) was folded as needed for the Kimi hunk; the prompt-cache feature itself is not part of this change.

Test plan

  • go build ./... green
  • go test ./... green
  • New tests pin Kimi reasoning preservation, carry-over skip, and content fallback removal.

Stock issues

Decision

  • reports/kimi-fallback-reasoning-decision.md

Integration counterpart

warelik#2

@warelik warelik left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AO review: approved (posted as COMMENT; GitHub rejects APPROVE on ones own PR).

This is a batch sync of the mission-integration branch into main (126 commits / 123 files). Verified composition and head state:

  • Constituent work already reviewed per-PR: the merges cover PRs #188-#218 (failover/cooldown fixes, signature hardening, thinking-replay and cache-control fixes, carry-over feature, configurable cooldown knobs, management endpoints), each of which went through its own review cycle on this repo.
  • Spot-checked integration integrity at head ff4aeeb: the cache-determinism files from #213 (session_id_cache.go, user_id_cache.go) are byte-identical to the approved #213 head; cloak_utils.go differs only in a doc comment; the carry-over feature files match the approved #216 state.
  • Net-new content is the head commit (Kimi reasoning preservation) — same SHA as the warelik fork PR #2 reviewed today: translator degrades Claude thinking to canonical reasoning_content on Kimi targets via DecideSignatureCompatibilityForModel (Preserve/DropSignature only), carry-over gate skips Kimi so reasoning stays in the canonical container, GPT/unknown strict paths and the compat wrapper unchanged. Byte-identical files confirmed across forks.
  • CI is meaningful here: the build check runs go build ./cmd/server plus the full go test ./... suite — green at this head.

Carried-forward non-blocking items (already raised on their owning PRs, none block this sync): (1) translator.carry-over-thinking-in-system is still absent from config.example.yaml while the #217 knobs are documented; (2) the unreachable content: [] branch in carry_over.go; (3) optional extra Kimi signature test cases.

warelik added a commit to warelik/CLIProxyAPIPlus that referenced this pull request Aug 22, 2026
Add config-gated carryOverThinkingInSystem that moves previous assistant
reasoning_content into a labeled system message for OpenAI chat targets
that lack a canonical thought field. Defaults off to preserve protocol
purity.
Extract unsigned assistant thinking into the source system field before
registry translation so plugin NormalizeRequest hooks run. Signed thinking
with compatible signatures stays in place and maps to reasoning_content as
before.
…ning_content

- openai_claude_request.go: target-aware thinking mapping; Kimi degrades
  signed/unsigned Claude thinking to reasoning_content, GPT keeps strict.
- codex_multi_agent_v2.go: skip CarryOverThinkingToSystem for Kimi targets
  so prior reasoning stays in canonical reasoning_content.
- carry_over.go: fix plugin-payload doc comment.

Tests pin Kimi degradation and carry-over skip.
fallbackAssistantReasoning previously copied assistant content into
reasoning_content for tool-call messages when no prior reasoning existed.
That fabricates hidden reasoning from visible text and risks
self-reflection loops on replay. It now returns [reasoning unavailable]
unless a usable prior reasoning_content exists.

Decision: reports/kimi-fallback-reasoning-decision.md
@warelik
warelik force-pushed the ao/airouters-16-kimi-reasoning branch 2 times, most recently from 6a27105 to d34e87d Compare August 22, 2026 06:16
warelik added a commit to warelik/CLIProxyAPIPlus that referenced this pull request Aug 22, 2026
…soning as canonical reasoning_content (updated head)
@warelik
warelik force-pushed the ao/airouters-16-kimi-reasoning branch from d758a28 to 6a27105 Compare August 22, 2026 06:28
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