Skip to content

UCP/PROTO: Resolve SGL replay handles per element - #12404

Open
gleon99 wants to merge 8 commits into
openucx:masterfrom
gleon99:sgl-ft/step3-replay
Open

gleon99 wants to merge 8 commits into
openucx:masterfrom
gleon99:sgl-ft/step3-replay

Conversation

@gleon99

@gleon99 gleon99 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Preserve original element identity across native SGL batch purge and
replay. Resolve its rkey and memory handle on the surviving MDs and
reconstruct the logical remote address from the fragment offset.

Add failing-then-passing regressions for incorrect element keys, stale
memory handles, overlapping ranges and transport-adjusted addresses.
Verify host and CUDA replay with actual QP failures.

@gleon99
gleon99 requested a review from a team as a code owner November 20, 2026 08:46
@gleon99 gleon99 added the WIP-DNM Work in progress / Do not review label Nov 20, 2026
@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread src/ucp/rma/put_offload.c Outdated
{
ucp_request_t *req = ucs_container_of(self, ucp_request_t, send.uct);

if (ucs_unlikely(ucp_ep_config(req->send.ep)->key.err_mode ==

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

put/sgl/offload is not probed at all when err_mode is FAILOVER: ucp_proto_multi_check_params() → ucp_proto_common_init_check_err_handling() requires UCP_PROTO_COMMON_INIT_FLAG_FAILOVER, and ucp_proto_put_sgl_offload_probe() passes extra_flags=0, so this branch is dead and SGL puts keep falling back to put/sgl/contig. pls add the flag in the probe and pick the repost send_func there, instead of re-checking err_mode on every progress call.

Comment thread src/ucp/rma/put_offload.c Outdated
ucp_request_invoke_uct_completion_success,
ucp_proto_request_zcopy_completion);
}
static ucs_status_t ucp_proto_put_sgl_offload_progress(uct_pending_req_t *self)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: 1 blank line between functions (docs/CodeStyle.md).

Suggested change
static ucs_status_t ucp_proto_put_sgl_offload_progress(uct_pending_req_t *self)
static ucs_status_t ucp_proto_put_sgl_offload_progress(uct_pending_req_t *self)

Comment thread src/ucp/proto/proto_repost.c Outdated
ucs_mpool_params_t params;
ucs_status_t status;

if (ucs_unlikely(!(worker->flags &

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls init this mpool in ucp_worker_init_mpools() next to reg_mp/rkey_mp; lazy init from the send path is inconsistent with the other worker pools and adds a check on every post.

Comment thread src/ucp/proto/proto_repost.h Outdated
/* Keep logical element identity until a native SGL batch is completed.
* NULL indices denotes consecutive elements starting at the iterator offset;
* otherwise count is at most UCP_MAX_IOV and indices is copied. */
uct_completion_t *ucp_proto_repost_sgl_completion(ucp_request_t *origin,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

outside proto_repost.c these two are used only by gtest — can we keep them static and cover the batch through ucp_proto_repost_submit()? docs/CodeStyle.md requires static for single-file functions.

Comment thread src/ucp/proto/proto_repost.c Outdated
batch = ucs_container_of(comp, ucp_proto_repost_sgl_t, comp);
if (!(info->field_mask & UCT_EP_OP_INFO_FIELD_SGL_INDEX) ||
(info->sgl_index >= batch->count)) {
return UCS_ERR_INVALID_PARAM;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls log the reason before returning UCS_ERR_INVALID_PARAM here (and in the other reject paths); otherwise a replay mismatch fails the user's RMA with no trace.

Comment thread src/ucp/proto/proto_repost.c Outdated
select_param.mem_type = UCS_MEMORY_TYPE_HOST;
select_param.sg_count = 1;
ucp_memory_info_set_host(&mem_info);
ucp_proto_select_param_init(&select_param, UCP_OP_ID_REPOST, 0, 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: this hunk is unrelated to SGL repost and changes the selection key (sys_dev becomes UNKNOWN, mem_flags gets REGISTRABLE) — pls move it to a separate PR.

Comment thread src/uct/ib/mlx5/rc/rc_mlx5_ep.c Outdated
if (status == UCS_OK) {
if (sgl_op != NULL) {
info.field_mask |= UCT_EP_OP_INFO_FIELD_SGL_INDEX;
info.sgl_index = (uint16_t)(pi - sgl_op->sn);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pi - sgl_op->sn is a WQE/BB delta; it equals the element index only because every SGL element WQE is exactly one BB. pls add an assert (or a comment) so a future WQE layout change does not silently shift the index.

Comment thread test/gtest/ucp/test_ucp_rma.cc Outdated
UCP_INSTANTIATE_TEST_CASE_TLS_GPU_AWARE(test_ucp_rma_sgl_data, tcp, "tcp")

/* Exercise replay independently of SGL failover protocol selection. */
class test_ucp_rma_sgl_repost : public test_ucp_rma_sgl {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this class patches global iface->ops/internal_ops, fabricates ucp_request_t on the stack and clears memh/rkey md_map for ~20 internal cases, so it breaks on any refactor of the repost internals. pls keep the cases reachable through the real failover flow (like test_ucp_rma_sgl_failover) and drop the white-box ones.

@svc-nvidia-pr-review

Copy link
Copy Markdown

PR-level (REQUEST_CHANGES): ~1300 added lines spanning the UCT purge API, rc_mlx5 purge parsing, the UCP repost protocol and two large gtest suites — above the 500-line limit, pls split (UCT sgl_index + purge support, UCP element-identity replay, put/sgl failover protocol).

Residual coverage gap: nothing exercises the new ucp_proto_put_sgl_offload_repost_progress() through protocol selection (see the probe/FAILOVER flag finding), so the UCP-level failover path for native SGL put is effectively untested.

Residual coverage gap: GET SGL purge support is added in rc_mlx5 but there is no UCP get/sgl protocol; it is covered only by direct UCT submissions in gtest.

Residual coverage gap: the mid-batch/start_pi and sgl_op != NULL leak-at-loop-exit paths in uct_rc_mlx5_ep_outstanding_purge() are guarded only by ucs_assert, and no test drives them.

@svc-ucx

svc-ucx commented Nov 20, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (Tests althca on worker 2) · commit fc7e75f5

TL;DR: The gtest tcp/test_ucp_wireup_errh_peer.force_close_simultaneous_connect_winner/9 aborted on ucs_assert(wireup_ep->pending_count == 0) in ucp_wireup_ep_pending_purge() because the EP was torn down re-entrantly while a wireup proxy pending request was still executing — its count had not been decremented and it was no longer on the TL pending queue, so nothing could decrement it. Fix by making pending_count accounting re-entrancy-safe in ucp_wireup_ep_progress_pending() (decrement before invoking req->func, re-add only if it is actually re-queued) instead of asserting the count is zero.

Full analysis

Summary: Azure job "althca on worker 2" (build 146558) failed: make test aborted with assertion wireup_ep->pending_count == 0 at src/ucp/wireup/wireup_ep.c:224 during tcp/test_ucp_wireup_errh_peer.force_close_simultaneous_connect_winner/9 <tcp/tag,unified,addr_v2>.

Root cause: Re-entrant pending purge during pending dispatch. The backtrace shows a single nested call chain:

  1. uct_tcp_cm_handle_simult_conn → uct_tcp_cm_change_conn_state → uct_tcp_ep_pending_queue_dispatch (tcp_ep.c:1048) dequeues the wireup proxy request and calls ucp_wireup_ep_progress_pending (wireup_ep.c:121).
  2. That invokes ucp_wireup_msg_progress → uct_ep_am_bcopy → uct_tcp_ep_send → send fails (the peer force-closed; the log is full of "Connection reset by remote peer") → uct_tcp_ep_handle_send_err (tcp_ep.c:1101 purges the TCP ep) → ucp_worker_iface_error_handler.
  3. ucp_worker_iface_handle_uct_ep_failure (ucp_worker.c:502, ucp_ep_set_lanes_failed) → ucp_ep_set_failed (ucp_ep.c:1660) → ucp_ep_discard_lanes (ucp_ep.c:1614) → uct_ep_pending_purge() on the wireup lane → ucp_wireup_ep_pending_purge.

At step 3 wireup_ep->pending_count is still 1: it is only decremented when req->func returns UCS_OK (wireup_ep.c:122-124) or from the release callback (wireup_ep.c:137), and the in-flight proxy request has already been removed from the TCP ep's pending queue by the dispatcher. So uct_ep_pending_purge(msg_ep, ...) (wireup_ep.c:220) finds an empty queue, nothing decrements the counter, and the assertion at line 224 fires. In a release build the same window is worse: after the purge, uct_pending_queue_dispatch re-queues the proxy request onto the just-purged/failed TCP ep, leaking it or re-using freed state. This is a latent race in the wireup pending accounting (debug/assert builds only expose it), triggered by the simultaneous-connect + force-close test, not by anything in the test itself.

Implicated commit: unknown — not conclusively attributable from the log; the counter logic is pre-existing. Most recent change to this accounting is b904de40 "UCP/WIREUP: fix worker flush hang from recovery wireup ep (#11988)" (Zhenlong Ma), and the failing teardown path was recently touched by f68fa5fc (dmitrygx, #12360) and 11ae0fca (Evgeny Leksikov, #12274).

File: src/ucp/wireup/wireup_ep.c:224 (assert); real defect at src/ucp/wireup/wireup_ep.c:114-127 (ucp_wireup_ep_progress_pending)

Suggested fix: Make the proxy-request accounting valid across re-entrancy:

  • In ucp_wireup_ep_progress_pending(), decrement wireup_ep->pending_count (and record the proxy req as "in dispatch", e.g. a UCP_WIREUP_EP_FLAG_PENDING_DISPATCH flag) before calling req->func(req); if the call returns a status other than UCS_OK and the wireup ep was not purged meanwhile, re-increment it because UCT re-queues the request. If the ep was purged while the callback was running, free the proxy request and return UCS_OK so UCT does not push it back onto the destroyed/failed TL ep.
  • Correspondingly relax ucp_wireup_ep_pending_purge() to only assert that no queued requests remain (i.e. ucs_assertv(wireup_ep->pending_count == 0, ...) guarded by the not-in-dispatch condition), with a descriptive ucs_assertv printing ucp_ep, wireup_ep, pending_count and flags for future triage.

This test is a flaky-but-real abort; rerunning will hide it, so it should be fixed rather than retried.

Related: none found (no existing issue/PR matches this assertion); nearest context PRs: #11988, #12360, #12274.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread src/ucp/proto/proto_repost.c Outdated
}

rkey = ucp_proto_repost_origin_rkey(origin);
if (origin->send.state.dt_iter.dt_class == UCP_DATATYPE_SGL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ucp_proto_repost_tl_rkey() is also called for PUT_SHORT/PUT_BCOPY/GET_BCOPY, but ucp_proto_repost_sgl_index()/ucp_proto_repost_sgl_contains() read info->rma.payload.zcopy.iov unconditionally, which is a different member of the rma.payload union for those ops. pls also require info->operation to be PUT_ZCOPY/GET_ZCOPY before taking this branch, so it cannot dereference a garbage iov if an SGL origin ever reports a non-zcopy fragment.

Comment thread src/ucp/rma/put_offload.c Outdated
{
ucp_request_t *req = ucs_container_of(self, ucp_request_t, send.uct);

if (ucs_unlikely(ucp_ep_config(req->send.ep)->key.err_mode ==

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

err_mode is part of ep_config_key and is already resolved at probe time for every other protocol (ucp_proto_common_init_check_err_handling). why not register the repost variant as its own proto (or store the send func in the priv) instead of branching on err_mode in every progress call?

Comment thread src/uct/ib/mlx5/rc/rc_mlx5_ep.c Outdated
status = uct_rc_mlx5_op_info_fill(iface, ep, txwq, pi, sgl_op, ctrl,
wqe_size, &callback_data, &info);
if (status == UCS_OK) {
if (sgl_op != NULL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: two adjacent checks of the same condition.

Suggested change
if (sgl_op != NULL) {
if (sgl_op != NULL) {
/* Each SGL element occupies one BB. Preserve this contract
* when changing the batch WQE layout. */
ucs_assert(wqe_size <= MLX5_SEND_WQE_BB);
info.field_mask |= UCT_EP_OP_INFO_FIELD_SGL_INDEX;
info.sgl_index = (uint16_t)(pi - sgl_op->sn);
/* The original reference keeps the SGL alive even when a
* replay callback completes a fragment synchronously. */
if (sgl_op->user_comp != NULL) {
++sgl_op->user_comp->count;
}
}

Comment thread test/gtest/ucp/test_ucp_rma.cc Outdated
}
}

unsigned m_errors = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

m_errors hides ucs::test_base::m_errors (the captured error-message vector used by num_errors() and by other tests in this file), pls rename to avoid the collision.

Suggested change
unsigned m_errors = 0;
unsigned m_num_ep_errors = 0;

Comment thread src/uct/api/v2/uct_v2.h Outdated
} atomic;
};

/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: pls use @ref UCT_EP_OP_INFO_FIELD_SGL_INDEX like the neighbouring fields, and add this field to the per-operation field list above (PUT_ZCOPY and GET_ZCOPY: ...) — otherwise there is no indication in the API docs that a transport may report it.

Comment thread src/ucp/proto/proto_repost.c Outdated
const ucp_proto_repost_priv_t *rpriv = req->send.proto_config->priv;
const uct_ep_op_info_t *info = req->send.repost.info;
uct_rkey_t tl_rkey = UCT_INVALID_RKEY;
size_t sgl_index = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: = should align with the lines above (docs/CodeStyle.md: "the longest left-hand side gets one space before =, others align to it"); same for the &sgl_index continuation line at 662, which is one column past the opening paren.

Suggested change
size_t sgl_index = 0;
size_t sgl_index = 0;

@svc-nvidia-pr-review

Copy link
Copy Markdown

Notes on what I checked and did not report:

  • Reference counting of the SGL batch completion is consistent: the extra ++user_comp->count taken before params->cb() is balanced either by the repost request completion or by ucp_ep_tf_outstanding_cancel_cb() when ucp_proto_repost_submit() fails, and the original reference is released at the CQ-update WQE. uct_completion_update_status() keeps the error over the UCS_OK passed for the original reference.
  • batch->first_index is captured before ucp_datatype_iter_copy_position() advances dt_iter.offset, so it is correct for both the batch and restart paths; memcpy into batch->indices is bounded because the fragment path caps count at UCP_MAX_IOV.
  • The widened uct_rc_mlx5_send_op_is_put_zcopy()/is_get_zcopy() predicates are consistent with uct_rc_mlx5_ep_outstanding_release_send_op() (lines 1806-1831), so the SGL send op is returned to the pool and RDMA-read credits are accounted.
  • ucp_worker_init_mpools() cleanup labels unwind in reverse order, and sgl_repost_mp chunks are allocated lazily, so the new pool costs nothing for workers that never fail over.
  • Residual coverage gap: ucp_proto_repost_sgl_index()'s legacy (no batch metadata) branch is not exercised by any test — all new UCP tests go through a batch completion with UCT_EP_OP_INFO_FIELD_SGL_INDEX set.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread test/gtest/ucp/test_ucp_rma.cc Outdated
};

virtual const char *get_protos() const {
return "put/sgl/offload,reconfig";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blocker: PROTOS is an allow-list, so this disables the repost protocol and ucp_proto_repost_submit() fails with UCS_ERR_UNREACHABLE — token-mode replay can never succeed here.

Suggested change
return "put/sgl/offload,reconfig";
return "put/sgl/offload,repost,reconfig";

Comment thread src/uct/ib/mlx5/rc/rc_mlx5_ep.c Outdated
if (sgl_op != NULL) {
/* Each SGL element occupies one BB. Preserve this contract
* when changing the batch WQE layout. */
ucs_assert(wqe_size <= MLX5_SEND_WQE_BB);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls use ucs_assertv_always() like the other WQE-parsing invariants in this file; in a release build a layout change would silently map sgl_index to the wrong element and replay it to the wrong remote address.

Suggested change
ucs_assert(wqe_size <= MLX5_SEND_WQE_BB);
ucs_assertv_always(wqe_size <= MLX5_SEND_WQE_BB,
"wqe_size=%zu", wqe_size);

Comment thread src/uct/api/v2/uct_v2.h Outdated
* - PUT_ZCOPY and GET_ZCOPY: @ref UCT_EP_OP_INFO_FIELD_RMA with @a rma.field_mask =
* @ref UCT_EP_OP_INFO_RMA_FIELD_REMOTE_ADDR |
* @ref UCT_EP_OP_INFO_RMA_FIELD_RKEY | @ref UCT_EP_OP_INFO_RMA_FIELD_PAYLOAD_ZCOPY.
* @ref UCT_EP_OP_INFO_FIELD_SGL_INDEX optionally identifies the element

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls also document the completion ownership here: with an SGL batch the callback gets one reference on @a comp per reported element and the transport releases its own. A consumer that completes @a comp once per batch, as it would for a single operation, leaves the count unbalanced.

Comment thread src/ucp/proto/proto_repost.c Outdated
return UCS_ERR_INVALID_PARAM;
}
index = (batch->first_index != SIZE_MAX) ?
batch->first_index + info->sgl_index :

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

how can we be sure sgl_index holds the correct value? uct, psn?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

maybe repost the whole sgl?

Comment thread src/ucp/core/ucp_worker.c Outdated
@@ -2415,6 +2416,11 @@ static ucs_status_t ucp_worker_init_mpools(ucp_worker_h worker)
goto err_rkey_mp_cleanup;
}

status = ucp_proto_repost_init_mpool(worker);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why do we need an mpool here? is it reg'ed? maybe malloc?

@svc-ucx

svc-ucx commented Nov 20, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (AddressSanitizer gpu on worker 2) · commit b601a9bc

TL;DR: The ASAN GPU gtest run failed because two of the PR's own new tests — rcx/test_ucp_rma_sgl_failover.put_lane_failure/3 (rc_x/cuda/put/sw) and rcx/test_ucp_rma_sgl_failover.put/5 (rc_x/cuda/put/token) — failed, while all host-memory variants of the same tests passed; the regression is in the new per-element SGL replay/handle-resolution code added by this PR, which can't resolve a valid local memh / remote rkey for a CUDA element on the replay lane, so the replayed PUT is aborted instead of landing.

Full analysis

Summary: make test in the AddressSanitizer GPU job exited non-zero: 2 FAILED TESTS out of 10816 — both are the SGL failover acceptance tests introduced by this PR, only in their CUDA variants.

Root cause: From the job log: [ FAILED ] rcx/test_ucp_rma_sgl_failover.put_lane_failure/3, where GetParam() = rc_x/cuda/put/sw and [ FAILED ] rcx/test_ucp_rma_sgl_failover.put/5, where GetParam() = rc_x/cuda/put/token, followed by make: *** [Makefile:5017: test] Error 1. The variant numbering in test_ucp_rma_sgl_failover (test/gtest/ucp/test_ucp_rma.cc:1879-2054, memtype at index 1, failover mode at index 3) means variants 3 and 5 are cuda/sw and cuda/token; the host counterparts (2 and 4) and all peer-mode variants passed. So the failure is specific to device memory under FAILOVER_MODE, i.e. the replay path this PR rewrote:

  • ucp_proto_repost_sgl_index() resolves the SGL element from the batch metadata (batch->first_index / batch->indices, src/ucp/proto/proto_repost.c:408-494), and ucp_proto_repost_zcopy_memh() then requires memh->md_map & UCS_BIT(md_index) for the new lane's MD (proto_repost.c:578-589), with ucp_proto_repost_tl_rkey() requiring rkey->md_map & UCS_BIT(dst_md_index) (proto_repost.c:546-553). A CUDA element is registered on a narrower MD set than a host element, so these checks return UCS_ERR_UNREACHABLE, ucp_proto_repost_abort() completes the origin with an error, and the test's ASSERT_UCS_OK(status) / ASSERT_EQ(0u, m_num_ep_errors) / guard-byte comparison fail.
  • Contributing asymmetry: ucp_proto_put_sgl_offload_progress() reroutes to the repost (batch-identity) send under UCP_ERR_HANDLING_MODE_FAILOVER (src/ucp/rma/put_offload.c:485-501), but the sw protocol ucp_proto_put_sgl_offload_sw_progress() (put_offload.c:559-589) always posts with the origin completion and no elem_indices, so its replayed fragments fall into the "legacy" address-scan branch (proto_repost.c:472-491), which rejects anything ambiguous — exactly the cuda/put/sw case that failed.
  • Note: the per-test assertion text is not visible because the Azure log is truncated to the tail; the failure attribution above comes from the test list, the variant mapping in the test source, and the new code paths.

Implicated commit: fc7e75f5 "UCP/PROTO: Resolve SGL replay handles per element" (Leonid Genkin), with follow-ups 8aa4209b, 50b31bde, b601a9bc; tests added in 0feb91eb.

File: src/ucp/proto/proto_repost.c:578 (and :546, :472-491); src/ucp/rma/put_offload.c:573; src/ucp/proto/proto_multi.inl:562 (batch post passes elem_indices = NULL).

Suggested fix:

  1. In ucp_proto_repost_zcopy_memh() / ucp_proto_repost_tl_rkey(), don't fail the replay when the per-element CUDA memh/rkey isn't registered on the replay lane's MD — either register/look up the element's handle for the new MD, or restrict replay lane selection to lanes whose MD is present in memh->md_map & rkey->md_map for the resolved element (fall back to the origin protocol's lane selection instead of UCS_ERR_UNREACHABLE).
  2. Give ucp_put_sgl_offload_sw_proto the same failover routing as the native proto: have ucp_proto_put_sgl_offload_sw_progress() use ucp_proto_put_sgl_offload_repost_post (so each fragment carries elem_indices/batch identity) when ucp_ep_config(req->send.ep)->key.err_mode == UCP_ERR_HANDLING_MODE_FAILOVER, removing reliance on the ambiguous address-scan branch.
  3. Reproduce locally with UCX_LOG_LEVEL=debug ./gtest --gtest_filter='rcx/test_ucp_rma_sgl_failover.*cuda*' and grep for the repost %p: ... debug lines (missing or invalid SGL batch index, fragment does not match any SGL element, ambiguous SGL elements) to confirm which branch rejects the replay.

Related: PR #12404 (this PR); related SGL/failover work: #12379, #12191, #11871.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread src/ucp/rma/flush.c

ucp_trace_req(req, "flush restart");
ucs_assert(req->send.flush.sw_state == UCP_FLUSH_SW_STATE_RESTART_PENDING);
if (ucp_ep_flush_defer_recovery(req)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this re-arms the oneshot and signals the worker on every progress iteration until recovery ends, so a worker blocked in ucp_worker_wait() spins for the whole recovery (up to RECOVERY_RETRIES × keepalive interval). ucp_ep_flush_defer_recovery() calls ucp_ep_flush_schedule_restart(), which re-adds the one-shot callback and calls ucp_worker_signal_internal(); the pre-existing ucp_ep_flush_request_resched() pattern re-arms but does not signal. Can we schedule the restart once from the recovery completion path, or at least skip ucp_worker_signal_internal() when only re-deferring?

Comment thread src/ucp/rma/put_offload.c Outdated
{
if ((req->flags & UCP_REQUEST_FLAG_PROTO_INITIALIZED) &&
(req->send.state.uct_comp.count != 0) &&
ucp_ep_err_mode_eq(req->send.ep, UCP_ERR_HANDLING_MODE_FAILOVER)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why is the deferral restricted to failover mode? the wireup replay path (ucp_wireup_replay_pending_requests() → ucp_proto_request_restart()) restarts pending requests in other modes too (CM lane / UCX_PROTO_REQUEST_RESET=y), and there the ucp_ep_err_mode_eq() guard makes the function fall through to ucp_proto_offload_zcopy_reset(), which deregisters the SGL memory and rewinds dt_iter while posted batches may still reference it.

/* Model a posted batch whose completion arrives after recovery. */
++req->send.state.uct_comp.count;
auto *memhs = req->send.state.dt_iter.type.sgl.memhs;
uct_ep_pending_purge(ucp_ep_get_lane(ep, req->send.lane),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pls assert the request is really pending before this, e.g. ASSERT_NE(UCP_NULL_LANE, req->send.lane); otherwise ucp_ep_get_lane() reads out of the lanes array when the request was fully posted. ucp_proto_multi_request_init() sets req->send.lane = UCP_NULL_LANE under ENABLE_ASSERT, so a fully posted request hits ucs_assertv(lane_index < UCP_MAX_LANES) in debug and reads out of bounds in release.

auto lanes = get_lanes(TEST_OP_PUT);
auto mem_type = static_cast<ucs_memory_type_t>(get_variant_value(1));
sgl_ctx ctx;
std::vector<size_t> sizes = pending ? std::vector<size_t>(2048, 4096) :

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: 2048 elements means ~4k buffer allocations + registrations per instance (plus rkey pack/unpack per element, for 3 of the 4 scenarios, and also for CUDA). a few hundred elements should already exceed the QP length and leave the request pending.

Comment thread src/ucp/core/ucp_worker.h
unsigned ep_init_flags,
ucp_worker_cfg_index_t *cfg_index_p);

ucs_status_t ucp_worker_reconfigure_rkey(ucp_worker_h worker,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: continuation lines are off by one space — indented to column 40 instead of 41, i.e. not aligned on the open parenthesis as required by docs/CodeStyle.md ("Indent function arguments on column"):

Suggested change
ucs_status_t ucp_worker_reconfigure_rkey(ucp_worker_h worker,
ucs_status_t ucp_worker_reconfigure_rkey(ucp_worker_h worker,
ucp_worker_cfg_index_t rkey_cfg_index,
ucp_worker_cfg_index_t ep_cfg_index,
ucp_worker_cfg_index_t *new_cfg_index);

same for the definition in ucp_worker.c (and pls keep a single blank line between functions there).

@svc-nvidia-pr-review

Copy link
Copy Markdown

Residual coverage gaps: the early-return path of ucp_worker_reconfigure_rkey() (key.ep_cfg_index == ep_cfg_index) is only exercised indirectly by the last assertion of reconfigure_rkey_distances; nothing covers ucp_ep_flush_defer_recovery() being reached from ucp_ep_flush_lanes_internal() (flush submitted while recovery is already armed) — the new tests all submit the flush before the failure.

@svc-ucx

svc-ucx commented Nov 21, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (Tests BlueField on worker 1) · commit a3b438d2

TL;DR: The BlueField gtest shard aborted on a debug assertion in ucp_ep_flush_request_resched() (!req->send.flush.started_lanes, started_lanes=0x5) during shm_ib/test_ucp_fault_tolerance.target_failure/10 <shm,ib/AM|FLUSH>; in FAILOVER mode lanes are flushed one at a time, so a replayed flush request legitimately has started lanes, and the strict assert must be replaced by the failover-aware ucp_ep_flush_assert_started_p2p() check (already proposed in PR #12389).

Full analysis

Summary: gtest shard 2 of 4 crashed (core dumped, make: *** [Makefile:5017: test] Aborted) on flush.c:431 assertion failure in the fault-tolerance AM+FLUSH test.

Root cause: The test performs ucp_am_send_nbx + ucp_ep_flush_nbx (test_ucp_fault_tolerance.cc:727) and then injects a lane failure via uct_ep_invalidate. Recovery runs ucp_wireup_replay_pending_requests() (src/ucp/wireup/wireup.c:2068), which sets UCP_EP_FLAG_BLOCK_FLUSH and replays the queued pending requests. The flush request takes the else branch at wireup.c:2059 → ucp_request_send() → ucp_ep_flush_progress_pending() (flush.c:469) → ucp_ep_flush_request_resched(). There, because ucp_ep_config(ep)->p2p_lanes is non-zero and config.ext.proto_request_reset is enabled, the code takes the strict branch at flush.c:431 and asserts started_lanes == 0. That invariant is false under UCP_ERR_HANDLING_MODE_FAILOVER: recovery switches one lane at a time, so the flush has already been started on the two still-live lanes (started_lanes=0x5). The relaxed, failover-aware check ucp_ep_flush_assert_started_p2p() (flush.c:390-422), which explicitly tolerates this case, is only reachable from the else branch — the condition ordering at flush.c:428-430 bypasses it. The crash is assert-only (debug/gtest build), not a data-corruption bug, but it hard-fails CI. HEAD commit a3b438d2 ("Restart the original SGL request on failover") touches both flush.c and this test and makes the replay path reachable with proto_request_reset.

Implicated commit: [REDACTED:Hex High Entropy String] — Leonid Genkin, "UCP/RMA: Restart the original SGL request on failover" (PR #12404); invariant originally added in 7561177 / 15c3ed9 (Evgeny Leksikov)

File: src/ucp/rma/flush.c:428-440 (assert fires at src/ucp/rma/flush.c:431); triggered from src/ucp/wireup/wireup.c:2059 and src/ucp/wireup/wireup.c:2068

Suggested fix: Make the failover mode take the relaxed path in ucp_ep_flush_request_resched() — i.e. check ucp_ep_err_mode_eq(ep, UCP_ERR_HANDLING_MODE_FAILOVER) before the proto_request_reset/p2p_lanes condition:

if (ucp_ep_err_mode_eq(ep, UCP_ERR_HANDLING_MODE_FAILOVER)) {
    /* Recovery switches lanes one at a time, so a flush may already be
     * started on the remaining live lanes. */
    ucs_assertv(!(UCS_BIT(req->send.lane) & req->send.flush.started_lanes),
                "req=%p lane=%d started_lanes=0x%" PRIx64, req,
                req->send.lane, req->send.flush.started_lanes);
    ucp_ep_flush_assert_started_p2p(ep, req);
} else if (ucp_ep_has_cm_lane(ep) || (...proto_request_reset...)) {
    ucs_assertv(!req->send.flush.started_lanes, ...);
} else {
    ...
}

This is exactly what PR #12389 does; rebase this PR on it (or cherry-pick it) and re-run the BlueField job. Keep the sw_state == UCP_FLUSH_SW_STATE_NOT_STARTED assertion unchanged.

Related: #12389 (fix: "UCP/FLUSH: Allow started lanes on failover resched with request reset"), #12404 (this PR), #11210, #12274

🛡️ This comment had 1 potential secret(s) redacted (Hex High Entropy String). See request_id 384e6654-a3fa-4053-87ba-f8a7210f5c2d in the triage console for the audit trail.

@svc-nvidia-pr-review

Copy link
Copy Markdown

🤖 Starting review — findings will be posted here when done.

Comment thread src/ucp/rma/put_offload.c
static ucs_status_t ucp_proto_put_sgl_offload_reset(ucp_request_t *req)
{
if ((req->flags & UCP_REQUEST_FLAG_PROTO_INITIALIZED) &&
(req->send.state.uct_comp.count != 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

how do we know the posting reference is still held here? count != 0 is also true after the last fragment was posted (the extra ref is dropped by ucp_request_invoke_uct_completion_success()), and in that state this drops a reference we don't own and would complete the request while batches are still in flight. pls add an assertion for this invariant.

Comment thread src/ucp/rma/flush.c

static void ucp_ep_flush_schedule_restart(ucp_request_t *req)
{
int signal = req->send.flush.sw_state != UCP_FLUSH_SW_STATE_RESTART_PENDING;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

when we re-arm from ucp_ep_flush_failover_oneshot_cb() the state is already RESTART_PENDING, so no wakeup is sent. what wakes a worker blocked in ucp_worker_wait() to run the re-armed callback?

UCP_DT_LOCAL_SGL_FIELD_BUFFERS);
sgl.lengths = sgl_array(ctx.lengths, ctx.null_local_arrays,
UCP_DT_LOCAL_SGL_FIELD_LENGTHS);
sgl.memhs = sgl_array(ctx.memhs, ctx.null_local_arrays,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: the moved helper sets memhs even when UCP_DT_LOCAL_SGL_FIELD_MEMHS is not in field_mask (the original had that guard), so tests that clear the flag no longer pass NULL. pls keep the guard.

remote_addr, rkey, clear_param_mask,
null_remote, remote_count);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor: pls remove the extra blank lines.

Suggested change
};

@svc-nvidia-pr-review

Copy link
Copy Markdown

Residual coverage gap: nothing exercises ucp_proto_put_sgl_offload_reset() reaching the deferred path with count == 1 (posting reference only), where the inline ucp_invoke_uct_completion() re-enters ucp_proto_request_restart() for the same request from inside proto->reset().

@svc-ucx

svc-ucx commented Nov 22, 2026

Copy link
Copy Markdown

🤖 CI Triage Agent — UCX PR (Tests roce on worker 2) · commit 2740acaf

TL;DR: The gtest rcx/test_ucp_sgl_restart.lane_failure/3 aborted on the assertion !req->send.flush.started_lanes in ucp_ep_flush_request_resched() (src/ucp/rma/flush.c:435) — that assert is too strict for FAILOVER endpoints, where a flush can legitimately already be started on healthy lanes when its pending request is replayed during lane recovery; relax it (as done in the already-open PR #12389) instead of asserting zero started lanes.

Full analysis

Summary: make test aborted (core dumped) in rcx/test_ucp_sgl_restart.lane_failure/3 <rc_x,cuda_copy,rocm_copy/sw_sw/host> with flush.c:435 Assertion '!req->send.flush.started_lanes' failed: req=0x55fc8cecfc80 flush started_lanes=0x5.

Root cause: Backtrace: ucp_wireup_eps_progress → ucp_wireup_replay_pending_requests → ucp_wireup_replay_pending_request (wireup.c:2059) → ucp_request_send → ucp_ep_flush_progress_pending (flush.c:473) → ucp_ep_flush_request_resched (flush.c:435). ucp_wireup_replay_pending_requests() sets UCP_EP_FLAG_BLOCK_FLUSH (wireup.c:2068) before replaying queued requests, so the replayed EP-flush request lands in the BLOCK_FLUSH path of ucp_ep_flush_request_resched(). Because the rc_x endpoint has p2p lanes and proto_request_reset is enabled, it takes the strict branch at flush.c:432-437, which asserts that no lane has started flushing. In this failover scenario the flush had already been started on lanes 0 and 2 (started_lanes=0x5) before the lane failure/recovery, which is a legal state — the relaxed, failover-aware check already exists in ucp_ep_flush_assert_started_p2p() (flush.c:401-413, "Recovery switches lanes one at a time, so another lane may already be on the transport with a flush in progress"), but it is only reachable from the else branch at flush.c:438-444. So the assertion, not the data flow, is wrong. The new test added by this PR (test_ucp_sgl_restart::test_restart posts ucp_ep_flush_nbx() immediately after the SGL put, test_ucp_fault_tolerance.cc:1694-1695) is what exposes it.

Implicated commit: 2740aca "UCP/RMA: Harden SGL restart and CUDA failover coverage" (Leonid Genkin) adds the exposing test; the faulty assertion comes from the failover flush work on src/ucp/rma/flush.c (lineage: 7561177 / d513f98, Evgeny Leksikov / nbellalou).

File: src/ucp/rma/flush.c:435 (triggered via src/ucp/wireup/wireup.c:2059, test at test/gtest/ucp/test_ucp_fault_tolerance.cc:1795/1694)

Suggested fix: Make the BLOCK_FLUSH resched check failover-aware — check ucp_ep_err_mode_eq(ep, UCP_ERR_HANDLING_MODE_FAILOVER) first and in that case assert only that the request's own lane has not started (!(UCS_BIT(req->send.lane) & req->send.flush.started_lanes)) plus call ucp_ep_flush_assert_started_p2p(ep, req), keeping the strict !started_lanes assert for the non-failover cm-lane / proto_request_reset path. Concretely, pick up / rebase onto PR #12389 ("UCP/FLUSH: Allow started lanes on failover resched with request reset"), which targets exactly this assertion, then re-run the roce worker-2 job.

Related: #12389 (fix for this assert), #12404 (this PR)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP-DNM Work in progress / Do not review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants