In this article
A nonblocking return is not always an outstanding request; callback timing and immediate completion must share one explicit ownership protocol.
Nonblocking does not mean a live request exists
A wrapper stores every nonblocking send return value as a request pointer and waits for a callback to release its source buffer. Some operations never call that callback, while an error value can be mistaken for a pointer. The problem is an incorrect return-state model. UCX NBX operations can report immediate completion, an encoded error or an outstanding request, and the wrapper must discriminate before assigning ownership.
Read the operation-specific return contract
The UCP public API header documents tagged send completion when the source buffer may safely be reused. Immediate success returns without invoking the normal deferred completion callback. A scheduled operation instead returns a request handle, and an encoded error is detected through the documented status-pointer mechanism. These cases cannot share a path that dereferences every non-null value or waits for a callback after every successful call.
Connect callback fields to their validity mask
The callback definitions specify a completed request, completion status and user data for NBX sends. The API’s operation-attribute mask determines which parameter fields are supplied. Initializing a callback field while omitting its validity bit does not establish a callback contract. Preserve the operation’s exact parameter mask and status handling, and distinguish a local send buffer becoming reusable from the remote application consuming or committing the message.
Forced request completion can be reentrant
The API documents that NO_IMM_CMPL prevents a null immediate-completion return, but a supplied callback can run before the function returns. Therefore, forcing a request does not guarantee that completion arrives later on another thread. Initialize completion state before calling UCX, and coordinate ownership so an early callback and the return path cannot both release the same application resource. A wrapper that registers its pending entry only after return can lose an already delivered completion.
Test each state transition
An isolated integration should cover immediate success, deferred completion, an encoded error and the supported early-callback case. Track buffer ownership, callback count, request cleanup and application completion exactly once. Exercise shutdown with pending work rather than letting process exit hide unreleased request state. Acceptance requires a coherent state transition for each outcome, not a chosen payload size that happens to avoid immediate completion. Do not fabricate which transport always produces each outcome; scheduling and selected protocols can vary.
Bound the reuse guarantee
The successful tagged-send completion boundary concerns safe local reuse under that operation’s contract. It does not establish remote application durability or permit changing unrelated receive buffers. The verbs completion guide supplies background on posting versus completion, while registration lifetime explains the underlying resource boundary. The useful wrapper centralizes the three outcomes and reentrant callback handling so transport changes cannot silently introduce double release, indefinite waiting or reuse of a still-live source buffer.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.