fix(cli): persist diagnostics before dead-terminal exits
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
stdoutEIO,stderrEPIPE, 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-changesetsskill, or this PR needs no changeset. - [x] Ran
gen-docsskill, or this PR needs no doc update.
🦋 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
@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!