MoonshotAI / MoonshotAI/kimi-code

bug(tui): SubAgentEventHandler lacks error handling — unhandled exceptions can crash the TUI event loop

Open
#1,136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What version of Kimi Code is running?

Code audit finding (all versions) — apps/kimi-code/src/tui/controllers/subagent-event-handler.ts (643 lines)

Which open platform/subscription were you using?

N/A — code audit finding

What platform is your computer?

All platforms

What issue are you seeing?

The SubAgentEventHandler class (643 lines) has zero try/catch blocks across all its methods. Two critical public methods — routeChildAgentEvent() and handleLifecycleEvent() — are called directly from SessionEventHandler.handleEvent() (line 233 and line 270 in session-event-handler.ts) without any exception wrapper around them either.

If any internal operation throws (e.g., accessing a missing tool component via streamingUI.getToolComponent(), manipulating a cleared agentSwarmProgress map, formatting hook results, etc.), the exception propagates uncaught into the main TUI event loop, potentially crashing the UI.

Confirmed via CodeGraph: all 3 callers of SubAgentEventHandler methods are in session-event-handler.ts, and none of those call sites wrap the subagent handler calls in try/catch.

What steps can reproduce the bug?

  1. Trigger any code path that routes a subagent event through SubAgentEventHandler.routeChildAgentEvent() or handleLifecycleEvent()
  2. If an unexpected condition causes an internal error (e.g., null reference, missing map entry), the exception is not caught
  3. The TUI crashes or enters an inconsistent state

What is the expected behavior?

Exceptions in subagent event handling should be caught, logged, and gracefully handled so the TUI event loop continues running.

Suggested fix: wrap routeChildAgentEvent and handleLifecycleEvent bodies (or at minimum their public entry points) in try/catch blocks that log the error via the hosts logger and return a safe default.

Additional information

Discovered by systematic-codebase-audit skill during a routine scan. No known reproduction steps — this is a defense-in-depth finding.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apps/kimi-code/src/tui/controllers/subagent-event-handler.ts, focusing on routeChildAgentEvent() and handleLifecycleEvent(), then inspect their callers at the noted lines in session-event-handler.ts. Trace the existing hosts logger and event flow before deciding where handling belongs. Done means unexpected subagent-handler errors are caught and logged while the TUI event loop continues rather than crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.