Skip to content

Add KV cache operation observability - #410

Open
shipiyouniao wants to merge 4 commits into
ovg-project:mainfrom
shipiyouniao:feature/operational-observability
Open

Add KV cache operation observability#410
shipiyouniao wants to merge 4 commits into
ovg-project:mainfrom
shipiyouniao:feature/operational-observability

Conversation

@shipiyouniao

Copy link
Copy Markdown
Contributor

Summary

  • add read-only operation counters, byte totals, latency, and error snapshots for KV cache managers
  • expose stable snapshots through the vLLM and SGLang integration interfaces
  • label SGLang MHA, MLA, and Mamba pools at manager creation so collectors can distinguish them
  • cover manager operations, snapshots, integration forwarding, bounded dimensions, and stub compatibility

Dependency

Depends on #385, which introduces the read-only snapshot foundation. This PR intentionally remains separate from #400; it contains no DeepSeek-V4 pool implementation changes.

Validation

  • python -m pytest tests/test_observability.py -q (8 passed)
  • ruff, codespell, isort, clang-format, PyMarkdown, actionlint, and trailing-whitespace hooks passed locally
  • strict MyPy for tests passed locally

The full Linux pre-commit and Python 3.9-3.13 MyPy matrix is left to CI because the local Windows host does not provide the repository scripts' POSIX flock, Unix sockets, and signal APIs.

Copilot AI review requested due to automatic review settings July 24, 2026 05:12
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

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

Adds a read-only observability surface for kvcached KV cache pools, including per-manager operation counters and integration-facing snapshot helpers so external collectors can retrieve stable, structured state without relying on engine internals.

Changes:

  • Introduces kvcached.observability dataclasses + registry helpers for pool/runtime snapshots and operation counter snapshots.
  • Adds monotonic operation counters + error metadata to KVCacheManager, and exposes snapshot/snapshot_dict helpers.
  • Wires vLLM/SGLang integration interfaces to register pools, clear registration on shutdown, and expose snapshot forwarding; labels SGLang pool types (mha/mla/mamba).

Reviewed changes

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

Show a summary per file
File Description
tests/test_observability.py Adds unit tests covering operation counters, snapshot serialization, weakref registry behavior, and integration forwarding.
kvcached/observability.py Implements snapshot dataclasses, capability discovery, and a weakref-based registry for live pools.
kvcached/kv_cache_manager.py Adds operation counter tracking, error recording, and snapshot helper methods on the manager.
kvcached/integration/vllm/interfaces.py Registers vLLM managers in the pool registry and exposes runtime/pool snapshot helpers.
kvcached/integration/sglang/interfaces.py Registers SGLang managers in the pool registry and exposes runtime/pool snapshot helpers.
kvcached/integration/sglang/patches.py Passes stable pool_name labels when creating managers so collectors can distinguish pool types.

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

Comment thread kvcached/observability.py
Comment on lines +205 to +210
block_size_bytes = _int_attr(manager, "block_mem_size") or 0
bytes_per_block = block_size_bytes * num_layers * num_kv_buffers
available_blocks = int(manager.available_size())
allocated_blocks = int(manager._get_num_alloced_blocks())
reserved_blocks = len(getattr(manager, "reserved_blocks", []))

Comment on lines +276 to +280
def _record_operation_error(self, code: str, counter_name: str) -> None:
self._increment_operation_counter("operation_errors_total")
self._increment_operation_counter(counter_name)
self._last_error_code = code
self._last_error_timestamp_ns = time.time_ns()
@shipiyouniao
shipiyouniao force-pushed the feature/operational-observability branch from d9c1dbe to 4295979 Compare July 27, 2026 05:38
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