Skip to content

feat(kap-server): wire cloud telemetry for engine events - #2230

Merged
7Sageer merged 7 commits into
mainfrom
feat/kap-server-cloud-telemetry
Jul 27, 2026
Merged

feat(kap-server): wire cloud telemetry for engine events#2230
7Sageer merged 7 commits into
mainfrom
feat/kap-server-cloud-telemetry

Conversation

@7Sageer

@7Sageer 7Sageer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

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 its ITelemetryService: 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 config telemetry flag, 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): initializeServerTelemetry mirrors the v1 kimi web host wiring — same product app_name = kimi-code-cli with the surface distinguished by ui_mode = web, shared <home>/device_id via createKimiDeviceId, access token from IOAuthToolkit, model from defaultModel. Honors the config telemetry toggle 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. shutdownServerTelemetry bounds the final flush to 3s so a wedged endpoint cannot hold server shutdown hostage.
  • packages/kap-server/src/start.ts: new opt-in telemetry start option. When enabled, the appender is attached right after bootstrap(), before any session exists, so session_started / session_load_failed are 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: the kimi web host passes telemetry: true. This complements the v1 telemetry client already registered there, which only covers host-level events — engine events now flow too.
  • Session isolation: each Session scope receives its own ITelemetryService context view instead of mutating the App-scoped root. CloudAppender derives the top-level session_id from the event context when present, while retaining its configured fallback for single-session hosts.
  • Tests: packages/kap-server/test/telemetry.test.ts covers appender attachment by default (with device-id persistence) and the telemetry = false config path. Agent-core-v2 regression tests cover interleaved events from two Session scopes and event-local session_id enrichment.

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 (its afterEach close hits the 10s hook timeout); it reproduces on a clean upstream/main checkout without this change and passes in isolation, so it is unrelated to this PR.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset. (Telemetry-only change — per repo convention telemetry changes ship without a changeset.)
  • Ran gen-docs skill, or this PR needs no doc update. (No user-facing surface change: the existing settings toggle simply starts taking effect server-side.)

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.
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8110eff

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@8110eff
npx https://pkg.pr.new/@moonshot-ai/kimi-code@8110eff

commit: 8110eff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant