// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // // trtllm.engine.v1: disaggregated serving handoff objects. // // Flow: the context engine's host (fills ctx_instance_id, request_digest and digest_version per its // capabilities, inlines tensors, encodes, optionally signs) -> SignedHandoff on the CONTEXT_DONE row -> // context frontend -> one HTTP hop through the orchestrator -> generation frontend -> `disagg.handoff` // of the GENERATION_ONLY request -> the generation engine's host (verifies the signature per its // capabilities and parses). The KV cache itself never travels over this protocol. // // Numbering: KvHandoff fields 30-39 are reserved for disaggregated n > 1 and 40-49 for encoder // disaggregation. syntax = "proto3"; package trtllm.engine.v1; import "engine/v1/common.proto"; // First-token logprob of one beam. message FirstTokenLogprob { // Sampled token. sfixed32 token_id = 1; // Logprob of the sampled token; -inf is encoded as IEEE negative infinity (no lower clamp). float logprob = 2; // Rank in the full vocabulary (1-based); 0 = not computed. uint32 rank = 3; // Top-k candidates in descending logprob order. repeated TopLogprob topk = 4; } // One top-k candidate. message TopLogprob { sfixed32 token_id = 1; float logprob = 2; } // Multimodal layout for disaggregated prefill/decode. mRoPE tensors can only be inlined. message MultimodalHandoff { // Start position of each multimodal item in the (expanded) prompt. repeated uint32 positions = 1; // Same length as positions: length of each item (tokens). repeated uint32 lengths = 2; // mRoPE position ids (inline form of the native shared tensor handle). InlineTensor mrope_position_ids = 3; // mRoPE position deltas. InlineTensor mrope_position_deltas = 4; } // Effective max_tokens of the context engine (equals PromptInfo.max_tokens of its first row). message EffectiveMaxTokens { // Effective value (tokens). The generation engine must use it; if its local limit is smaller it // rejects before acceptance with PEER_INCOMPATIBLE (field = "stop.max_tokens") instead of silently // truncating. uint32 value = 1; // True when the requested value was clamped. bool clamped = 2; } // Generation-first rendezvous ticket. The context host issues it with the deployment key; the // generation frontend obtains it from the context frontend's // /server_info.disaggregated_params.rendezvous_ticket_b64 and copies it unchanged into the rendezvous // subset. mac = HMAC-SHA256(key[key_id], canonical encoding of the other ticket fields); the canonical // encoding is a fixed byte layout defined by the host implementation, not protobuf serialization. message RendezvousTicket { // Instance id of the issuing context host (equals Capabilities.disagg.instance_id). string ctx_instance_id = 1; // Transfer backend name. string transfer_backend = 2; // Targeted attention DP rank; unset = broadcast. optional uint32 attention_dp_rank = 3; // Rendezvous address, verbatim; byte-identical to KvHandoff.ctx_endpoint of a context-first handoff. string endpoint = 4; // Issue time (unix milliseconds); the clock skew tolerated across machines is a deployment setting. uint64 issued_at_unix_ms = 5; // Validity (milliseconds): invalid after issued_at_unix_ms + ttl_ms. uint32 ttl_ms = 6; // Signing key id (one of Capabilities.disagg.integrity.key_ids). string key_id = 7; // HMAC-SHA256, 32 B; empty when integrity.scheme is NONE. bytes mac = 8; } // Typed handoff object. // Who fills what: the engine (adapter) fills disagg_request_id, ctx_engine_request_id through // multimodal, engine_state, expires_after_ms, expanded_prompt_tokens and effective_max_tokens; the // context host core fills ctx_instance_id, request_digest and digest_version. For generation-first, the // generation frontend assembles the rendezvous subset (disagg_request_id, ctx_instance_id, ctx_dp_rank, // ctx_endpoint, transfer_backend, schedule_style, rendezvous_ticket). // "Frontend-readable" below only means the frontend may parse a read-only copy; when forwarding, the // SignedHandoff is always passed on unchanged. "Forward only" fields are opaque to the frontend. message KvHandoff { // Pairing key (fixed u64) equal to Request.disagg.request_id of both legs; when the context leg did // not set it, the pairing id the engine actually used (= engine_request_id). Always present. // Frontend-readable (orchestration, release). fixed64 disagg_request_id = 1; // Instance id of the producing context host (= Capabilities.disagg.instance_id), filled by that host. // Always present. Frontend-readable. string ctx_instance_id = 2; // Context engine local request id (native ctx_request_id), only for log / perf correlation. optional uint64 ctx_engine_request_id = 3; // Context-side attention DP rank; unset = the generation side broadcasts to all context DP ranks // (distinct from an explicit 0). Forward only. optional uint32 ctx_dp_rank = 4; // Rendezvous address given by the transceiver, verbatim; a single string, not split into host and // port. Format depends on the backend. Forward only. string ctx_endpoint = 5; // Transfer backend of the producer; if the generation side is incompatible it fails with // PEER_INCOMPATIBLE before rendezvous. Always present. Forward only. string transfer_backend = 6; // Native transceiver communication state, verbatim (not interpreted by the protocol). Forward only. bytes opaque_state = 7; // Same as Request.disagg.schedule_style. Always present. Frontend-readable. ScheduleStyle schedule_style = 8; // First token, one per beam (including beams whose first token is end_id); empty for remote tail. // The frontend must not emit it as output. Forward only. repeated sfixed32 first_gen_tokens = 9; // One entry per beam; the length must equal the beam width. Required when beam_width > 1 (the // generation side initializes cum_logprob from it). Forward only. repeated FirstTokenLogprob first_gen_logprobs = 10; // One vocabulary-sized vector per beam; inline only; gated by Capabilities.disagg.first_gen_logits. // Forward only. repeated InlineTensor first_gen_logits = 11; // Speculative draft tokens from the context side. Forward only. repeated sfixed32 draft_tokens = 12; // When set, the generation leg must be sent and replays the suffix starting at this prompt position. // Frontend-readable (orchestration). optional uint32 remote_tail_start = 13; // Multimodal prefill/decode layout. Forward only. MultimodalHandoff multimodal = 14; // Consistency digest of the two legs: SHA-256 (32 B) computed by the context host core over the // context request, using the field allowlist and TLV canonical encoding selected by digest_version. // The generation host core recomputes it before acceptance and rejects a mismatch with // HANDOFF_INVALID. The engine is not involved. Required for context-first (empty in the // generation-first rendezvous subset). Forward only. bytes request_digest = 15; // Engine-specific handoff state that the protocol does not interpret (the only opaque engine field, // declared by Capabilities.disagg.uses_engine_state). Forward only. bytes engine_state = 16; // Validity from CONTEXT_DONE (milliseconds, judged by the context engine's clock); on expiry the // context side reclaims the KV. Required for context-first (0 in the generation-first rendezvous // subset). Frontend-readable. uint32 expires_after_ms = 17; // Tokens the generation leg must use when the engine rewrote the prompt (media mode); same as // PromptInfo.expanded_prompt_tokens. Unset = not rewritten. The generation leg uses it as // prompt_tokens. Frontend-readable. TokenSeq expanded_prompt_tokens = 18; // Field 19 is retired: integrity is carried by the enclosing SignedHandoff. The number is not reused. reserved 19; reserved "integrity"; // Effective max_tokens of the context engine. Required for context-first (CONTEXT_DONE); empty in the // generation-first rendezvous subset. Frontend-readable. EffectiveMaxTokens effective_max_tokens = 20; // Version of the allowlist and canonical encoding used for request_digest (logical u16, 1-65535; this // contract defines version 1). Required for context-first (0 in the generation-first rendezvous // subset). Forward only. uint32 digest_version = 21; // Ticket issued by the context host that the generation-first rendezvous subset must carry verbatim. // Forward only. RendezvousTicket rendezvous_ticket = 22; // 30-39 are reserved for disaggregated n > 1 (for example one handoff per sequence with a seq_index); // 40-49 for encoder disaggregation (encoder -> context handoff). To use them, remove the matching // reserved line and define the fields. reserved 30 to 39; reserved 40 to 49; } // Signed envelope. handoff_bytes = the encoded KvHandoff, written once by the context host; // mac = HMAC-SHA256(key[key_id], // "trtllm.engine.v1.SignedHandoff\0" || u32_le(len(key_id)) || utf8(key_id) || handoff_bytes) // The domain-separation prefix and the key_id binding prevent a MAC from being reused for another // message type or key. The generation host verifies the MAC over the raw bytes before parsing and never // re-encodes; frontends and orchestrators only parse read-only copies and forward the whole envelope // unchanged. When a key is configured, a missing MAC or a failed verification is HANDOFF_INVALID. // Generation-first rendezvous subset (selected by // Request.disagg.schedule_style == SCHEDULE_STYLE_GENERATION_FIRST, never guessed from an empty mac): // handoff_bytes encodes the subset and mac and key_id must be empty; after parsing, the host asserts // KvHandoff.schedule_style == GENERATION_FIRST and that all non-subset fields are empty, then verifies // the rendezvous_ticket. message SignedHandoff { // Encoded KvHandoff bytes (opaque to forwarders). bytes handoff_bytes = 1; // HMAC-SHA256, 32 B; empty when Capabilities.disagg.integrity.scheme is NONE. bytes mac = 2; // Signing key id. string key_id = 3; } // Global identity of a handoff: (ctx_instance_id, disagg_request_id). Used by ReleaseHandoffs. message HandoffKey { // Equals KvHandoff.ctx_instance_id. string ctx_instance_id = 1; // Equals KvHandoff.disagg_request_id. fixed64 disagg_request_id = 2; }