Skip to content

fix(cli): persist diagnostics before dead-terminal exits#2088

Open
Heyu2002 wants to merge 4 commits into
MoonshotAI:mainfrom
Heyu2002:main
Open

fix(cli): persist diagnostics before dead-terminal exits#2088
Heyu2002 wants to merge 4 commits into
MoonshotAI:mainfrom
Heyu2002:main

Conversation

@Heyu2002

Copy link
Copy Markdown

Related Issue

Terminal execution abnormal termination #2045

Problem

When stdout or stderr reports a dead-terminal error such as EIO or EPIPE, the TUI restores the terminal and immediately exits with code 129.

Because the exit is immediate, diagnostics written through buffered output or asynchronous logging may be lost. This leaves insufficient durable context to determine whether an observed session termination was caused by a task failure, a terminal stream failure, or another exit path.

What changed

  • Added a synchronous diagnostic callback before the dead-terminal emergency exit.
  • Recorded the failing stream, error metadata, session and turn context, streaming phase, terminal state, process identifiers, and exit code.
  • Synchronously flushed file-backed diagnostic logs before calling the emergency exit path.
  • Kept diagnostic recording best-effort so logging failures cannot prevent terminal restoration or exit.
  • Added coverage for stdout EIO, stderr EPIPE, unrelated stream errors, diagnostic callback failures, captured context, and log ordering.
  • Added a patch changeset for @moonshot-ai/kimi-code.

The existing emergency-exit behavior is intentionally unchanged. No documentation update is needed because this change adds internal diagnostics without introducing new commands, configuration, or user-facing workflows.

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, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7465ca2

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

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code 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

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