Skip to content

feat(telemetry): implement session tracking and telemetry server - #2098

Merged
RealKai42 merged 1 commit into
mainfrom
kaiyi/fuquay-varina
Apr 28, 2026
Merged

feat(telemetry): implement session tracking and telemetry server#2098
RealKai42 merged 1 commit into
mainfrom
kaiyi/fuquay-varina

Conversation

@RealKai42

@RealKai42 RealKai42 commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • emit a session_started telemetry event once per session with raw Wire client info as event properties
  • stop attaching client name/version to telemetry context while preserving UI mode context
  • add a local telemetry debug server script and focused telemetry/Wire tests

Test Plan

  • uv run pytest tests/telemetry tests/core/test_wire_server_steer.py::test_wire_client_info_emits_session_started
  • uv run ruff check src/kimi_cli/telemetry/__init__.py src/kimi_cli/telemetry/sink.py src/kimi_cli/app.py src/kimi_cli/wire/server.py src/kimi_cli/soul/agent.py tests/telemetry/test_instrumentation.py tests/telemetry/test_telemetry.py tests/telemetry/test_crash.py tests/core/test_wire_server_steer.py
  • uv run ruff format --check src/kimi_cli/telemetry/__init__.py src/kimi_cli/telemetry/sink.py src/kimi_cli/app.py src/kimi_cli/wire/server.py src/kimi_cli/soul/agent.py tests/telemetry/test_instrumentation.py tests/telemetry/test_telemetry.py tests/telemetry/test_crash.py tests/core/test_wire_server_steer.py
  • uv run pyright src/kimi_cli/telemetry src/kimi_cli/wire/server.py src/kimi_cli/app.py src/kimi_cli/soul/agent.py

Open in Devin Review

Copilot AI review requested due to automatic review settings April 28, 2026 06:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements per-session telemetry attribution by emitting a single session_started event per session (with raw Wire client info as properties), removing client name/version from the shared telemetry context, and adding local debugging + targeted tests.

Changes:

  • Add track_session_started_once(...) and process-level tracking to ensure session_started is emitted once per session.
  • Wire/app integration: emit session_started from Wire initialization (and a fallback on first prompt), and from non-wire app startup.
  • Add telemetry debug server script and update/extend tests to reflect new attribution model (client info on event properties, not context).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/kimi_cli/telemetry/__init__.py Adds session-started tracking API/state and opportunistic flush scheduling.
src/kimi_cli/telemetry/sink.py Removes client name/version enrichment from global context.
src/kimi_cli/wire/server.py Tracks session start from wire initialize + prompt fallback.
src/kimi_cli/app.py Tracks session start on app init for non-wire UI modes.
src/kimi_cli/soul/agent.py Adds ui_mode / resumed fields onto Runtime for attribution.
tests/telemetry/test_instrumentation.py Updates tests to assert client info is not in context; adds session_started-focused tests.
tests/telemetry/test_telemetry.py Resets new session_started tracking state in test fixture.
tests/telemetry/test_crash.py Resets new session_started tracking state in test fixture.
tests/core/test_wire_server_steer.py Adds focused test ensuring wire client info emits session_started.
scripts/telemetry_debug_server.py Adds a small local HTTP receiver for inspecting outbound telemetry payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +88 to +90
session_id = _session_id
if not session_id or session_id in _session_started_sessions:
return
Comment on lines +111 to +113
if _sink is not None:
with suppress(Exception):
asyncio.get_running_loop().create_task(_sink.flush())

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 copy_for_subagent does not propagate new ui_mode and resumed fields to subagent runtimes

The copy_for_subagent method at src/kimi_cli/soul/agent.py:339-361 constructs a new Runtime but does not pass ui_mode=self.ui_mode or resumed=self.resumed. This means every subagent runtime silently gets the defaults ui_mode="shell" and resumed=False, even when the parent is running in "wire" mode or was resumed. While no code currently reads these fields from subagent runtimes, the wire server accesses self._soul.runtime.resumed (src/kimi_cli/wire/server.py:639), and if a similar pattern is ever used in a subagent context, the values would be wrong.

(Refers to lines 339-361)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@RealKai42
RealKai42 merged commit 7d8652c into main Apr 28, 2026
24 checks passed
@RealKai42
RealKai42 deleted the kaiyi/fuquay-varina branch April 28, 2026 06:37
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.

2 participants