fix(cli): share telemetry shutdown deadline #2333
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.55) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 545 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2333"
general
weight: 0.35
ousamabenyounes
Requirement or Bug
Resolve #2248. CLI shutdown previously gave each telemetry owner a separate timeout, so a stalled engine pipeline followed by a stalled host pipeline could delay exit beyond the configured budget. The same budget must also cover cleanup after web startup fails.
Bug Reproduction Steps
The regression tests run two stalled telemetry pipelines under fake time. Before this change, their cumulative shutdown time exceeded one budget; the startup-failure cleanup path had the same problem. See
apps/kimi-code/test/cli/telemetry.test.ts,apps/kimi-code/test/cli/web/web.test.ts, andpackages/kap-server/test/boot.test.ts.Root Cause
The print and web entrypoints passed a fresh timeout to each independently owned telemetry pipeline.
RunningServer.close()had no way to receive the absolute deadline from the web host, and the webonReadyrejection path bypassed the normal shutdown policy. This is a shared-deadline fix, not a change to telemetry transport or stored data.Code Changes
One absolute deadline is created at each CLI shutdown boundary. Each pipeline receives only the remaining time, and the caller also bounds the await so a stalled token lookup cannot outlive the deadline. A rejection or timeout is reported without blocking the next owner. Web startup failure now uses the same close helper as normal shutdown.
The server-close error boundary remains distinct from telemetry failures, and print exit results are preserved. Start with
apps/kimi-code/src/cli/telemetry-shutdown.ts, then the print/web call sites andpackages/kap-server/src/start.ts.Behavior Changes and Affected Users
| Behavior | Before | After | Who relies on the old behavior | Escape hatch |
|---|---|---|---|---|
| Telemetry flush on print/headless CLI exit | Each pipeline could use a full timeout, extending exit latency | All pipelines share one absolute budget; failures are reported and later cleanup is still attempted | Headless CLI users, scripts that parse print output or exit status | No output format, exit code, flag, or telemetry setting changes; the existing telemetry toggle still applies |
| Telemetry flush on
kimi webexit or startup failure | Engine and host flushes could each wait a full timeout, including afteronReadyfailed | Both use the remaining shared budget; server close errors remain visible | Code-app web/desktop hosts and remote-control clients using the local server | No REST, WebSocket, remote-control protocol, auth, or persisted session shape changes |Previous-release clients and data remain compatible: this PR changes shutdown timing and warning behavior only. Existing CLI arguments, printed result formats, exit outcomes, REST/WebSocket contracts, remote-control messages, and stored sessions remain readable and unchanged. A stalled telemetry owner may receive less time than before because it shares the process exit budget; the configured budget itself and the telemetry setting stay the same.
Affected modules and evidence: print lifecycle tests cover failure, reporter failure, expired budget, and preserved exit result; web lifecycle tests cover normal shutdown, startup failure, and server-close error; kap-server tests cover the propagated deadline. On the rebased branch, 128 focused tests pass across four suites (including a RED → GREEN stalled-host-lookup regression),
apps/kimi-codeandpackages/kap-servertypecheck, and the CLI production build passes. Full Vitest matrix was not rerun for this rebase.Checklist
gen-changesetsskill; added a patch changeset for the CLI package.gen-docsskill; no documentation update is needed for this internal shutdown policy.