vllm.v1.kv_offload.tiering.p2p.session.server ¶
Server-role state machine for a single peer session.
Owns block matching (supply vs. demand), inflight RDMA transfers, store-job timeouts, abort-drain, and produces StoreResult for completed stores. 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).
Protocol violations the role can detect (today: duplicate FetchMsg for the same kv_request_id) are surfaced as ValueError so the coordinator's _dispatch_message can reuse its existing _protocol_error path.
Classes:
-
ServerRole–Server-side store/serve state machine for one peer session.
-
StoreResult–Result from a session poll, server side.
ServerRole ¶
Server-side store/serve state machine for one peer session.
The coordinator owns the connection and the send-gating; this role is given a send callback, the DataTransport, and the peer_id for transport calls and log messages.
Methods:
-
add_stored_blocks–New blocks stored locally — match within their fetch round.
-
close–Tear down. Cancels inflight.
-
collect_idle_timeouts–Run only the store-job timeout sweep.
-
collect_results–Drain timeouts, deferred results, and transport completions.
-
drain_pending_aborts–Re-attempt every parked abort once per poll tick.
-
finish–Mark an outbound request finishing.
-
on_abort_fetch–Handle an AbortFetchMsg from the peer, cancelling one round.
-
on_fetch–Handle a FetchMsg from the peer.
-
on_lookup–Enqueue a LookupMsg from a symmetric-P2P consumer.
-
serve_external_requests–Resolve inbound peer lookups against the tiering manager.
Attributes:
-
has_inflight_transfers(bool) –True if any outbound store transfer is still in flight.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 | |
has_inflight_transfers property ¶
True if any outbound store transfer is still in flight.
_drain_abort(kv_request_id, round_seq) ¶
One drain attempt for a pending abort.
Detaches the aborted round, then asks the transport to cancel its inflight transfers in mode="wait". Sends AbortAckMsg once nothing remains inflight, or after _CANCEL_DRAIN_TIMEOUT_S falls back to mode="immediate" and acks anyway.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_fail_round_jobs(rnd) ¶
Fail a terminated round's still-pending store jobs (idempotent).
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_finalize_lookup(lookup, parent) ¶
Emit the aggregated LookupRespMsg and close the synthetic request.
Called once per lookup when pending is empty — either every key resolved to HIT or MISS, or the deadline forced remaining stragglers to MISS. Preserves the wire order of the inbound LookupMsg so the client can zip keys and hits positionally.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_finalize_outbound(kv_request_id, round_key, success=None, send_done=True) ¶
Pop one round and emit its terminal results.
If success is None, derive it from req.remaining == 0. send_done=False skips the TransferDoneMsg (terminal empty fetch). Other rounds of the id are untouched.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_finish_inbound_lookups(kv_request_id) ¶
Close the server-side lookup phase for kv_request_id.
Pops every parked _ActiveLookup for this id (so _resolve_pending_lookups cannot promote a HIT_PENDING / RETRY key into a fresh parent.create_store_job after this point) and queues each lookup.ctx for parent.on_request_finished (fired by the next serve_external_requests, since no parent handle is available during dispatch) so the TieringManager can release per-lookup bookkeeping. Any still-unprocessed raw LookupMsg for this id is dropped — it never got on_new_request, so nothing is owed. The aggregated LookupRespMsg is skipped — the client already knows the request is over (it just sent a terminal FetchMsg, or is finishing locally).
Called on the two events that mean "no more lookup traffic for kv_request_id is expected on this session": the terminal empty FetchMsg from the peer and a local finish. Whichever fires second is a no-op.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_get_or_create_request(kv_request_id) ¶
Get or create the state entry for a kv_request_id.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_inflight_add(tid, xfer) ¶
Insert an inflight transfer and record it on the request.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_inflight_pop(tid) ¶
Pop an inflight transfer and drop it from the request's set.
Callers are responsible for the _maybe_prune that may follow once the request's other state has also cleared.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_maybe_prune(kv_request_id) ¶
Drop the entry once it holds no live state.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_pin_and_register_hits(lookup, keys, parent) ¶
Pin primary slots for HIT keys and park them as the lookup's round supply via add_stored_blocks.
Caller has already confirmed every key is HIT (single-threaded scheduler ⇒ no eviction race), so the JobMetadata returned by parent.create_store_job carries parallel keys/block_ids of length len(keys).
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_poll_lookup_keys(lookup, keys, parent) ¶
Poll keys against the tiering manager and pin any HITs.
For each key not already definitively resolved, query parent.lookup and record the outcome on lookup: HIT / MISS land in resolved and clear pending; HIT_PENDING / RETRY park in pending for a later serve. Newly-HIT keys are pinned in one batch via :meth:_pin_and_register_hits and also returned (for caller logging).
Shared by the first-sighting pass (:meth:_process_inbound_lookup) and the re-poll pass (:meth:_resolve_pending_lookups); callers pass a de-duplicated keys collection.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_process_inbound_lookup(kv_request_id, keys, enqueued_at, round_seq, parent) ¶
Resolve one enqueued LookupMsg against parent.
For each key, query the tiering manager via parent.lookup and pin any HITs immediately via parent.create_store_job (plumbed into the existing add_stored_blocks matching path so the eventual FetchMsg finds them). HIT_PENDING / RETRY keys park in :class:_ActiveLookup for re-polling by :meth:_resolve_pending_lookups.
The outbound LookupRespMsg is deferred until every key has settled to HIT or MISS (or the batch-level deadline fires, forcing any stragglers to MISS). One LookupRespMsg goes out per LookupMsg — carrying every key in wire order — after which parent.on_request_finished fires and the entry is dropped.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_resolve_pending_lookups(kv_request_id, parent) ¶
Re-poll a request's deferred LookupMsg keys; finalize when ready.
Walks every parked :class:_ActiveLookup for kv_request_id and re-calls parent.lookup per still-pending key, moving HIT/MISS results into resolved. If deadline has passed, remaining pending keys are force-resolved to MISS so the consumer can fall back instead of waiting on a stuck producer. Newly-HIT keys are pinned via parent.create_store_job in one call per affected lookup. Lookups whose pending empties out get their aggregated LookupRespMsg sent by :meth:_finalize_lookup.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_settle_xfer_jobs(xfer, success) ¶
Emit StoreResults for a completed transfer's store jobs.
Pops each attached job from _store_jobs and clears it from its round's pending set. A job already popped (via timeout, cancel, etc.) is skipped so we never double-emit a contradictory result.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
add_stored_blocks(kv_request_id, keys, block_ids, job_id, round_seq=0, *, from_lookup=False) ¶
New blocks stored locally — match within their fetch round.
Lookup pins carry the round they were probed under; PD submit_store batches share PD's single round 0.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
close() ¶
Tear down. Cancels inflight.
Returns (failed_store_job_ids, failed_serves) where failed_serves are synthetic lookup ctxs still owing a parent.on_request_finished. The session is going away with no parent handle in hand, so the manager flushes these in its next serve_external_requests.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
collect_idle_timeouts() ¶
Run only the store-job timeout sweep.
Used by the coordinator's no-conn poll path: a pending session cannot have inflight transfers (no peer registered yet), so we skip the transport poll and the deferred-result drain.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
collect_results() ¶
Drain timeouts, deferred results, and transport completions.
Inbound LookupMsg resolution (including re-polling HIT_PENDING / RETRY keys) is NOT done here — it runs in serve_external_requests where the ParentManager is available.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 | |
drain_pending_aborts() ¶
Re-attempt every parked abort once per poll tick.
finish(kv_request_id) ¶
Mark an outbound request finishing.
No more submit_store calls will arrive for this id. Any blocks the peer demanded but we never stored will never come; tell the peer to stop waiting (TransferDoneMsg success=False) instead of letting it hit _LOAD_TIMEOUT_S.
Also drops any in-flight lookups for this kv_request_id and queues their ctxs for parent.on_request_finished so the TieringManager can release per-request bookkeeping. (For symmetric P2P this path is rarely hit since the producer has no local request lifecycle for the consumer's id; this cleanup is mostly active on the PD side.)
If the decoder hasn't sent fetch yet (no demand received), defer — on_fetch will finalize once demand arrives.
If inflight transfers exist for this id, defer — the last completing transfer in collect_results will fire the message.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
on_abort_fetch(kv_request_id, round_seq=0) ¶
Handle an AbortFetchMsg from the peer, cancelling one round.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
on_fetch(kv_request_id, keys, block_indexes, round_seq=0) ¶
Handle a FetchMsg from the peer.
A non-empty fetch binds and closes its round, leaving lookup state alone (the next round's LookupMsg may already be in flight). The terminal empty fetch closes the id: parked lookups are popped and every remaining round drained. A second fetch for a round already holding demand raises ValueError (protocol-error disconnect).
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
on_lookup(kv_request_id, keys, round_seq=0) ¶
Enqueue a LookupMsg from a symmetric-P2P consumer.
Dispatch runs during session.poll() where the :class:ParentManager handle is not available, so this only records the raw request. It is resolved — querying the tiering manager and emitting the aggregated LookupRespMsg — by the next :meth:serve_external_requests, the sole window in which parent calls are valid.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
serve_external_requests(parent) ¶
Resolve inbound peer lookups against the tiering manager.
Called once per scheduler step with a parent handle valid only for this call. Drains newly-enqueued LookupMsgs, re-polls any parked HIT_PENDING / RETRY keys, and releases the bookkeeping for lookups closed since the last serve.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
StoreResult ¶
_ActiveLookup dataclass ¶
In-flight state for one inbound LookupMsg.
Aggregates per-key HIT/MISS resolutions and defers the single outbound LookupRespMsg until every key has been resolved or the deadline fires (remaining pending keys then force-MISS). Exactly one LookupRespMsg is emitted per LookupMsg, carrying every key in the original wire order.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_InflightXfer dataclass ¶
Metadata for a single inflight RDMA transfer, keyed by transfer_id.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_MatchResult ¶
Bases: NamedTuple
Result of block matching: pairs ready for transfer.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_OutboundRequestState dataclass ¶
Server-role state for a single fetch round of a peer request.
A kv_request_id may run several lookup→fetch rounds; rounds live in _ServerRequestState.outbound keyed by the wire round_seq, so terminals touch only their own round.
Methods:
-
add_fetch_demand–Register the peer's fetch demand. Returns matched pairs.
-
add_stored_blocks–Add locally-stored blocks. Returns matched pairs.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
add_fetch_demand(keys, block_indexes) ¶
Register the peer's fetch demand. Returns matched pairs.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
add_stored_blocks(keys, block_ids, job_id) ¶
Add locally-stored blocks. Returns matched pairs.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_PendingLookup ¶
Bases: NamedTuple
A raw inbound LookupMsg awaiting resolution.
Enqueued by on_lookup during dispatch and drained by the next serve_external_requests. The deadline for any resulting HIT_PENDING / RETRY key is measured from enqueued_at.
Source code in vllm/v1/kv_offload/tiering/p2p/session/server.py
_ServerRequestState dataclass ¶
Per-kv_request_id server-side state.
Consolidates the outbound serve/transfer state, the symmetric-P2P inbound-lookup state, abort bookkeeping, and the inflight-transfer count for one kv_request_id. The owning id is the _requests dict key and is not duplicated here. An entry is dropped once every field is idle — see ServerRole._maybe_prune.