kimi-code
kimi-code copied to clipboard
fix(kap-server): make boot and telemetry shutdown lifecycle complete
Summary
Fixes #2247. Defines and enforces explicit shutdown ordering in kap-server so telemetry producers are quiesced before the final flush boundary.
Changes
Shutdown ordering (close())
- Stop HTTP/WS intake —
app.close()drains in-flight requests and rejects new connections. - Quiesce telemetry producers — resolve
ISessionLifecycleServiceand close every active session. Each session close stops its agents, which stops emitting lifecycle events. This guarantees no telemetry event is produced after the final flush boundary. - Bounded telemetry flush —
shutdownServerTelemetryruns within its deadline; failures are logged but never block core cleanup. - Dispose core scope + release instance registration — the existing best-effort rollback handles partial-boot scenarios.
Partial-boot rollback
- The existing listen-failure path (
try/catcharoundlistenWithPortRetry) already callsclose(), which now drains whatever was successfully initialized (sessions, telemetry, core) and releases the instance registration. - Session draining is wrapped in
try/catchso it does not fail in partial-init scenarios whereISessionLifecycleServiceis not yet available.
Invariants preserved
- Telemetry failure never blocks core/instance cleanup.
- Normal close and partial-boot rollback are idempotent.
- No change to public CLI shutdown policy.
🦋 Changeset detected
Latest commit: b62f076faee869dac0b3149a07d2b79932cd7e2b
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @moonshot-ai/kap-server | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR