Skip to content

fix(agent-core): recover sessions interrupted during thinking#2172

Open
morluto wants to merge 2 commits into
MoonshotAI:mainfrom
morluto:codex/audit-think-only
Open

fix(agent-core): recover sessions interrupted during thinking#2172
morluto wants to merge 2 commits into
MoonshotAI:mainfrom
morluto:codex/audit-think-only

Conversation

@morluto

@morluto morluto commented Jul 25, 2026

Copy link
Copy Markdown

Related Issue

Resolve #1404

Related prior work: #1882

Problem

If a process exits after recording step.begin and a nonempty thinking part but before step.end, v1 resume reconstructs the unfinished assistant step as ordinary history.

The OpenAI-compatible adapter extracts the thinking part into reasoning_content. Because the interrupted step has no answer text or tool call, the resulting request has neither content nor tool_calls, and strict providers reject every later request from that session.

The vacuous-message repair in #1968 handles empty or whitespace-only thinking. #1882 similarly checks assistant entries whose content array is empty. The record reported in #1404 contains a nonempty ThinkPart, so it does not satisfy that predicate.

step.begin -> nonempty ThinkPart -> process exits
     |
     +-- resume marks the open response partial -> omitted
     |
     +-- adapter rejects contentless/tool-less assistant history

What changed

  • Track tool-free assistant steps that remain open at the end of v1 resume and exclude them from provider projections without changing canonical history.
  • Keep interrupted tool-call steps so the existing synthetic result can close their tool exchange.
  • Prevent the OpenAI-compatible adapter from emitting assistant history with neither content nor tool_calls.
  • Preserve reasoning fields on valid assistant tool-call messages.
  • Add regressions using the nonempty thinking-only record shape from Empty assistant message after terminal crash causes 400 on session resume (DeepSeek) #1404.

The adapter does not copy private reasoning into visible assistant content and does not rely on an empty-string fallback that strict providers may reject.

Validation:

  • Agent resume tests: 29 passed
  • OpenAI legacy provider tests: 78 passed
  • @moonshot-ai/kosong and @moonshot-ai/agent-core typechecks
  • Oxlint on changed TypeScript files
  • git diff --check
  • Changeset validation

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, and included a patch changeset.
  • This restores existing resume behavior and needs no documentation update.

@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a5b526c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch
@moonshot-ai/kosong Patch

Not sure what this means? Click here to learn what changesets are.

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

@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: 946681c262

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/kosong/src/providers/openai-legacy.ts
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.

Empty assistant message after terminal crash causes 400 on session resume (DeepSeek)

1 participant