Skip to content

fix(agent-core-v2): preserve llm reasoning and usage compatibility - #4485

Merged
sailist merged 1 commit into
mainfrom
fix-301-10-28-llm-compat-followups
Oct 28, 2026
Merged

sailist merged 1 commit into
mainfrom
fix-301-10-28-llm-compat-followups

Conversation

@sailist

@sailist sailist commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Follow up on #4352 with two LLM compatibility fixes identified during review:

  • Unmarked reasoning history uses the previous model's dialect after an A → B → A model switch.
  • OpenAI Responses streams can drop top-level token usage when an event also contains response metadata.

Bug Reproduction Steps

  1. Run a request with a model that detects reasoning, switch to a model that detects reasoning_content, then switch back with history containing one explicitly marked and one unmarked thinking part. The unmarked part is emitted with reasoning_content instead of the current model's reasoning key.
  2. Stream an ordinary OpenAI Responses event containing both response metadata and top-level usage. The emitted token usage is undefined.

Root Cause

  • Outbound reasoning dialect selection consulted historical keys before the current model's detected key, overriding main's detected-key priority for unmarked parts.
  • The Responses decoder read only nested response.usage whenever response metadata was present, even for ordinary events that carry usage at the top level.

Both fixes address the selection logic directly rather than adding a compatibility workaround.

Code Changes

  • Use explicit reasoning configuration first, then the current model's detected dialect, then historical keys, then the default. Explicitly marked historical parts remain unchanged.
  • Keep nested-only usage handling for response.completed and response.incomplete; for other Responses events, fall back from nested usage to top-level usage.
  • Extend existing reasoning and Responses tests without adding test declarations.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Unmarked reasoning after an A → B → A model switch Uses the previous model's dialect Uses the current model's detected dialect OpenAI-compatible and Kimi reasoning histories; restores main's priority Explicit configuration and explicitly marked history are unchanged
Ordinary Responses events with response metadata and top-level usage Token usage is omitted Token usage is reported Clients consuming usage from compatible Responses streams Terminal response.completed and response.incomplete handling is unchanged

Coverage: thinking.test.ts exercises real HTTP model switches and mixed marked/unmarked history; trait.test.ts exercises a real requester stream with top-level usage. Prior focused verification passed: thinking 15/15, trait plus response-format 69/69, and agent-core-v2 typecheck.

Checklist

  • I have read the CONTRIBUTING document.
  • Linked the originating PR refactor(agent-core-v2): port the agent-core llm core into human/llm #4352; there is no separate issue.
  • Added regression assertions to existing tests without increasing the test count.
  • The behavior-change table is complete; no default is flipped and no existing behavior is removed.
  • Ran gen-changesets; no changeset was added per the author's decision.
  • No documentation update is needed because this restores existing behavior without changing configuration or public APIs.

- prefer the current model's detected reasoning dialect for unmarked history
- restore top-level usage fallback for ordinary Responses events
@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 77bc08a

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T07:55:00.033337Z 77bc08a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026

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

commit: 77bc08a

@sailist
sailist merged commit 88c3bec into main Oct 28, 2026
17 checks passed
@sailist
sailist deleted the fix-301-10-28-llm-compat-followups branch October 28, 2026 08:07
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
MoonshotAI#4410 MoonshotAI#4413 MoonshotAI#4431 MoonshotAI#4450 MoonshotAI#4451 MoonshotAI#4485 MoonshotAI#4524 were each implemented earlier —
the compaction prefix suite, the media-recovery case, the OAuth callback
socket drain, the split delivering-work section, the compaction wording,
the reasoning-key order and the 10-step todo reminder are all in the tree
and pinned by their own tests. Each row now carries that probe.

Only MoonshotAI#4410 needed care: upstream patched paths that this fork renamed
(`human/llm/builtin/protocol` versus `human/llm/requester/bases`), so the
matching was done on the behaviour — stripDynamicToolContext is gone and
extractEventUsage already reads usage only on terminal response events.

Ledger: closed 22 -> 28, remaining 71.
teknium1 added a commit to NousResearch/hermes-agent that referenced this pull request Nov 20, 2026
… terminal event

Same bug class on the Responses wire: a Responses-compatible server can
put usage on the `response.completed` event itself instead of inside its
`response` object. The Codex assembler read only the nested copy, so the
turn's usage was None. Fall back to the event-level copy; the nested one
still wins when both exist. kimi-code#4485 restored the same fallback
in its Responses decoder.
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.

2 participants