MoonshotAI / MoonshotAI/kimi-code

Session close and server shutdown leave session-scoped resources alive

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

Problem

Several session-scoped resources are only released by explicit per-resource close paths or full process disposal. When a session is archived or the daemon/server shuts down, live sessions and related server-side state can remain active longer than intended.

Observed cleanup gaps:

  • server shutdown disposes the DI graph without first closing live agent sessions
  • terminal records and pty processes are not cleaned up when a session closes
  • filesystem watcher entries are not disposed when a session closes
  • WebSocket broadcast per-session buffers, journal state, and in-flight turn tracking are not removed when a session closes
  • tool-call start timestamps can remain after interrupted/aborted turns

Expected behavior

Session archive and server shutdown should use the normal session/resource cleanup paths so session-owned processes, watchers, buffers, journals, and turn bookkeeping are released promptly.

Proposed fix

  • add a bulk live-session close path and call it during server shutdown before DI disposal
  • subscribe session-scoped services to session close events
  • drop per-session terminal, fs watcher, and WebSocket broadcast state on close
  • clear tool-call timing state on turn boundaries/abort paths

Scope

This issue is limited to session lifecycle cleanup. Longer-term retention policies for completed background tasks/subagents and unrelated timeout hardening can be handled in separate follow-ups.

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 the session archive/close path and the server shutdown path first, then inspect the session-owned terminal, pty, filesystem watcher, WebSocket broadcast, journal, and turn-tracking state described in the issue. Verify that shutdown closes live sessions before DI disposal and that session close removes all listed resources, including tool-call timing state after aborts.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, 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.