MoonshotAI / MoonshotAI/kimi-code

fix(kap-server): make boot and telemetry shutdown lifecycle complete

Open
#2,247 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

Context

PR #2230 added a deliberately local, 3-second best-effort telemetry close path to kap-server. The review also exposed broader server lifecycle gaps that were kept out of that PR.

Problem

  • The server must quiesce asynchronous engine telemetry producers before the final telemetry flush; otherwise events can be emitted after the flush boundary.
  • If startServer fails after partially initializing scopes, routes, or telemetry, boot needs one complete rollback path rather than ad hoc cleanup at individual call sites.

These are server lifecycle invariants, not part of wiring a new telemetry appender.

Scope

  • Define and enforce shutdown ordering: stop intake, quiesce producers, perform bounded telemetry shutdown, then dispose remaining scopes/resources.
  • Preserve the invariant that telemetry failure never blocks core/instance cleanup.
  • Make partially completed startServer initialization unwind every acquired resource exactly once.
  • Avoid changing public CLI shutdown policy in this issue.

Acceptance criteria

  • No telemetry event can be produced after the final flush boundary.
  • Cleanup continues when telemetry flush rejects or reaches its deadline.
  • Failure injection at each meaningful boot stage leaves no live server, timer, appender, or scope.
  • Normal close and partial-boot rollback are idempotent and covered by tests.

Follow-up to #2230.

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 at startServer and the lifecycle path discussed in PR #2230. Trace boot and close handling for scopes, routes, telemetry, timers, and intake; use failure injection at each meaningful boot stage and verify idempotent normal close and rollback, continued cleanup after telemetry failure, and no event after the final flush boundary.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend, observability
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.