Skip to content

vllm.v1.kv_offload.tiering.p2p.session

Modules:

  • client –

    Client-role state machine for a single peer session.

  • protocol –

    P2P KV cache sharing protocol constants and documentation.

  • server –

    Server-role state machine for a single peer session.

  • session –

    P2PSession — bidirectional session combining client + server roles.

Classes:

LoadResult

Bases: NamedTuple

Result from a session poll, client side.

P2PSession

Bidirectional session — coordinator over ClientRole + ServerRole.

Lifecycle
  • Constructor with conn=None ⇒ pending. Accepts add_stored_blocks but cannot send (used by the prefiller to buffer blocks before the decoder connects).
  • Constructor with conn != None ⇒ connected. Sends our own ConnectMsg immediately; the peer's ConnectMsg arrives in poll() and is dispatched to _on_connect, which starts transport.add_remote_peer_async. A later poll() sees the registration land and replies with ConnectAckMsg; a failed registration marks the connection dead instead. Outgoing sends are queued until ConnectAckMsg confirms our metadata reached the peer.
  • attach_connection(conn) on a pending session ⇒ same as above, starting from pending.

Methods:

  • abort_loads –

    Abort every inbound load, failing each now; see ClientRole.

  • add_stored_blocks –

    New blocks stored locally — match against pending fetch demand.

  • attach_connection –

    Attach a connection to a pending session and announce ourselves.

  • close –

    Shut down.

  • drain_stores –

    Withdraw queued stores, optionally for fetches arriving during drain.

  • finish_request –

    Called when the request is finishing locally.

  • flush_pending_lookups –

    Flush any aggregated symmetric-P2P lookups for this peer.

  • poll –

    Process incoming messages, drive transfers, apply timeouts.

  • register_lookup –

    Register or resolve one (kv_request_id, key) probe.

  • request_blocks –

    Send fetch to the peer.

  • serve_external_requests –

    Resolve inbound peer lookups against the tiering manager.

Attributes:

  • data_plane_fault (str | None) –

    The data-plane fault that ended this session, if any.

  • death_reason (str) –

    Why the connection died, for the manager's peer-down log.

  • has_pending_work (bool) –

    True while inbound loads or outbound transfers are outstanding.

  • last_activity_at (float) –

    Monotonic timestamp of the last meaningful session activity.

  • ready (bool) –

    True after the peer acked our ConnectMsg (we may send freely).

data_plane_fault property

The data-plane fault that ended this session, if any.

The transport's peer fault (see server role), an AbortAck that never arrived, which leaves this side unable to tell whether the peer's WRITE stopped, or a failed registration of the peer's NIXL agent.

death_reason property

Why the connection died, for the manager's peer-down log.

A connection the control transport marked dead itself (heartbeat timeout, socket closed) has no recorded cause.

has_pending_work property

True while inbound loads or outbound transfers are outstanding.

last_activity_at property

Monotonic timestamp of the last meaningful session activity.

ready property

True after the peer acked our ConnectMsg (we may send freely).

_disconnect(reason)

Best-effort DisconnectMsg, then mark the connection dead.

_escalate_abort_ack_timeout()

Fault the peer once one of its AbortAcks times out.

The timed-out load already failed in this poll's results. Without this, the session stays up and every later fetch to the same stuck peer waits out the full load and abort-ack timeouts again.

_escalate_peer_fault()

Disconnect once a data-plane peer fault's inflight WRITEs drain.

See "Failure model" in data/base.py: the fault ends the session through the same reap as a control-plane failure.

_mark_dead(reason)

Mark the connection dead, recording the first cause.

_poll_registration()

Ack or reject the peer once its registration resolves.

Called from poll() after message dispatch. A successful registration releases ConnectAckMsg — the peer treats that as permission to send, so it must not go out earlier. A failed one sends a best-effort disconnect and marks the local connection dead for the manager to reap.

_protocol_error(reason)

Log a protocol violation and disconnect.

Best-effort sends DisconnectMsg so the peer learns why we're going away, then marks the connection dead. The manager reaps the session on the next poll via alive.

_send_connect()

Send our ConnectMsg announcing local NIXL metadata.

abort_loads()

Abort every inbound load, failing each now; see ClientRole.

add_stored_blocks(kv_request_id, keys, block_ids, job_id)

New blocks stored locally — match against pending fetch demand.

attach_connection(conn)

Attach a connection to a pending session and announce ourselves.

Symmetric: every side advertises its NIXL metadata on connect, so whichever peer receives a session first can register the other.

close()

Shut down.

failed_jobs: client load job_ids to fail. failed_req_ids: client kv_request_ids to fail — in-flight loads plus requests with an unresolved symmetric-P2P probe toward the now-dead peer. The manager fails these so the consumer's lookup() falls back to local prefill instead of deferring forever on an answer that can never arrive. failed_stores: server store job_ids to fail. failed_serves: synthetic lookup ctxs still owing parent.on_request_finished (the manager flushes these on its next serve_external_requests). retained: server transfers that may still be writing, with the store jobs they read (held until they stop).

drain_stores(kv_request_ids=None)

Withdraw queued stores, optionally for fetches arriving during drain.

finish_request(kv_request_id)

Called when the request is finishing locally.

Finishes the client role (aborts any inbound load and drops any pending symmetric-P2P lookup state) and finalizes any outbound serving (server role) for this id. Roles that aren't active for this id are silent no-ops.

flush_pending_lookups()

Flush any aggregated symmetric-P2P lookups for this peer.

Called once per scheduler step from the manager's on_schedule_end(). Probes wait for ConnectAckMsg before sending.

poll()

Process incoming messages, drive transfers, apply timeouts.

register_lookup(kv_request_id, key)

Register or resolve one (kv_request_id, key) probe.

Called from the manager's lookup() for symmetric-P2P consumers (remote_kv_source sub-dict in kv_transfer_params). See ClientRole.register_lookup for the state-machine contract.

request_blocks(job_id, kv_request_id, keys, block_ids)

Send fetch to the peer.

serve_external_requests(parent)

Resolve inbound peer lookups against the tiering manager.

Delegates to the server role; the parent handle is valid only for the duration of this call.

SessionCloseResult

Bases: NamedTuple

Result of tearing down a P2PSession.

failed_jobs/failed_stores are the in-flight jobs (client loads / server stores) the manager must mark failed. failed_req_ids is every client-side kv_request_id whose lookup() must fail (in-flight loads plus unresolved probes); failed_serves is the server-side lookup state the dead peer can no longer resolve. retained maps each server transfer that may still be writing to the store jobs it reads: they are not in failed_stores, and stay pinned until the transport reports it stopped.

SessionPollResult

Bases: NamedTuple

Result of one P2PSession.poll() tick.

loads/stores are the same per-role results the manager has always consumed. new_fetch_ids reports kv_request_ids whose FetchMsg arrived this tick — the manager uses them to bind kv_request_id → session and replay any submit_store batches parked while no peer had asked yet. Reporting (rather than calling back into the manager mid-dispatch) keeps the dependency strictly top-down.

StoreResult

Bases: NamedTuple

Result from a session poll, server side.