lmcache-cli 0.5.8rc2.dev0__py3-none-any.whl → 0.5.8rc4.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. lmcache/_version.py +3 -3
  2. lmcache/cli/commands/base.py +2 -2
  3. lmcache/cli/commands/bench/server_bench/client.py +1 -1
  4. lmcache/cli/commands/bench/server_bench/helpers.py +1 -1
  5. lmcache/cli/commands/coordinator.py +1 -1
  6. lmcache/cli/commands/describe.py +61 -38
  7. lmcache/cli/commands/query/_coordinator.py +156 -2
  8. lmcache/cli/commands/trace/replay_command.py +2 -2
  9. lmcache/cli/commands/trace/replay_events_command.py +1 -1
  10. lmcache/cli/metrics/__init__.py +7 -9
  11. lmcache/integration/atom/multi_process_adapter.py +1 -1
  12. lmcache/integration/sglang/unified_lmcache_mp_connector.py +18 -13
  13. lmcache/integration/tensorrt_llm/tensorrt_mp_adapter.py +1 -1
  14. lmcache/integration/vllm/kv_cache_group_edits.py +104 -40
  15. lmcache/integration/vllm/kv_cache_groups.py +138 -37
  16. lmcache/integration/vllm/lmcache_mp_connector.py +21 -25
  17. lmcache/integration/vllm/lmcache_mp_metadata.py +43 -19
  18. lmcache/integration/vllm/mp_lookup_state.py +1 -1
  19. lmcache/integration/vllm/vllm_multi_process_adapter.py +1 -1
  20. lmcache/lmcache_frontend/app.py +2 -4
  21. lmcache/lmcache_native.pyi +11 -0
  22. lmcache/sdk/batch.py +37 -15
  23. lmcache/sdk/context.py +145 -53
  24. lmcache/sdk/qringbuffer.py +6 -1
  25. lmcache/sdk/wrapper/__init__.py +2 -8
  26. lmcache/sdk/wrapper/ring_mapping.py +183 -83
  27. lmcache/sdk/wrapper/ring_transfer.py +205 -276
  28. lmcache/security/bearer.py +31 -0
  29. lmcache/security/http.py +1 -29
  30. lmcache/tools/cache_simulator/trace_analyze.py +1 -1
  31. lmcache/utils.py +3 -0
  32. lmcache/v1/client/async_engine_driven.py +1 -1
  33. lmcache/v1/client/heartbeat.py +1 -1
  34. lmcache/v1/client/kv_event_subscriber.py +1 -1
  35. lmcache/v1/client/transfer_context/base.py +5 -9
  36. lmcache/v1/client/transfer_context/inline.py +1 -1
  37. lmcache/v1/client/transfer_context/shm.py +2 -2
  38. lmcache/v1/client/transport/factory.py +1 -1
  39. lmcache/v1/client/transport/grpc_impl/__init__.py +1 -1
  40. lmcache/v1/client/transport/grpc_impl/auth.py +1 -1
  41. lmcache/v1/client/transport/grpc_impl/client.py +8 -35
  42. lmcache/v1/client/transport/zmq_impl/__init__.py +1 -1
  43. lmcache/v1/client/transport/zmq_impl/client.py +1 -1
  44. lmcache/v1/client/transport/zmq_impl/mq_client.py +3 -3
  45. lmcache/v1/client/worker_transfer.py +2 -2
  46. lmcache/v1/common/api.py +24 -0
  47. lmcache/v1/common/attn_window.py +30 -0
  48. lmcache/v1/common/errors.py +50 -0
  49. lmcache/v1/common/metrics/__init__.py +29 -0
  50. lmcache/{cli → v1/common}/metrics/formatter.py +1 -1
  51. lmcache/{cli → v1/common}/metrics/handler.py +4 -4
  52. lmcache/{cli → v1/common}/metrics/metrics.py +3 -3
  53. lmcache/v1/common/token_codec.py +35 -6
  54. lmcache/v1/common/utils.py +13 -0
  55. lmcache/v1/distributed/api.py +68 -28
  56. lmcache/v1/distributed/bitmap_ops/fold.py +1 -1
  57. lmcache/v1/distributed/config.py +87 -5
  58. lmcache/v1/distributed/internal_api.py +4 -1
  59. lmcache/v1/distributed/l1_manager/base.py +10 -3
  60. lmcache/v1/distributed/l1_manager/devdax.py +7 -2
  61. lmcache/v1/distributed/l1_manager/shadow.py +4 -1
  62. lmcache/v1/distributed/l2_adapters/aerospike_l2_adapter.py +23 -15
  63. lmcache/v1/distributed/l2_adapters/fs_native_l2_adapter.py +2 -2
  64. lmcache/v1/distributed/l2_adapters/nixl_native_l2_adapter.py +64 -10
  65. lmcache/v1/distributed/l2_adapters/p2p_l2_adapter.py +382 -24
  66. lmcache/v1/distributed/l2_adapters/valkey/worker_pool.py +10 -2
  67. lmcache/v1/distributed/memory_manager/shared_devdax_region.py +161 -0
  68. lmcache/v1/distributed/p2p.py +161 -0
  69. lmcache/v1/distributed/serde/aesgcm.py +54 -7
  70. lmcache/v1/distributed/shared_l1/__init__.py +2 -0
  71. lmcache/v1/distributed/shared_l1/visibility.py +58 -0
  72. lmcache/v1/distributed/storage_controllers/p2p_store_policy.py +117 -0
  73. lmcache/v1/distributed/storage_controllers/prefetch_controller.py +81 -76
  74. lmcache/v1/distributed/storage_controllers/prefetch_policy.py +16 -8
  75. lmcache/v1/distributed/storage_controllers/store_controller.py +155 -31
  76. lmcache/v1/distributed/storage_controllers/store_policy.py +21 -2
  77. lmcache/v1/distributed/storage_manager.py +27 -2
  78. lmcache/v1/distributed/transfer_channel/impl/mooncake_te_impl.py +1 -1
  79. lmcache/v1/distributed/transfer_channel/impl/nixl_impl.py +1 -1
  80. lmcache/v1/gpu_connector/gpu_ops.py +1 -12
  81. lmcache/v1/kv_layer_groups.py +8 -10
  82. lmcache/v1/memory_allocators/devdax_memory_allocator.py +20 -3
  83. lmcache/v1/memory_orchestrator/_codec.py +34 -1
  84. lmcache/v1/memory_orchestrator/_proto_gen/memory_orchestrator_pb2.pyi +30 -0
  85. lmcache/v1/memory_orchestrator/api.py +13 -0
  86. lmcache/v1/memory_orchestrator/client.py +38 -0
  87. lmcache/v1/memory_orchestrator/protos/memory_orchestrator.proto +25 -1
  88. lmcache/v1/memory_orchestrator/service.py +33 -0
  89. lmcache/v1/memory_orchestrator/state.py +69 -0
  90. lmcache/v1/mp_coordinator/api.py +3 -2
  91. lmcache/v1/mp_coordinator/cache_events.py +5 -2
  92. lmcache/v1/mp_coordinator/config.py +1 -1
  93. lmcache/v1/mp_coordinator/controllers/eviction_controller.py +2 -1
  94. lmcache/v1/mp_coordinator/controllers/eviction_http_api.py +44 -39
  95. lmcache/v1/mp_coordinator/controllers/prefetch_manager.py +3 -2
  96. lmcache/v1/mp_coordinator/http_auth.py +2 -4
  97. lmcache/v1/mp_coordinator/persistence/quiesce.py +1 -1
  98. lmcache/v1/mp_coordinator/schemas.py +109 -12
  99. lmcache/v1/mp_coordinator/utils/http.py +29 -0
  100. lmcache/v1/mp_coordinator/views/key_directory.py +38 -22
  101. lmcache/v1/mp_observability/errors.py +33 -39
  102. lmcache/v1/mp_observability/event_bus.py +10 -0
  103. lmcache/v1/mp_observability/subscribers/metrics/l2_failures.py +2 -3
  104. lmcache/v1/multiprocess/affinity_pool.py +39 -0
  105. lmcache/v1/multiprocess/cache_control/prefetch_service.py +2 -1
  106. lmcache/v1/multiprocess/config.py +95 -13
  107. lmcache/v1/multiprocess/custom_types.py +2 -70
  108. lmcache/v1/multiprocess/engine_context.py +97 -14
  109. lmcache/v1/multiprocess/engine_module.py +12 -0
  110. lmcache/v1/multiprocess/http_auth.py +2 -4
  111. lmcache/v1/multiprocess/http_server.py +81 -3
  112. lmcache/v1/multiprocess/modules/blend/fingerprint_eviction.py +200 -0
  113. lmcache/v1/multiprocess/modules/blend/lookup.py +2 -2
  114. lmcache/v1/multiprocess/modules/blend/matcher.py +48 -18
  115. lmcache/v1/multiprocess/modules/blend/module.py +10 -0
  116. lmcache/v1/multiprocess/modules/blend/retrieve.py +12 -7
  117. lmcache/v1/multiprocess/modules/blend/store.py +16 -1
  118. lmcache/v1/multiprocess/modules/engine_driven_transfer.py +7 -1
  119. lmcache/v1/multiprocess/modules/kv_events.py +22 -17
  120. lmcache/v1/multiprocess/modules/lmcache_driven_transfer.py +115 -22
  121. lmcache/v1/multiprocess/modules/lookup.py +47 -19
  122. lmcache/v1/multiprocess/modules/p2p_controller.py +118 -17
  123. lmcache/v1/multiprocess/object_group_transfer/__init__.py +42 -0
  124. lmcache/v1/multiprocess/object_group_transfer/direct_copy.py +264 -0
  125. lmcache/v1/multiprocess/object_group_transfer/dispatch.py +111 -0
  126. lmcache/v1/multiprocess/object_group_transfer/engines.py +138 -0
  127. lmcache/v1/multiprocess/object_group_transfer/gpu_dma.py +43 -0
  128. lmcache/v1/multiprocess/object_group_transfer/nic_dma.py +42 -0
  129. lmcache/v1/multiprocess/object_group_transfer/nvme_dma.py +42 -0
  130. lmcache/v1/multiprocess/object_group_transfer/planning.py +148 -0
  131. lmcache/v1/multiprocess/object_group_transfer/staged.py +413 -0
  132. lmcache/v1/multiprocess/object_group_transfer/unfull_chunk.py +338 -0
  133. lmcache/v1/multiprocess/plugin_modules/qstore.py +6 -1
  134. lmcache/v1/multiprocess/request_handler.py +10 -4
  135. lmcache/v1/multiprocess/rocm_host_event_wait.py +386 -0
  136. lmcache/v1/multiprocess/server.py +81 -35
  137. lmcache/v1/multiprocess/session.py +6 -2
  138. lmcache/v1/multiprocess/transport/base.py +1 -307
  139. lmcache/v1/multiprocess/transport/grpc_impl/aio_server.py +3 -1
  140. lmcache/v1/multiprocess/transport/grpc_impl/auth.py +1 -1
  141. lmcache/v1/multiprocess/transport/grpc_impl/native_server.py +5 -3
  142. lmcache/v1/multiprocess/transport/grpc_impl/server.py +3 -3
  143. lmcache/v1/multiprocess/transport/grpc_impl/server_base.py +10 -6
  144. lmcache/v1/multiprocess/transport/grpc_impl/server_builder.py +37 -4
  145. lmcache/v1/multiprocess/transport/grpc_impl/server_handlers.py +11 -6
  146. lmcache/v1/multiprocess/transport/zmq_impl/mq.py +1 -57
  147. lmcache/v1/platform/base/ipc_wire.py +6 -0
  148. lmcache/v1/platform/cache_context.py +4 -4
  149. lmcache/v1/platform/devices/cpu/cache_context.py +1 -1
  150. lmcache/v1/platform/devices/cuda/cache_context.py +1 -1
  151. lmcache/v1/platform/devices/cuda/ipc_wrapper.py +37 -25
  152. lmcache/v1/platform/devices/npu/cache_context.py +1 -1
  153. lmcache/v1/platform/devices/rocm/__init__.py +23 -0
  154. lmcache/v1/platform/devices/rocm/ipc_wrapper.py +36 -0
  155. lmcache/v1/platform/devices/rocm/vmm_bindings.py +173 -0
  156. lmcache/v1/transport/auth.py +1 -1
  157. lmcache/v1/transport/futures.py +1 -1
  158. lmcache/v1/transport/grpc/_proto_gen/p2p_service_pb2.pyi +28 -0
  159. lmcache/v1/transport/grpc/descriptors.py +13 -5
  160. lmcache/v1/transport/grpc/method_registry.py +7 -5
  161. lmcache/v1/transport/grpc/protos/p2p_service.proto +25 -0
  162. lmcache/v1/transport/grpc/utils.py +48 -0
  163. lmcache/v1/transport/request_client.py +294 -0
  164. lmcache/v1/transport/rpc.py +8 -7
  165. lmcache/v1/transport/zmq/codec.py +109 -0
  166. lmcache/v1/transport/zmq/wire.py +1 -3
  167. {lmcache_cli-0.5.8rc2.dev0.dist-info → lmcache_cli-0.5.8rc4.dev0.dist-info}/METADATA +1 -1
  168. {lmcache_cli-0.5.8rc2.dev0.dist-info → lmcache_cli-0.5.8rc4.dev0.dist-info}/RECORD +173 -147
  169. lmcache/v1/multiprocess/object_group_transfer.py +0 -1091
  170. /lmcache/{cli → v1/common}/metrics/section.py +0 -0
  171. {lmcache_cli-0.5.8rc2.dev0.dist-info → lmcache_cli-0.5.8rc4.dev0.dist-info}/WHEEL +0 -0
  172. {lmcache_cli-0.5.8rc2.dev0.dist-info → lmcache_cli-0.5.8rc4.dev0.dist-info}/entry_points.txt +0 -0
  173. {lmcache_cli-0.5.8rc2.dev0.dist-info → lmcache_cli-0.5.8rc4.dev0.dist-info}/licenses/LICENSE +0 -0
  174. {lmcache_cli-0.5.8rc2.dev0.dist-info → lmcache_cli-0.5.8rc4.dev0.dist-info}/top_level.txt +0 -0
lmcache/_version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.5.8rc2.dev0'
22
- __version_tuple__ = version_tuple = (0, 5, 8, 'rc2', 'dev0')
21
+ __version__ = version = '0.5.8rc4.dev0'
22
+ __version_tuple__ = version_tuple = (0, 5, 8, 'rc4', 'dev0')
23
23
 
24
- __commit_id__ = commit_id = 'g6a316c3e0'
24
+ __commit_id__ = commit_id = 'g651617efc'
@@ -11,13 +11,13 @@ import argparse
11
11
  import sys
12
12
 
13
13
  # First Party
14
- from lmcache.cli.metrics import (
14
+ from lmcache.logging import init_logger
15
+ from lmcache.v1.common.metrics import (
15
16
  FileHandler,
16
17
  Metrics,
17
18
  StreamHandler,
18
19
  get_formatter,
19
20
  )
20
- from lmcache.logging import init_logger
21
21
 
22
22
  logger = init_logger(__name__)
23
23
 
@@ -59,7 +59,7 @@ from lmcache.v1.kv_layer_groups import (
59
59
  if TYPE_CHECKING:
60
60
  # First Party
61
61
  from lmcache.v1.client.worker_transfer import IPCEvent, TransferContext
62
- from lmcache.v1.multiprocess.transport.base import RequestClient
62
+ from lmcache.v1.transport.request_client import RequestClient
63
63
 
64
64
 
65
65
  @dataclass(frozen=True)
@@ -13,8 +13,8 @@ import urllib.request
13
13
 
14
14
  # First Party
15
15
  from lmcache.v1.common.custom_types import IPCCacheServerKey
16
- from lmcache.v1.multiprocess.transport.base import RequestClient
17
16
  from lmcache.v1.transport.futures import DeviceMessagingFuture, MessagingFuture
17
+ from lmcache.v1.transport.request_client import RequestClient
18
18
 
19
19
  # ------------------------------------------------------------------ #
20
20
  # Constants #
@@ -51,7 +51,7 @@ class CoordinatorCommand(BaseCommand):
51
51
  "--host",
52
52
  type=str,
53
53
  default=None,
54
- help="Host the coordinator's HTTP server binds to (default: 0.0.0.0).",
54
+ help="Host the coordinator's HTTP server binds to (default: 127.0.0.1).",
55
55
  )
56
56
  parser.add_argument(
57
57
  "--port",
@@ -29,7 +29,7 @@ from lmcache.cli.http import (
29
29
 
30
30
  if TYPE_CHECKING:
31
31
  # First Party
32
- from lmcache.cli.metrics import Metrics
32
+ from lmcache.v1.common.metrics import Metrics
33
33
 
34
34
  # -------------------------------------------------------------------
35
35
  # Shared helpers
@@ -127,6 +127,12 @@ def fmt_bytes(n: int) -> str:
127
127
  return f"{n} B"
128
128
 
129
129
 
130
+ def fmt_l1_used(used_bytes: int, total_bytes: int) -> str:
131
+ """Format L1 usage as GB with its share of capacity, e.g. ``0.33 (8.3%)``."""
132
+ pct = used_bytes / total_bytes * 100 if total_bytes > 0 else 0.0
133
+ return f"{used_bytes / 1024**3:.2f} ({pct:.1f}%)"
134
+
135
+
130
136
  def fmt_health(is_healthy: object) -> str | None:
131
137
  """Format a boolean health flag as ``'OK'`` / ``'UNHEALTHY'``."""
132
138
  if is_healthy is None:
@@ -183,51 +189,43 @@ class KVCacheDescriber:
183
189
  self.metrics.add("chunk_size", "Chunk size", self.data.get("chunk_size"))
184
190
 
185
191
  def add_l1_storage(self) -> None:
186
- """L1 cache capacity, usage, eviction, and object count."""
187
- total_bytes = safe_get(
188
- self.data, "storage_manager", "l1_manager", "memory_total_bytes"
189
- )
190
- if total_bytes is not None:
191
- self.metrics.add(
192
- "l1_capacity_gb",
193
- "L1 capacity (GB)",
194
- round(total_bytes / (1024**3), 2),
195
- )
196
- else:
197
- self.metrics.add("l1_capacity_gb", "L1 capacity (GB)", None)
192
+ """L1 totals across all L1s, plus one section per L1 when there are several.
198
193
 
199
- used_bytes = safe_get(
200
- self.data, "storage_manager", "l1_manager", "memory_used_bytes"
201
- )
202
- usage_ratio = safe_get(
203
- self.data, "storage_manager", "l1_manager", "memory_usage_ratio"
204
- )
205
- if used_bytes is not None and usage_ratio is not None:
206
- gb = used_bytes / (1024**3)
207
- pct = usage_ratio * 100
208
- self.metrics.add("l1_used_gb", "L1 used (GB)", f"{gb:.2f} ({pct:.1f}%)")
209
- else:
210
- self.metrics.add("l1_used_gb", "L1 used (GB)", None)
211
-
212
- self.metrics.add(
213
- "eviction_policy",
214
- "Eviction policy",
215
- safe_get(
216
- self.data,
217
- "storage_manager",
218
- "eviction_controller",
219
- "eviction_policy",
220
- ),
194
+ Reads the per-tag ``l1_managers`` and ``l1_eviction_controllers`` maps,
195
+ which ``/status`` sends for any number of L1s. The single-L1 keys
196
+ (``l1_manager``, ``l1_eviction_controller``) are omitted on multi-L1
197
+ servers, so they cannot describe every deployment.
198
+ """
199
+ managers = safe_get(self.data, "storage_manager", "l1_managers") or {}
200
+ evictions = (
201
+ safe_get(self.data, "storage_manager", "l1_eviction_controllers") or {}
221
202
  )
203
+ capacity_gb: float | None = None
204
+ used_gb: str | None = None
205
+ objects: int | None = None
206
+ if managers:
207
+ total = sum(m["memory_total_bytes"] for m in managers.values())
208
+ used = sum(m["memory_used_bytes"] for m in managers.values())
209
+ capacity_gb = round(total / (1024**3), 2)
210
+ used_gb = fmt_l1_used(used, total)
211
+ objects = sum(m["total_object_count"] for m in managers.values())
212
+ # Each L1 may set its own policy; list each distinct one once.
213
+ policies = dict.fromkeys(e["eviction_policy"] for e in evictions.values())
214
+
215
+ self.metrics.add("l1_capacity_gb", "L1 capacity (GB)", capacity_gb)
216
+ self.metrics.add("l1_used_gb", "L1 used (GB)", used_gb)
222
217
  self.metrics.add(
223
- "cached_objects",
224
- "Cached objects",
225
- safe_get(self.data, "storage_manager", "l1_manager", "total_object_count"),
218
+ "eviction_policy", "Eviction policy", ", ".join(policies) or None
226
219
  )
220
+ self.metrics.add("cached_objects", "Cached objects", objects)
227
221
  self.metrics.add(
228
222
  "active_sessions", "Active sessions", self.data.get("active_sessions")
229
223
  )
230
224
 
225
+ if len(managers) > 1:
226
+ for tag, manager in managers.items():
227
+ self._add_l1_section(tag, manager, evictions[tag])
228
+
231
229
  def add_models(self) -> None:
232
230
  """Per-model KV cache layout sections.
233
231
 
@@ -355,6 +353,31 @@ class KVCacheDescriber:
355
353
  f"{pool_used} / {pool_size} ({pct:.1f}%)",
356
354
  )
357
355
 
356
+ def _add_l1_section(self, tag: str, manager: dict, eviction: dict) -> None:
357
+ """Emit one ``l1_managers`` list section for the L1 tagged *tag*.
358
+
359
+ Args:
360
+ tag: The L1's configured tag.
361
+ manager: That L1's entry in ``storage_manager.l1_managers``.
362
+ eviction: That L1's entry in ``storage_manager.l1_eviction_controllers``.
363
+ """
364
+ self.metrics.add_list_section("l1_managers", f"l1_{tag}", f"L1: {tag}")
365
+ sec = self.metrics[f"l1_{tag}"]
366
+ sec.add("tag", "Tag", tag)
367
+ sec.add("backend", "Backend", manager["backend"])
368
+ sec.add(
369
+ "capacity_gb",
370
+ "Capacity (GB)",
371
+ round(manager["memory_total_bytes"] / (1024**3), 2),
372
+ )
373
+ sec.add(
374
+ "used_gb",
375
+ "Used (GB)",
376
+ fmt_l1_used(manager["memory_used_bytes"], manager["memory_total_bytes"]),
377
+ )
378
+ sec.add("cached_objects", "Cached objects", manager["total_object_count"])
379
+ sec.add("eviction_policy", "Eviction policy", eviction["eviction_policy"])
380
+
358
381
 
359
382
  # -------------------------------------------------------------------
360
383
  # Engine describer
@@ -3,7 +3,7 @@
3
3
 
4
4
  One entry per queryable coordinator endpoint. Each knows its path, which
5
5
  extra arguments it needs, and how to shape the reply into a
6
- :class:`~lmcache.cli.metrics.Metrics` report -- so the terminal gets an
6
+ :class:`~lmcache.v1.common.metrics.Metrics` report -- so the terminal gets an
7
7
  aligned table and ``--format json`` gets the same data structurally.
8
8
 
9
9
  Only reads live here. The coordinator's mutating routes (``POST /events``,
@@ -28,8 +28,8 @@ import urllib.request
28
28
  from lmcache.cli.commands.describe import fmt_bytes
29
29
  from lmcache.cli.commands.quota._helpers import escape_salt
30
30
  from lmcache.cli.http import normalize_url as normalize_url
31
- from lmcache.cli.metrics import Metrics
32
31
  from lmcache.logging import init_logger
32
+ from lmcache.v1.common.metrics import Metrics
33
33
 
34
34
  logger = init_logger(__name__)
35
35
 
@@ -262,6 +262,144 @@ def _render_prefetch(body: Any, metrics: Metrics) -> None:
262
262
  metrics.add(key, key.replace("_", " ").capitalize(), value)
263
263
 
264
264
 
265
+ def _render_status(body: Any, metrics: Metrics) -> None:
266
+ """The coordinator's debugging snapshot, one block per component.
267
+
268
+ Tables print without their label, so each one's first column names
269
+ what its rows are.
270
+ """
271
+ source = body["event_source"]
272
+ section = metrics.add_section("event_source", "Event source")
273
+ section.add("source_name", "Source", source["source_name"])
274
+ section.add("replay_capability", "Replay", source["replay_capability"])
275
+ # Only the Kafka source reports what it has read.
276
+ reads = source.get("reads")
277
+ if reads is not None:
278
+ for key, label in (
279
+ ("records_applied", "Records applied"),
280
+ ("records_undecodable", "Records undecodable"),
281
+ ("records_failed", "Records failed"),
282
+ ("partitions_assigned", "Partitions assigned"),
283
+ ):
284
+ section.add(key, label, reads[key])
285
+ table = metrics.add_table(
286
+ "partitions",
287
+ "Partitions",
288
+ ("partition", "partition"),
289
+ ("next_offset", "next offset"),
290
+ ("unread_records", "unread"),
291
+ )
292
+ partitions = set(reads["next_offsets"]) | set(reads["unread_records"])
293
+ for partition in sorted(partitions, key=int):
294
+ table.add_row(
295
+ partition=partition,
296
+ next_offset=reads["next_offsets"].get(partition),
297
+ unread_records=reads["unread_records"].get(partition),
298
+ )
299
+
300
+ ingest = body["ingest"]
301
+ section = metrics.add_section("ingest", "Ingest")
302
+ for key, label in (
303
+ ("batches_applied", "Batches applied"),
304
+ ("batches_duplicate", "Batches duplicate"),
305
+ ("batches_stale", "Batches stale"),
306
+ ("batches_missing", "Batches missing"),
307
+ ("events_dropped", "Events dropped by servers"),
308
+ ):
309
+ section.add(key, label, ingest[key])
310
+ table = metrics.add_table(
311
+ "streams",
312
+ "Streams",
313
+ ("server", "server"),
314
+ ("incarnation", "incarnation"),
315
+ ("last_seq", "last seq"),
316
+ ("view", "view"),
317
+ ("missing_batches", "missing"),
318
+ ("events_dropped", "dropped"),
319
+ ("seconds_since_last_event", "since event s"),
320
+ ("event_delivery_delay_seconds", "delivery delay s"),
321
+ )
322
+ for server, stream in sorted(ingest["streams"].items()):
323
+ table.add_row(
324
+ server=server,
325
+ incarnation=stream["incarnation"],
326
+ last_seq=stream["last_seq"],
327
+ view="incomplete" if stream["gap_detected"] else "complete",
328
+ missing_batches=stream["missing_batches"],
329
+ events_dropped=stream["events_dropped"],
330
+ seconds_since_last_event=stream["seconds_since_last_event"],
331
+ event_delivery_delay_seconds=stream["event_delivery_delay_seconds"],
332
+ )
333
+
334
+ table = metrics.add_table(
335
+ "consumers",
336
+ "Consumers",
337
+ ("consumer", "consumer"),
338
+ ("batches_delivered", "delivered"),
339
+ ("average_apply_ms", "avg apply ms"),
340
+ ("consume_failures", "consume failures"),
341
+ ("fence_failures", "fence failures"),
342
+ )
343
+ for name, consumer in sorted(body["consumers"].items()):
344
+ delivered = consumer["batches_delivered"]
345
+ table.add_row(
346
+ consumer=name,
347
+ batches_delivered=delivered,
348
+ average_apply_ms=(
349
+ consumer["apply_seconds"] / delivered * 1000 if delivered else None
350
+ ),
351
+ consume_failures=consumer["consume_failures"],
352
+ fence_failures=consumer["fence_failures"],
353
+ )
354
+
355
+ table = metrics.add_table(
356
+ "heartbeats",
357
+ "Heartbeats",
358
+ ("server", "registered server"),
359
+ ("seconds_since_heartbeat", "since heartbeat s"),
360
+ )
361
+ for server, age in sorted(body["registry"]["seconds_since_heartbeat"].items()):
362
+ table.add_row(server=server, seconds_since_heartbeat=age)
363
+
364
+ table = metrics.add_table(
365
+ "controllers",
366
+ "Controllers",
367
+ ("controller", "controller"),
368
+ ("started", "started"),
369
+ )
370
+ for name, started in sorted(body["controllers"].items()):
371
+ table.add_row(controller=name, started="yes" if started else "no")
372
+
373
+ # The error is last: it is free text of any length, and as the final
374
+ # column it cannot push the others out of line.
375
+ table = metrics.add_table(
376
+ "background_loops",
377
+ "Background loops",
378
+ ("loop", "loop"),
379
+ ("interval_seconds", "every s"),
380
+ ("passes_ok", "ok"),
381
+ ("passes_failed", "failed"),
382
+ ("seconds_since_last_success", "since success s"),
383
+ ("failing", "failing"),
384
+ ("last_error", "last error"),
385
+ )
386
+ for name, loop in sorted(body["background_loops"].items()):
387
+ table.add_row(
388
+ loop=name,
389
+ interval_seconds=loop["interval_seconds"],
390
+ passes_ok=loop["passes_ok"],
391
+ passes_failed=loop["passes_failed"],
392
+ seconds_since_last_success=loop["seconds_since_last_success"],
393
+ failing="yes" if _still_failing(loop) else "no",
394
+ last_error=loop["last_error"] or "--",
395
+ )
396
+
397
+ section = metrics.add_section("event_loop", "Event loop")
398
+ section.add(
399
+ "blocked_seconds", "Blocked (s, total)", body["event_loop"]["blocked_seconds"]
400
+ )
401
+
402
+
265
403
  @dataclass(frozen=True)
266
404
  class CoordinatorApi:
267
405
  """One queryable coordinator endpoint.
@@ -330,9 +468,25 @@ APIS: dict[str, CoordinatorApi] = {
330
468
  render=_render_prefetch,
331
469
  requires=("instance", "request_id"),
332
470
  ),
471
+ "status": CoordinatorApi(
472
+ summary="debugging snapshot: ingest, consumers, loops, controllers",
473
+ path=lambda a: "/status",
474
+ render=_render_status,
475
+ ),
333
476
  "metrics": CoordinatorApi(
334
477
  summary="Prometheus metrics, verbatim",
335
478
  path=lambda a: "/metrics",
336
479
  raw=True,
337
480
  ),
338
481
  }
482
+
483
+
484
+ def _still_failing(loop: dict[str, Any]) -> bool:
485
+ """Whether a loop's latest pass failed.
486
+
487
+ A later success leaves ``last_error`` in place, so the error alone does
488
+ not say the loop is failing now; its time against the last success does.
489
+ """
490
+ failed_at = loop["last_error_timestamp"]
491
+ succeeded_at = loop["last_success_timestamp"]
492
+ return failed_at is not None and (succeeded_at is None or failed_at > succeeded_at)
@@ -13,8 +13,8 @@ import sys
13
13
 
14
14
  # First Party
15
15
  from lmcache.cli.commands.base import BaseCommand
16
- from lmcache.cli.metrics import Metrics, StreamHandler, get_formatter
17
16
  from lmcache.logging import init_logger
17
+ from lmcache.v1.common.metrics import Metrics, StreamHandler, get_formatter
18
18
 
19
19
  logger = init_logger(__name__)
20
20
 
@@ -110,7 +110,7 @@ def run_trace_replay(args: argparse.Namespace) -> None:
110
110
  * Aggregated per-qualname summary: CSV (unless ``--no-csv``)
111
111
  and JSON (with ``--json``) written under ``--output-dir``.
112
112
  * Terminal metrics table (unless ``--quiet``) using the shared
113
- :class:`~lmcache.cli.metrics.Metrics` renderer.
113
+ :class:`~lmcache.v1.common.metrics.Metrics` renderer.
114
114
 
115
115
  Args:
116
116
  args: Parsed CLI arguments.
@@ -12,8 +12,8 @@ import sys
12
12
 
13
13
  # First Party
14
14
  from lmcache.cli.commands.base import BaseCommand
15
- from lmcache.cli.metrics import Metrics, StreamHandler, get_formatter
16
15
  from lmcache.logging import init_logger
16
+ from lmcache.v1.common.metrics import Metrics, StreamHandler, get_formatter
17
17
 
18
18
  logger = init_logger(__name__)
19
19
 
@@ -1,20 +1,18 @@
1
1
  # SPDX-License-Identifier: Apache-2.0
2
- """Metrics package — collector, handlers, and formatters."""
2
+ """Compatibility path for :mod:`lmcache.v1.common.metrics`."""
3
3
 
4
4
  # First Party
5
- from lmcache.cli.metrics.formatter import (
5
+ from lmcache.v1.common.metrics import (
6
+ FileHandler,
6
7
  JsonFormatter,
8
+ Metrics,
7
9
  MetricsFormatter,
8
- TerminalFormatter,
9
- get_formatter,
10
- )
11
- from lmcache.cli.metrics.handler import (
12
- FileHandler,
13
10
  MetricsHandler,
11
+ Section,
14
12
  StreamHandler,
13
+ TerminalFormatter,
14
+ get_formatter,
15
15
  )
16
- from lmcache.cli.metrics.metrics import Metrics
17
- from lmcache.cli.metrics.section import Section
18
16
 
19
17
  __all__ = [
20
18
  "FileHandler",
@@ -28,8 +28,8 @@ from lmcache.v1.common.group_view import (
28
28
  EngineGroupInfo,
29
29
  expand_engine_block_ids,
30
30
  )
31
- from lmcache.v1.multiprocess.transport.base import RequestClient
32
31
  from lmcache.v1.transport.futures import MessagingFuture
32
+ from lmcache.v1.transport.request_client import RequestClient
33
33
 
34
34
  logger = init_logger(__name__)
35
35
 
@@ -241,14 +241,6 @@ class UnifiedLMCacheMPConnector:
241
241
  self._mp_transfer_mode = config.get_extra_config_value(
242
242
  "lmcache.mp.mp_transfer_mode", None
243
243
  )
244
- if any(
245
- group.recurrent_state or group.sliding_window_size >= 0
246
- for group in wire_groups
247
- ):
248
- logger.warning(
249
- "LMCache sparse SWA/recurrent groups require the LMCache MP "
250
- "server to be started with --separate-object-groups."
251
- )
252
244
 
253
245
  self.model_name = model_config.model_path
254
246
  (
@@ -303,6 +295,7 @@ class UnifiedLMCacheMPConnector:
303
295
  self._control_futures: list[Any] = []
304
296
  self._heartbeat: Optional[HeartbeatThread] = None
305
297
  self._heartbeat_lock = threading.Lock()
298
+ self._needs_store_progress_reset = False
306
299
 
307
300
  self.chunk_size = self._get_chunk_size()
308
301
  if self.chunk_size <= 0 or any(
@@ -450,7 +443,10 @@ class UnifiedLMCacheMPConnector:
450
443
  def ready_prefix_count(
451
444
  self, operations: Sequence[LMCacheLoadOperation | LMCacheStoreOperation]
452
445
  ) -> int:
453
- """Return the cross-rank count of ready leading operations."""
446
+ """Return the cross-rank count of ready leading operations.
447
+
448
+ Synchronize store progress resets across TP/PP ranks.
449
+ """
454
450
  count = 0
455
451
  for operation in operations:
456
452
  try:
@@ -464,9 +460,16 @@ class UnifiedLMCacheMPConnector:
464
460
  if not ready:
465
461
  break
466
462
  count += 1
467
- tensor = torch.tensor([count], dtype=torch.int64, device="cpu")
463
+ with self._heartbeat_lock:
464
+ keep_store_progress = not self._needs_store_progress_reset
465
+ self._needs_store_progress_reset = False
466
+ tensor = torch.tensor(
467
+ [count, int(keep_store_progress)], dtype=torch.int64, device="cpu"
468
+ )
468
469
  self._parallel_all_reduce(tensor, dist.ReduceOp.MIN)
469
- return int(tensor.item())
470
+ if not tensor[1].item():
471
+ self._store_submitted_tokens.clear()
472
+ return int(tensor[0].item())
470
473
 
471
474
  def _sync_leader_int(self, value: int) -> int:
472
475
  tensor = torch.tensor([value], dtype=torch.int64, device="cpu")
@@ -587,7 +590,7 @@ class UnifiedLMCacheMPConnector:
587
590
  heartbeat.start()
588
591
 
589
592
  def _reregister_kv_cache_after_recovery(self) -> bool:
590
- """Re-register KV tensors before publishing a recovered server."""
593
+ """Re-register KV tensors and request a store progress reset."""
591
594
  heartbeat = self._heartbeat
592
595
  if (
593
596
  self._closed
@@ -606,7 +609,9 @@ class UnifiedLMCacheMPConnector:
606
609
  if not registered:
607
610
  return False
608
611
  # A restarted server has no record of the previously stored prefixes.
609
- self._store_submitted_tokens.clear()
612
+ # Reset store progress together to keep collective calls aligned.
613
+ with self._heartbeat_lock:
614
+ self._needs_store_progress_reset = True
610
615
  logger.warning("Re-registered SGLang KV tensors after LMCache recovery")
611
616
  return True
612
617
 
@@ -38,13 +38,13 @@ from lmcache.utils import EngineType
38
38
  from lmcache.v1.client.transport.factory import RequestClientFactory
39
39
  from lmcache.v1.common.custom_types import IPCCacheServerKey
40
40
  from lmcache.v1.common.kv_format.types import LayoutHints
41
- from lmcache.v1.multiprocess.transport.base import RequestClient
42
41
  from lmcache.v1.platform.base.event_ipc import (
43
42
  EventIPCBackend,
44
43
  get_event_ipc_backend,
45
44
  )
46
45
  from lmcache.v1.platform.base.ipc_wrapper import KVCache
47
46
  from lmcache.v1.platform.devices.cuda.ipc_wrapper import RawCudaIPCWrapper
47
+ from lmcache.v1.transport.request_client import RequestClient
48
48
 
49
49
  logger = init_logger(__name__)
50
50