kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

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

Open Heyu2002 opened this issue 4 months ago • 2 comments

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

  • [x] I have read the CONTRIBUTING document.
  • [x] I have linked a related issue, or explained the problem above.
  • [x] I have added tests that prove my feature works.
  • [x] Ran gen-changesets skill, or this PR needs no changeset.
  • [x] Ran gen-docs skill, or this PR needs no doc update.

Heyu2002 avatar Jul 23 '26 03:07 Heyu2002

🦋 Changeset detected

Latest commit: 4e49431f3d7d124a5fb785950929bbcc34516b35

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

changeset-bot[bot] avatar Jul 23 '26 04:07 changeset-bot[bot]

@reviewer Hi, could you please review this PR? Three GitHub Actions workflows are currently awaiting approval. If you have write access to the repository, please review them and click Approve and run workflows. Thank you!

Heyu2002 avatar Jul 27 '26 03:07 Heyu2002