Skip to content

[Conductor] Add ZMQ event client with replay and reconnect - #4159

Merged
Chase-Rong merged 4 commits into
kvcache-ai:mainfrom
yejj710:conductor_zmq
Sep 21, 2026
Merged

Chase-Rong merged 4 commits into
kvcache-ai:mainfrom
yejj710:conductor_zmq

Conversation

@yejj710

@yejj710 yejj710 commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Add a reusable ZMQ client for Mooncake Conductor KV-event publishers.

The client:

  • Consumes multipart ZMQ messages containing topic, sequence number, and MessagePack payload.
  • Routes vLLM, Mooncake, and SGLang payloads through the corresponding event decoders.
  • Supports optional replay requests for vLLM and SGLang publishers.
  • Detects sequence gaps, tracks dropped events, reconnects after failures, and resumes pending replay ranges.
  • Provides an EventHandler interface for decoded batch dispatch.
  • Supports idempotent shutdown and configurable polling, replay, reconnect, and receive HWM settings.
  • Adds cppzmq/libzmq discovery and linking for different packaging layouts.
  • Adds unit coverage for connection lifecycle, multipart handling, routing, replay, reconnect, and sequence-gap behavior.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

build:

cd ~/Mooncake

cmake -S . -B build-conductor -G Ninja \
  -DWITH_CONDUCTOR=ON \
  -DWITH_TE=OFF \
  -DWITH_STORE=OFF \
  -DWITH_P2P_STORE=OFF \
  -DWITH_STORE_RUST=OFF \
  -DUSE_ETCD=OFF \
  -DSTORE_USE_ETCD=OFF \
  -DBUILD_EXAMPLES=OFF \
  -DBUILD_BENCHMARK=OFF \
  -DBUILD_UNIT_TESTS=ON \
  -DCMAKE_BUILD_TYPE=RelWithDebInfo

cmake --build build-conductor \
  --target conductor_test \
  --parallel 4

./build-conductor/mooncake-conductor/tests/conductor_test

Test results:
image

  • Unit tests pass — not run locally
  • Integration tests pass — not applicable
  • Manual testing done — not run

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (not applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

codex was used for repository inspection.

Co-authored-by: Misak2333 <jzxscp173@163.com>
Co-authored-by: Chase-Rong <lolopop.rong@gmail.com>
Co-authored-by: Asher-XunZhang <asherxunzhang@gmail.com>
@yejj710
yejj710 requested a review from Chase-Rong September 16, 2026 07:49
@github-actions github-actions Bot added run-ci Mooncake Conductor Changes related to mooncake-conductor labels Sep 16, 2026
if (pending_replay_ranges_.empty()) break;
range = pending_replay_ranges_.front();
}
if (auto err = RequestReplay(range.from, range.until);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The vLLM ZMQ publisher already serializes live publication and replay, and replay records are emitted in monotonically increasing sequence order. The ordering issue here is in the consumer replay-timeout path.

When a gap is detected, RequestReplay() may time out, but the code then breaks out of the replay loop and immediately dispatches the current live event. A later retry can therefore apply older events after newer ones. For example, if the missing range contains Stored(A) and the live boundary is Removed(A), the removal is applied first and the replayed store can later resurrect A in the index. This does not depend on the key being evicted immediately; the missing range may span a much longer disconnect.

Could the consumer buffer subsequent live messages while replay is in progress, then dispatch the recovered range followed by the buffered messages in sequence order, with replay/live deduplication? The buffer and recovery duration should be bounded. If the missing range cannot be recovered, the affected source/index should be marked stale rather than applying older mutations after the newer boundary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. I have reworked the consumer recovery path around the following design.

1. Contiguous event application

last_seq_ now represents only the highest contiguously applied sequence.

When a gap is detected, the current live boundary is not dispatched until all preceding sequences have been recovered. A replay timeout therefore cannot cause an older mutation to be applied after a newer one.

2. Unified replay/live ordering

Live messages received beyond a gap and replayed messages are placed in the same sequence-ordered buffer.

The consumer drains the buffer only from last_seq_ + 1, ensuring cases such as Stored(A) followed by Removed(A) are always applied in the original order.

3. Replay/live deduplication

Because replay and live traffic use separate ZMQ channels, the same sequence may arrive through both paths, particularly after reconnecting.

Already-applied sequences and duplicate buffered sequences are discarded. Conflicting payloads for the same sequence cause the source to be marked stale.

4. Bounded recovery

Recovery is bounded by:

  • A total recovery deadline.
  • A maximum buffered-message count.
  • A maximum buffered-byte count.

These limits prevent indefinite recovery and unbounded memory usage.

5. Fail-closed stale handling

If the missing range cannot be recovered, replay is unavailable, or a recovery limit is exceeded, the source is marked stale and no newer mutations are applied.

Staleness is propagated through the mandatory EventHandler::OnSourceStale(...) callback, requiring the index layer to invalidate or exclude data belonging to that source until a full resynchronization is completed.

The reconnect path uses the same ordering, buffering, and deduplication logic.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Thanks for the fixs.

@Chase-Rong
Chase-Rong self-requested a review September 17, 2026 11:33
@Chase-Rong Chase-Rong added run-ci and removed run-ci labels Sep 20, 2026
@Chase-Rong Chase-Rong added run-ci and removed run-ci labels Sep 21, 2026
@Chase-Rong
Chase-Rong merged commit fe0d23e into kvcache-ai:main Sep 21, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Mooncake Conductor Changes related to mooncake-conductor run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants