This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
PegaFlow is a high-performance KV cache transfer system for LLM inference, designed to work with vLLM. It provides RDMA-first, high-bandwidth transport optimized for GPU-to-CPU KV cache offloading and loading.
cargo build # Debug build
cargo build --release # Release build
cargo test # Run Rust testsOn CUDA 13 dev machines, pass --no-default-features --features cuda-13,rdma to cargo test/cargo clippy (default cuda-12 can fail with missing libcudart symbols).
Run all CI checks locally before committing:
./scripts/check.sh # Run fmt, typos, clippy, and cargo check| Gate | When to run | Command | Notes |
|---|---|---|---|
| Default unit | Every Python PR before review | cd python && uv run --extra test pytest |
Must not start vLLM, pegaflow-server, or GPU runtime. Collection still imports deselected files, so top-level imports must be in python[test] or moved behind fixtures. |
| Source-only default | CI and dependency-boundary checks | cd python && uv run --isolated --no-project --with pytest --with numpy --with 'requests>=2.26.0' pytest |
Proves default gate does not need torch, vLLM, CUDA, native extension build, or a running server. |
| Integration | Server/native/client/session lifecycle changes | cd python && uv run --extra test pytest -m integration |
Requires built native extension, server binary, and GPU where the test uses CUDA IPC. |
| vLLM correctness E2E | Python test gates, vLLM connector, connector-visible cache semantics, save/load, query planning, or release-confidence changes | cd python && uv run --extra test pytest -m e2e tests/test_vllm_e2e_correctness.py --model /data/models/Qwen3-4B --max-model-len 4096 |
Merge-before gate: code author runs it, reviewer reruns it on the GPU machine. |
| Stress | Warm-hit pressure, pending unpin, scheduler/cache concurrency | cd python && uv run --extra test pytest -m stress tests/test_vllm_warm_hit_stress.py --model /data/models/Qwen3-4B --max-model-len 2048 |
Targeted single-GPU evidence, not default PR feedback. |
| Release smoke | Published wheel/image, loader path, installed console script, CUDA runtime | See python/tests/README.md |
Validates final installed artifact, not the source checkout. |
Do not default to running all of python/tests. Current project taste is uv + pytest markers for Python and Cargo/CI for Rust; do not add an xtask wrapper until the gate contract is stable and repeated execution is the real bottleneck.
cargo bench --bench pinned_copy
cargo bench --bench uds_latency-
pegaflow-common (Rust): Shared lightweight utilities
logging.rs: Unified log initialization (logforth-based)numa.rs: NUMA topology detection and CPU affinity utilities- Depended on by all other crates to avoid heavy transitive dependencies
-
pegaflow-core (Rust): Core storage engine
PegaEngine: Main engine managing GPU workers and KV cache storagestorage/: Modular block storage enginemod.rs:StorageEngine— aggregates allocator, read cache, prefetch, write pipeline, SSD store, RDMA fetchread_cache.rs: Pin/unpin/consume operations on sealed blocksprefetch.rs: Per-request SSD/RDMA prefetch state machinetransfer_lock.rs: Transfer lock manager — prevents LRU eviction during RDMA transferwrite_path.rs: Async insert worker thread for batched writes
backing/: SSD backing storessd.rs:SsdBackingStorecoordinatorssd_cache.rs: SSD-backed block storageuring.rs: io_uring async I/O
pinned_pool.rs/pinned_mem.rs: NUMA-aware pinned memory allocatortransfer.rs: GPU-CPU transfer operations via CUDAcache.rs: LRU cache for blocksgpu_worker.rs: Per-GPU worker handling async operationsinternode/: Cross-node communicationmetaserver_client.rs: MetaServer registration, removal, query, and node heartbeat
-
pegaflow-proto (Rust): Protobuf definitions
- gRPC service definitions built with prost/tonic
-
pegaflow-server (Rust): gRPC server
service.rs: Tonic gRPC service implementationregistry.rs: Instance/worker registrationhttp_server.rs: HTTP health check and Prometheus metrics endpointbin/pegaflow-router.rs: P/D request router (coordinates P/D nodes; PegaFlow itself is a KV store)
-
pegaflow-metaserver (Rust): Cross-node block hash registry
service.rs: gRPC MetaServer service (insert/query block hashes)store.rs: Multi-owner block hash store with TTL sweep (backed by DashMap)- Used for multi-node KV cache coordination — each pegaflow-server registers its block hashes here
-
pegaflow-transfer (Rust): RDMA-based inter-node memory transfer engine
engine.rs:MooncakeTransferEngine— Mooncake-compatible API for one-sided RDMA READ/WRITEsideway_backend.rs: UD control plane + RC data plane with per-peer sessionsrdma_topo.rs: NUMA-aware topology detection (GPUs, RDMA NICs, CPUs)- CLI tools:
pegaflow_topo_cli(topology display),pegaflow_cpu_bench(RDMA benchmark)
-
python/ (Rust/PyO3 + Python): Python package (
pegaflow-llmon PyPI)src/lib.rs: PyO3 bindings exposingPegaEngineand gRPC clientpegaflow/connector/: vLLM v1 KV connector (scheduler + worker split)pegaflow/ipc_wrapper.py: CUDA IPC handle wrapper- CLI binaries:
pegaflow-server,pegaflow-metaserver(installed via pip)
vLLM Worker <--gRPC--> PegaEngine Server <--CUDA IPC--> GPU Memory
|
Pinned CPU Memory (KV cache storage)
/ \
SSD Cache (io_uring) Remote Node (RDMA READ)
|
MetaServer (block discovery)
- Instance: A model instance with specific num_layers and tp_size
- Worker: A tensor-parallel rank within an instance
- Block: Unit of KV cache storage, identified by content hash
- Split Storage: K and V segments stored separately for efficient batching
- Use English in comments
- Use
.venvfor Python virtual environment - KV cache uses layer-first layout: all K blocks contiguous, followed by all V blocks
- Visibility: Prefer
fn(private) >pub(crate)>pub; use the minimal necessary visibility - Prefer
NonNullover*mutin unsafe code
- Use native generics (
list,dict,set,tuple) instead oftyping.List,typing.Dict, etc. - Use PEP 604 union syntax (
X | Y,X | None) instead oftyping.Union,typing.Optional - Logging: use
%sformatting (logger.info("x=%s", x)) instead of f-strings to avoid evaluation overhead
- Do not add tests just for the sake of adding tests.
- Before adding or keeping a test, answer: would skipping this test materially reduce confidence to merge a PR in its trigger area? If not, delete it or keep it out of routine gates.
- Merge tests that protect the same contract; prefer table-driven cases with clear ids over copy-pasted methods.
- Delete tests with no clear consumer. A test that no dev, reviewer, CI job, release gate, or scheduled job uses is noise.
- Default Python tests must be dev friendly: fast, stable, no GPU, no vLLM, no native extension build, and failure messages that point to a Python contract.
- Heavy tests must declare their trigger: integration, e2e, stress, or release smoke. A heavy test without a trigger should not live in the main pytest surface.
- Stub and mock tests are allowed only for local contracts and must not shadow real runtime modules during integration/e2e collection.
- Prefer integration tests when they prove a real boundary that units cannot. Prefer units when they give faster, clearer feedback for local connector state machines.
- We have a strict version handshake (
CARGO_PKG_VERSIONexact match at registration), so do NOT design for backward compatibility with older clients or older stored formats — bump the version and break freely. - SSD cache is ephemeral: it is wiped on restart. Do NOT add migration, on-disk versioning, or cross-version SSD compatibility handling.
PEGAFLOW_ENGINE_ENDPOINT: gRPC endpoint (default:127.0.0.1:50055)PEGAFLOW_INSTANCE_ID: Override instance IDRUST_LOG: Control Rust logging (e.g.,info,pegaflow_core=debug,pegaflow_server=debug)
- We use commitizen commit message format.
- Do not commit directly to the master branch; create a feat/fix/chore/style/refactor/ci/... branch first.
pegaflow-common/src/logging.rs: Unified log initializationpegaflow-common/src/numa.rs: NUMA topology detection and CPU affinitypegaflow-core/src/lib.rs: Main PegaEngine implementationpegaflow-core/src/storage/mod.rs: StorageEngine (allocator, read cache, prefetch, write pipeline, RDMA fetch)pegaflow-core/src/storage/read_cache.rs: Pin/unpin/consume operationspegaflow-core/src/storage/prefetch.rs: SSD/RDMA prefetch state machinepegaflow-core/src/storage/transfer_lock.rs: Transfer lock manager for RDMA transferspegaflow-core/src/storage/write_path.rs: Async insert worker threadpegaflow-core/src/backing/ssd.rs: SSD backing store coordinatorpegaflow-core/src/internode/metaserver_client.rs: MetaServer registration, query, and node heartbeatpegaflow-server/src/service.rs: gRPC service implementationpegaflow-metaserver/src/lib.rs: MetaServer entry point and CLIpegaflow-metaserver/src/service.rs: MetaServer gRPC servicepegaflow-metaserver/src/store.rs: Block hash store (LRU + TTL)pegaflow-transfer/src/engine.rs: RDMA transfer engine (MooncakeTransferEngine)python/src/lib.rs: PyO3 bindings (Rust side)python/pegaflow/pegaflow.pyi: Type stubs for PyO3 bindingspython/pegaflow/connector/scheduler.py: vLLM scheduler-side connectorpython/pegaflow/connector/worker.py: vLLM worker-side connector