MoonshotAI / MoonshotAI/kimi-code

Session lifecycle resource leaks, compaction budget overrun, and cancellation timeout gaps

Open
#1,248 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

Summary

Long-running sessions can retain completed state indefinitely, and local process calls can hang without reliable cancellation or deadlines.

Problem

Six lifecycle/cancellation gaps create resource retention and reliability risks:

  1. Unbounded background task retention. BackgroundManager keeps every entry in tasks for the session lifetime, and scheduledNotificationKeys / deliveredNotificationKeys only grow. Task output is bounded per entry, but entry count is not.
  2. Idle subagent runtime state is never pruned. Session.agents accumulates a ready Agent per spawned subagent even after it is no longer active; heavy subagent sessions retain these objects in heap memory.
  3. MCP listeners are not fully cleared on shutdown. McpConnectionManager.shutdown() removes entries but leaves listeners, allowing stale callbacks after shutdown.
  4. External editor cannot be reliably cancelled. editInExternalEditor spawns $EDITOR without AbortSignal integration or a guaranteed child.kill() path, so a wedged editor can block the UI path.
  5. execFileUtf8 has no default deadline. packages/server service execution only times out when callers pass timeoutMs, so hung helpers (for example systemctl/launchctl) can stall indefinitely.
  6. Compaction may over-request completion tokens near context boundaries. FullCompaction computes the budget before estimating request tokens, so chat-completion providers can receive an output cap that exceeds remaining context.

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

Trace BackgroundManager task and notification collections, Session.agents, and McpConnectionManager.shutdown() first to map their lifecycle and shutdown paths. Then inspect editInExternalEditor, packages/server execFileUtf8, and FullCompaction; done means all six reported retention, cancellation, deadline, and token-budget gaps have bounded behavior without regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, cli, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.