MoonshotAI / MoonshotAI/kimi-code
fix(kap-server): make boot and telemetry shutdown lifecycle complete
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
startServerfails 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
startServerinitialization 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
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
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