Skip to content

UCP/EP/FT: lanes auto recovery after failure, WIP - #11379

Closed
evgeny-leksikov wants to merge 33 commits into
openucx:masterfrom
evgeny-leksikov:ucp_ft_recovery_poc_wip
Closed

evgeny-leksikov wants to merge 33 commits into
openucx:masterfrom
evgeny-leksikov:ucp_ft_recovery_poc_wip

Conversation

@evgeny-leksikov

@evgeny-leksikov evgeny-leksikov commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

What?

POC implementation of lanes auto recovery after failure
Inctoduce new parameters to control interval and retries:
UCX_RECOVERY_INTERVAL=5000000.00us
UCX_RECOVERY_RETRIES=inf

Why?

Fault tolerance improvements

How?

Introduce new wireup-like handshake: re-create failed UCT lanes and exchange their addresses by live AM lane

Note

continue of #11371 by rebase on top of master and fix wireup compatibility + more improvements

upstreaming progress:

@evgeny-leksikov
evgeny-leksikov force-pushed the ucp_ft_recovery_poc_wip branch from 3ec8382 to 1c44452 Compare May 4, 2026 15:19
@openucx openucx deleted a comment from svc-nixl May 4, 2026
evgeny-leksikov and others added 9 commits May 5, 2026 13:18
The lane-change adjustment block in ucp_ep_flush_progress, introduced
when num_lanes was replaced with the all_lanes bitmap, had two issues:

1. req->send.flush.all_lanes was updated only via OR with new lanes, so
   destroyed-lane bits stayed in all_lanes. On a subsequent EP
   reconfiguration (e.g. wireup CM swap rdmacm->tcp) the same destroyed
   lane was detected again and uct_comp.count was decremented a second
   time, eventually tripping the count >= 0 assertion when remaining
   lane flushes completed.

2. ep_destroyed_lanes was not masked with ~started_lanes, so a started
   lane that subsequently disappeared would also be subtracted from
   uct_comp.count even though it was already accounted for - either by
   the synchronous-OK decrement, by ucp_ep_flush_error, or by the
   pending uct completion delivered via the discard flow.

Mask ep_destroyed_lanes with ~started_lanes and resync all_lanes to
ep_live_lanes after each adjustment, restoring the invariant the
previous num_lanes-based code maintained.

Co-authored-by: Cursor <cursoragent@cursor.com>
… superset

The previous loop condition `started_lanes != ep_live_lanes` is true
whenever the two bitmaps differ, including the case where started_lanes
is a strict superset of ep_live_lanes (a lane was started and then
destroyed). In that case `ep_live_lanes & ~started_lanes` is 0, and the
ucs_ffs64(0) call inside the loop body invokes UB on x86_64 (bsfq with
a zero input), producing a garbage lane index that subsequently feeds
ucp_ep_get_lane() out of bounds.

Cache the unstarted-live-lane bitmap into next_lanes and use
`(next_lanes != 0)` as the loop condition. This safely handles the
superset case (loop exits cleanly) and also avoids re-computing
`ep_live_lanes & ~started_lanes` twice per iteration.

Co-authored-by: Cursor <cursoragent@cursor.com>
ucp_worker_discard_tl_uct_ep() short-circuits for failed-stub UCT EPs
to avoid inserting them into the worker discard hash. Previously it
returned UCS_OK without invoking uct_ep_destroy() on the stub, breaking
the caller-side invariant "ucp_worker_discard_uct_ep() takes ownership
of uct_ep". All callers in the code base subsequently NULL or overwrite
the lane slot the stub came from (see e.g. ucp_wireup_check_config_intersect
in src/ucp/wireup/wireup.c), which orphaned the stub:

  - The stub is no longer referenced by any lane slot.
  - It was never inserted into the worker discard hash (correct).
  - Its iface ep_destroy hook (ucp_ep_failed_destroy) is therefore
    never invoked.

Per-failover stubs are members of a heap-allocated
ucp_ep_discard_lanes_arg_t whose destroy_counter is decremented only
through ucp_ep_failed_destroy(). With the destroy never invoked, the
counter never reaches zero and the discard_arg is leaked. AddressSanitizer
reports this as a 32-byte leak from src/ucp/core/ucp_ep.c:1546
("discard_lanes_arg") on tests that exercise FAILOVER mode against a
subsequent wireup reconfiguration.

Restore the ownership invariant by invoking uct_ep_destroy() on the
stub. ucp_ep_failed_destroy() already returns early for the shared
&ucp_failed_tl_ep_discard_arg, so this is safe for both per-failover
and global stubs. The stub still does not enter the discard hash, so
the original concern that motivated the short-circuit is preserved.

Co-authored-by: Cursor <cursoragent@cursor.com>
For variants with TEST_OP_ALL_LANES_FAILED the test invalidates every
am_bw lane in sequence and expects every per-lane invalidation to
remain visible in the EP's failed_lanes set when the next one fires.
With the default 100ms RECOVERY_INTERVAL, recovery clears each lane's
UCP_LANE_TYPE_FAILED bit between consecutive injections, so failed_lanes
never accumulates within a single invalidation pass.

Set RECOVERY_INTERVAL to ucs::test_timeout_in_sec for these variants in
init() so that no recovery round fires during the injection loop and
the failed-lane bitmap captures every injection. modify_config() runs
after the UCS_TEST_P annotations are applied (the wrapper-generated
init() runs UCS_TEST_SET_CONFIG before calling our init()), so this
override wins over the test's RECOVERY_INTERVAL=100ms annotation only
for variants that opt in.

Also drop the now-obsolete UD-side num_lanes_to_fail decrement in
test_am_with_injected_failure: the value is recomputed inside the for
loop based on TEST_OP_ALL_LANES_FAILED, so the earlier shrink had no
effect.

Co-authored-by: Cursor <cursoragent@cursor.com>
In FAILOVER mode the EP keeps lanes that have been marked
UCP_LANE_TYPE_FAILED until recovery clears them. While in that state,
ucp_proto_common_find_lanes() filters them out of every protocol's lane
selection, so a feature whose lanes are all failed produces zero
matching real protocols and ucp_proto_select_init_protocols() falls back
to registering only the 'reconfig' stub for the affected operations.

When the user issues such an op after the failover, that stub's
progress runs and reaches the existing 'cannot find remote protocol'
abort path: the EP is REMOTE_CONNECTED, no real protocol can be found,
so the request is aborted with UCS_ERR_CANCELED. Until now the EP
itself was left in pending-recovery state - if recovery never succeeds
(or never gets a chance to run before the test deadline) the user
error callback never fires and the EP appears alive even though no
user feature can be served on it.

Schedule ucp_ep_set_lanes_failed(ep, 0, UCS_ERR_ENDPOINT_TIMEOUT) from
the same abort path. With lanes==0 this bypasses the FAILOVER recovery
branch in ucp_ep_set_lanes_failed() and falls straight through to
ucp_ep_set_failed(), which discards remaining lanes and invokes the
user error callback. The in-flight request is still aborted with
UCS_ERR_CANCELED as before. The UCP_EP_FLAG_FAILED guard avoids
scheduling extra callbacks when another path already started failing
the EP.

This piggybacks on proto selection's existing per-op lane-type filter
instead of maintaining a separate user-feature -> lane-type mapping at
the failure-detection site, so the feature -> service binding stays in
one place (the protocols themselves).

Co-authored-by: Cursor <cursoragent@cursor.com>
ucp_ep_recovery_find_iface_addr() used to return the first reachable
iface entry, which could silently migrate a recovered lane to a
different peer rsc when multiple peer devices are reachable from the
same local rsc.
@evgeny-leksikov evgeny-leksikov changed the title UCP/EP/FT: lanes auto recovery after failure, p2 UCP/EP/FT: lanes auto recovery after failure, WIP May 11, 2026
This commit adds a new internal flag, UCP_AM_HDR_FLAG_RESEND, to indicate that a first fragment header belongs to a restart of an already-identified message after a sender-side reset. This flag helps the receiver to discard any partial first receive descriptors left from previous multi-fragment attempts, ensuring in-order delivery and preventing message stranding.

Additionally, the implementation includes a new function to release long descriptors correctly, improving memory management during the assembly of message fragments. The changes enhance the handling of eager AM messages, particularly in scenarios involving fault recovery and retransmissions.
@evgeny-leksikov

Copy link
Copy Markdown
Contributor Author

Closing since everything from this PR is upstreamed in parts.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant