Skip to content

vllm.v1.kv_offload.tiering.p2p.session.client

Client-role state machine for a single peer session.

Handles outgoing fetch requests, abort-on-timeout, abort-ack timeout, and produces LoadResult for completed loads. The session coordinator parses wire messages and dispatches typed arguments here; this module never touches ControlConnection directly — it emits via the send callback injected by the coordinator (which gates on ConnectAck).

Classes:

  • ClientCloseResult –

    What the manager must fail when a peer session is torn down.

  • ClientRole –

    Client-side load state machine for one peer session.

  • LoadResult –

    Result from a session poll, client side.

ClientCloseResult

Bases: NamedTuple

What the manager must fail when a peer session is torn down.

failed_jobs is the job_id of every load still in flight and not yet reported; each becomes a JobResult(success=False). failed_req_ids is every kv_request_id whose lookup() would otherwise defer forever on the dead peer — the in-flight loads plus any request holding an unresolved symmetric-P2P probe. failed_jobs is the subset of failed_req_ids that had a load job.

ClientRole

Client-side load state machine for one peer session.

The coordinator owns the connection and the send-gating; this role is given a send callback and a peer_id for log messages and is otherwise self-contained.

Methods:

  • abort_loads –

    Abort every load not already aborting, for a cache reset.

  • can_send_terminal_fetch –

    A terminal fetch must not close a newer live round on the peer.

  • close –

    Tear down, reporting work the dead peer can no longer complete.

  • collect_results –

    Walk load timeouts and drain completed loads.

  • finish –

    Finish a request: abort in-flight loads and release lookup state.

  • flush_pending_lookups –

    Send a LookupMsg for each kv_request_id with unsent entries.

  • get_expired_lookup –

    Return an expired request and seconds without progress, if any.

  • mark_fetch_sent –

    Reject retired, cancelled or expired fetches before transport handoff.

  • on_abort_ack –

    Handle an AbortAckMsg from the peer.

  • on_lookup_resp –

    Apply per-pair hit/miss results from a peer.

  • on_transfer_done –

    Handle a TransferDoneMsg from the peer.

  • register_lookup –

    Register or resolve one (kv_request_id, key) probe.

  • request_blocks –

    Send the FetchMsg closing the current lookup round.

Attributes:

expired_abort_ack property

The first (kv_request_id, round_seq) whose AbortAck timed out.

has_active_loads property

True if any kv_request_id has a fetch in flight.

_abort_load(kv_request_id, round_seq, load)

Send AbortFetch and report the load failed now, deferring the release of its blocks until the peer confirms its WRITEs ended.

_get_or_create_request(kv_request_id)

Get or create the state entry for a kv_request_id.

_maybe_prune(kv_request_id)

Drop the entry once it holds no live load or lookup state.

peer_lookup_open is only read by finish, and every path that clears the last probe (fetch / finish / close) also settles it, so dropping on emptiness never loses a flag still in use. known_misses keeps the entry until finish, so a load completing doesn't discard them.

_on_load_terminal(kv_request_id, st)

Wind down id-level state once no load remains in flight.

abort_loads()

Abort every load not already aborting, for a cache reset.

Each is reported failed at once with its release deferred, so a drain waits only for the AbortAcks (or the abort-ack timeout's disconnect) instead of the full load timeout. Lookup state is left alone.

can_send_terminal_fetch(kv_request_id)

A terminal fetch must not close a newer live round on the peer.

close()

Tear down, reporting work the dead peer can no longer complete.

A request is failed if it has a load in flight (its job fails) or holds an unresolved symmetric-P2P probe (its lookup() would defer forever on an answer that can never arrive). See ClientCloseResult. The end of the session is the release point for every load already reported failed: their deferred releases are set here.

collect_results()

Walk load timeouts and drain completed loads.

A load past its load timeout (_P2P_LOAD_TIMEOUT_S or _PD_LOAD_TIMEOUT_S) gets an AbortFetchMsg and is reported failed at once, with its blocks' release deferred. One whose AbortAck then misses _ABORT_ACK_TIMEOUT_S is recorded in expired_abort_ack, so the session disconnects and close() releases it. Fetches never handed to the transport fail locally without an abort.

finish(kv_request_id)

Finish a request: abort in-flight loads and release lookup state.

Called from the session's finish_request. Sends an AbortFetchMsg per load not already aborting, and — independently — the terminal empty FetchMsg when the peer still holds lookup state no fetch has closed (its "request finished" signal: it releases lookup state, drains parked supply, and fires cb.finish_request). A later round's supply can be parked while an earlier round's load is still in flight, so both can be owed at once.

Then drop all probe/lookup state. Never-sent fetches fail locally on the next poll. Sent loads fail at once and keep their blocks until AbortAck, TransferDone, or session close.

flush_pending_lookups(send_ready)

Send a LookupMsg for each kv_request_id with unsent entries.

Called once per scheduler step from the manager's on_schedule_end(). A request's block set may be discovered across several scheduler steps, so more than one LookupMsg can go out per kv_request_id — one per step that registered new keys, all tagged with the current round. register_lookup() de-dups in-flight and already-resolved (req_id, key) pairs, so each LookupMsg carries only the keys first probed in that step. Wait for ConnectAckMsg before sending or starting the response deadline.

Only requests that registered new keys since the last flush are visited — the _flush_pending work-list avoids scanning every live request each scheduler step.

get_expired_lookup()

Return an expired request and seconds without progress, if any.

mark_fetch_sent(msg)

Reject retired, cancelled or expired fetches before transport handoff.

on_abort_ack(kv_request_id, round_seq)

Handle an AbortAckMsg from the peer.

on_lookup_resp(kv_request_id, keys, hits)

Apply per-pair hit/miss results from a peer.

Pairs that don't match a known entry (already cancelled or never asked) are silently dropped — the producer is free to split or coalesce responses.

on_transfer_done(kv_request_id, success, round_seq)

Handle a TransferDoneMsg from the peer.

register_lookup(kv_request_id, key)

Register or resolve one (kv_request_id, key) probe.

Idempotent across scheduler steps: - First call: creates a pending entry, returns None. - Subsequent calls while in-flight: returns None. - Once a LookupRespMsg has resolved the entry: returns the cached bool result on every call without popping it.

A resolved entry is retained until a fetch closes the round or the request finishes (finish clears all entries for the id). A request's block set can be re-probed across steps, so popping on read would make a repeat probe of an already-resolved key look brand-new and re-queue it, emitting a redundant LookupMsg for an answer we already hold. At fetch a HIT is dropped, forcing a fresh probe under the next round since the block is unpinned once served, while a MISS is kept for the rest of the request.

request_blocks(job_id, kv_request_id, keys, block_ids, send_ready)

Send the FetchMsg closing the current lookup round.

The scheduler may submit several loads per kv_request_id as its matched prefix resolves incrementally; each fetch carries the round it closes so the loads stay independent on the wire.

LoadResult

Bases: NamedTuple

Result from a session poll, client side.

_ClientRequestState dataclass

Per-kv_request_id client-side state.

One entry per kv_request_id we're driving. Lookup-phase fields are used only by symmetric P2P (do_p2p_fetch); PD-only loads leave probes/unsent empty and drive just phase and loads. An entry is dropped once every field is idle — see ClientRole._maybe_prune.

_InboundLoadState dataclass

Client-role state for a single in-flight load request.

Lives in _ClientRequestState.loads keyed by round_seq for the duration of a fetch; the owning kv_request_id is the outer dict key.