Skip to content

feat(agent-core-v2): round-trip reasoning_details in chat completions - #3492

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat-142-09-03-reasoning-details
Sep 8, 2026
Merged

feat(agent-core-v2): round-trip reasoning_details in chat completions#3492
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:feat-142-09-03-reasoning-details

Conversation

@sailist

@sailist sailist commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — internal task: client-side phase 1 support for the OpenGW "thinking hiding + summary" rollout (no public issue).

Problem

OpenGW will hide raw model thinking from Chat Completions responses and instead send a readable summary plus an encrypted reasoning state that clients must replay verbatim on later turns. The wire shape is a new reasoning_details array (summary segments plus one trailing encrypted element, index-addressed when streaming) alongside the existing reasoning_content plaintext. Today kimi-code silently drops array-shaped reasoning_details — the reasoning extractor only accepts strings — and outbound history only echoes concatenated think text under a single reasoning key while discarding ThinkPart.encrypted. Once OpenGW makes reasoning_details mandatory on continuation (phase 2 rejects requests without it), multi-turn conversations would fail.

What changed

  • Inbound (OpenAI chat base, stream and non-stream): array-shaped reasoning_details is parsed into ThinkParts keyed by the element's index; the string reasoning dialect is only observed when no array is present. Elements whose type is not summary/encrypted are skipped, so OpenRouter's reasoning.* array dialect stays ignored as before.
  • Contract: ThinkPart gains detailsIndex; mergeInPlace refuses to merge think parts with different indices, so summary segment boundaries survive streaming and the array replays in original order (encrypted element last, delivered once).
  • Outbound: assistant history carrying details-origin think parts is serialized back to reasoning_details (summary segments in order plus the trailing encrypted element) together with reasoning_content (segment concatenation); messages without details keep the existing dialect behavior byte-for-byte.
  • Interruption: streamed thinking that never received its encrypted state is dropped from history on abort; thinking that already carries the ciphertext is kept and replayed on the next turn.
  • State manifest regenerated for the ThinkPart shape change.

Verification: focused kosong contract/provider and agent loop tests pass; the full agent-core-v2 suite passes except pre-existing environment-dependent region-marker tests on this machine; repo-wide typecheck and lint pass.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3c63038

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@3c63038
npx https://pkg.pr.new/@moonshot-ai/kimi-code@3c63038

commit: 3c63038

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 714ef33b53

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +436 to +438
const reasoningDetails = extractReasoningDetails(message);
if (reasoningDetails !== undefined) {
yield* convertReasoningDetails(reasoningDetails);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor the explicitly configured reasoning key

When reasoningKey is explicitly configured and a response also contains an array-valued reasoning_details, this branch bypasses ReasoningKeyDialect.observe and accepts the array anyway. The resulting detailsIndex parts are subsequently serialized as reasoning_details plus reasoning_content, rather than under the configured key, so the explicit setting no longer pins the dialect as its existing contract and test describe; apply details detection only when no explicit key is set, in both response paths.

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the feat-142-09-03-reasoning-details branch 2 times, most recently from 714ef33 to 38ec6e0 Compare September 7, 2026 07:16
@sailist
sailist force-pushed the feat-142-09-03-reasoning-details branch from 38ec6e0 to 3c63038 Compare September 7, 2026 08:30
@sailist
sailist merged commit a0191da into MoonshotAI:main Sep 8, 2026
15 checks passed
arrrrny added a commit to arrrrny/kimi-code-sync that referenced this pull request Sep 9, 2026
Sync 147 upstream commits onto the fork. Notable upstream changes:
- Remove the protocol package and relocate wire types into
  agent-core-v2/src/events.ts (MoonshotAI#3646)
- Absorb stepRetry into the LLM requester turn state machine (already
  followed in the 2026-09-07 sync)
- NotifyUser tool + mid-turn update panel (MoonshotAI#3524)
- HEIC/HEIF/BMP image support (MoonshotAI#3649), resumable large file reads
  (MoonshotAI#3645), reasoning_details round-trip (MoonshotAI#3492), zstd updater
  manifests (MoonshotAI#3669)

Conflict resolutions (all by hand, fork features preserved):
- package.json: drop the empty simple-git-hooks block (upstream cleanup;
  not a fork feature).
- docs/config-manifest.toml: take the union, then regenerate with
  pnpm gen:config-manifest (33 sections, fork sections intact).
- test/agent/stepRetry/stepRetry.test.ts: keep upstream's slimmed
  retryBackoffDelays test — the fork had deleted the old fat version
  when stepRetry was absorbed; the util is fork-used code with no other
  coverage.
- protocol/src/events.ts: accept upstream's package removal; the fork's
  compaction.started model/model_display fields already auto-merged
  into their new home (agent/fullCompaction/compactionOps.ts). No source
  still imports @moonshot-ai/protocol.

Merge follow-ups:
- Regenerate state/wire/config manifests; freshness tests pass.
- node-sdk update-all-session-models flag test: drop the v1-engine
  parity half (legacy agent-core v1 is removed upstream); keep the v2
  registration pin.
- Fix pre-existing lint errors in merge-touched files so the
  lint-staged pre-commit gate passes: unused imports/variables
  (sdk-rpc-client-v2.ts, tui/commands/config.ts,
  check-import-boundaries.mjs), floating promises (sdk-rpc-client-v2.ts,
  fullCompaction.test.ts).
- Add compactionOps.ts (model_display) to .github/FORK_OWNED_FILES so
  the relocated compaction-model fields are guard-listed.

Verification:
- pnpm run typecheck green; pnpm run lint at fork baseline (no new
  findings vs pre-merge HEAD).
- FORK_OWNED_FILES markers all resolve.
- Fork suites pass: TUI commands + session CLI (75 tests),
  x-opencode-session (7), update-all-session-models flag, oauth
  openai-compatible.
- fullCompaction.test.ts: 2 failures, both pre-existing at pre-merge
  HEAD (baseline had 5; upstream's macOS stabilization fixed 3.
EOF
)
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