MoonshotAI / MoonshotAI/kimi-code
Session lifecycle resource leaks, compaction budget overrun, and cancellation timeout gaps
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:
- Unbounded background task retention.
BackgroundManagerkeeps every entry intasksfor the session lifetime, andscheduledNotificationKeys/deliveredNotificationKeysonly grow. Task output is bounded per entry, but entry count is not. - Idle subagent runtime state is never pruned.
Session.agentsaccumulates a readyAgentper spawned subagent even after it is no longer active; heavy subagent sessions retain these objects in heap memory. - MCP listeners are not fully cleared on shutdown.
McpConnectionManager.shutdown()removes entries but leaveslisteners, allowing stale callbacks after shutdown. - External editor cannot be reliably cancelled.
editInExternalEditorspawns$EDITORwithoutAbortSignalintegration or a guaranteedchild.kill()path, so a wedged editor can block the UI path. execFileUtf8has no default deadline.packages/serverservice execution only times out when callers passtimeoutMs, so hung helpers (for examplesystemctl/launchctl) can stall indefinitely.- Compaction may over-request completion tokens near context boundaries.
FullCompactioncomputes the budget before estimating request tokens, so chat-completion providers can receive an output cap that exceeds remaining context.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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