Skip to content

fix: preserve the crash error in diagnostic logs on unexpected exit - #1757

Merged
RealKai42 merged 1 commit into
mainfrom
fix/crash-log-flush-on-emergency-exit
Jul 15, 2026
Merged

fix: preserve the crash error in diagnostic logs on unexpected exit#1757
RealKai42 merged 1 commit into
mainfrom
fix/crash-log-flush-on-emergency-exit

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below (from a real user report).

Problem

When the interactive CLI dies from an unexpected error (uncaughtException / unhandledRejection), the crash handler logs the error and immediately calls process.exit(1) on the same tick. The diagnostic log sink drains asynchronously, so the single line that explains why the process crashed is still sitting in the in-memory queue at exit and never reaches the log file. We received a user report of the CLI "exiting by itself" mid-turn where the global log contained nothing — consistent with this drop — making such crashes impossible to diagnose from exported sessions.

What changed

  • Add flushDiagnosticLogsSync() to the diagnostic logging surface (agent-core, re-exported through @moonshot-ai/kimi-code-sdk; RootLogger itself stays internal). It appends pending entries with appendFileSync, so they survive an immediate process.exit().
  • Call it in the TUI's emergency-exit path before restoring the terminal and exiting, wrapped so an exit path can never throw.
  • Tests: prove a synchronously-flushed entry reaches the file before the async drain could run, and prove both crash handlers flush before exiting with code 1.

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.

The TUI crash path (uncaughtException / unhandledRejection) logged the
error into an asynchronously-drained sink and then called process.exit()
on the same tick, so the one line explaining the crash was never written
to disk. Flush the diagnostic logs synchronously before exiting.
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fd53592

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

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

commit: fd53592

@RealKai42
RealKai42 merged commit f0c8a10 into main Jul 15, 2026
15 checks passed
@RealKai42
RealKai42 deleted the fix/crash-log-flush-on-emergency-exit branch July 15, 2026 17:26
@github-actions github-actions Bot mentioned this pull request Jul 15, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Jul 15, 2026
…oonshotAI#1757)

The TUI crash path (uncaughtException / unhandledRejection) logged the
error into an asynchronously-drained sink and then called process.exit()
on the same tick, so the one line explaining the crash was never written
to disk. Flush the diagnostic logs synchronously before exiting.
7723qqq added a commit to 7723qqq/kimi-code that referenced this pull request Jul 15, 2026
…oonshotAI#1676 MoonshotAI#1625 MoonshotAI#1746 MoonshotAI#1753 MoonshotAI#1757)

Critical fixes cherry-picked from upstream v0.24.x:
- fix(agent-core-v2): align rate-limit retries with v1 (MoonshotAI#1598)
- fix: preserve empty reasoning across providers (MoonshotAI#1676)
- fix: resolve and synchronize thinking effort (MoonshotAI#1625)
- fix: align Anthropic-compatible model capabilities (MoonshotAI#1746)
- fix(kap-server): close auth bypass via percent-encoded API paths (MoonshotAI#1753)
- fix: preserve the crash error in diagnostic logs on unexpected exit (MoonshotAI#1757)
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