feat(kap-server): wire cloud telemetry for engine events - #2230
Merged
Conversation
The v2 engine registers a full telemetry event catalog, but kap-server never attached an appender, so events from web-hosted sessions were dropped to the null appender. Add an opt-in `telemetry` start option that attaches a CloudAppender (app_name kimi-code-cli, ui_mode web, matching the v1 `kimi web` host conventions), still gated by the config `telemetry` toggle, with periodic flush and a bounded flush on close. The option defaults off so tests never post to the real endpoint; the CLI's `kimi web` host enables it.
|
commit: |
This was referenced Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
No linked issue — the problem is explained below.
Problem
The v2 engine (
agent-core-v2) registers a full telemetry event catalog (turn_started,tool_call,permission_approval_result,session_started,image_compress, …), but kap-server never attached an appender to itsITelemetryService: the appender list stays at the default[nullTelemetryAppender], so every event from web-hosted sessions is silently dropped. The web UI's "Improve product with usage data" toggle writes the configtelemetryflag, yet nothing on the server consumes it — toggling it changes nothing.The session lifecycle also wrote each newly created or resumed session ID into the App-scoped telemetry root. In a long-lived server hosting multiple sessions, creating session B therefore caused subsequent events from session A to be attributed to B.
What changed
packages/kap-server/src/services/telemetry.ts(new):initializeServerTelemetrymirrors the v1kimi webhost wiring — same productapp_name = kimi-code-cliwith the surface distinguished byui_mode = web, shared<home>/device_idviacreateKimiDeviceId, access token fromIOAuthToolkit, model fromdefaultModel. Honors the configtelemetrytoggle at startup (the web settings UI already tells users a restart is required). Because the server is long-lived it also starts the appender's periodic flush (30s), not just threshold/exit flushing.shutdownServerTelemetrybounds the final flush to 3s so a wedged endpoint cannot hold server shutdown hostage.packages/kap-server/src/start.ts: new opt-intelemetrystart option. When enabled, the appender is attached right afterbootstrap(), before any session exists, sosession_started/session_load_failedare not lost; initialization is best-effort (a telemetry failure never blocks boot), and close flushes before the Core scope is disposed. The option defaults to off so kap-server's own test suite (and any embedding host) never posts to the real telemetry endpoint unintentionally.apps/kimi-code/src/cli/sub/web/run.ts: thekimi webhost passestelemetry: true. This complements the v1 telemetry client already registered there, which only covers host-level events — engine events now flow too.ITelemetryServicecontext view instead of mutating the App-scoped root.CloudAppenderderives the top-levelsession_idfrom the event context when present, while retaining its configured fallback for single-session hosts.packages/kap-server/test/telemetry.test.tscovers appender attachment by default (with device-id persistence) and thetelemetry = falseconfig path. Agent-core-v2 regression tests cover interleaved events from two Session scopes and event-localsession_idenrichment.Note:
packages/kap-server/test/sessions.test.ts"bundles the on-disk desktop app log" is flaky under full-suite parallel load in my local environment (itsafterEachclose hits the 10s hook timeout); it reproduces on a cleanupstream/maincheckout without this change and passes in isolation, so it is unrelated to this PR.Checklist
gen-changesetsskill, or this PR needs no changeset. (Telemetry-only change — per repo convention telemetry changes ship without a changeset.)gen-docsskill, or this PR needs no doc update. (No user-facing surface change: the existing settings toggle simply starts taking effect server-side.)