Skip to content

fix(model): add an optional connection retry time budget - #4853

Open
yaoyu-33 wants to merge 2 commits into
mainfrom
sync/bounded-connection-retries-20261021
Open

yaoyu-33 wants to merge 2 commits into
mainfrom
sync/bounded-connection-retries-20261021

Conversation

@yaoyu-33

Copy link
Copy Markdown
Contributor

A static vLLM endpoint can retry connection errors indefinitely after its engine disappears. Add optional endpoint_connection_retry_timeout_s and shared-client connection_retry_timeout_s settings to stop those retries with the original connection error. The window starts at the first connection failure and applies to both initial and rebound endpoint clients; null preserves current behavior. Existing attempt limits still apply.

This is a focused opt-in control related to #3159; it does not change the default replay policy or claim to complete that broader issue. The patch covers shared transport/client plumbing, vLLM configuration, and regression tests.

Validation: 1,077 tests passed across test_server_utils.py, test_openai_utils.py, and the complete vLLM model suite, including real local refused-port checks. pre-commit run --all-files passed. Model rollout: N/A for this transport/configuration change; agent and verifier behavior is unchanged.

Propagate a nullable connection-error retry budget through the shared HTTP
client to initial and rebound vLLM endpoints. Preserve existing defaults and
raise the last connection error when the configured retry window expires.

Co-authored-by: Wojciech Prazuch <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 added the internal_sync Public PR created by internal-to-public sync automation label Oct 21, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:model Model servers, inference providers, and model adapters bug Something isn't working labels Oct 21, 2026
@wprazuch
wprazuch marked this pull request as ready for review October 26, 2026 10:23
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 26, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

HOLD — one BLOCKER compatibility regression and two RISK findings in the retry-budget implementation.

Completed inspection of all six changed files and their affected transport, shared-client, and vLLM endpoint paths. Initial and rebound vLLM clients receive the setting correctly, but the public request signature changes positional behavior, and the configured window can be bypassed by pending reconnects or restarted by HTTP-status retries.

Static review only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

Comment thread nemo_gym/server_utils.py
url: str,
_internal: bool = False,
_max_connection_retries: Optional[int] = None,
_connection_retry_timeout_s: Optional[float] = None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BLOCKER — Preserve the existing positional request arguments.

Failure / blast radius: Inserting this option before _server_name shifts every subsequent positional argument in the public request() helper. For example, await request("POST", url, False, 2, "policy") previously selected two connection attempts and destination label policy (base signature). It now assigns "policy" to the timeout. On the first retriable ClientOSError, the deadline comparison raises TypeError, replacing the connection error instead of retrying. Consumers passing later positional controls are likewise remapped.

Correction: Restore the old positional order in request(). Remove the new parameter from its current location and add it after the existing controls as keyword-only:

    _resend_after_disconnect: bool = True,
    *,
    _connection_retry_timeout_s: Optional[float] = None,
    **kwargs: Unpack[_RequestOptions],

The inspected internal forwarding already uses keywords, so no dependent caller change is required. This preserves the public calling convention and follows the trusted guidance for new controls.

Preservation / acceptance — proposed, not run: With a mocked client always raising the same ClientOSError, the old positional example must make exactly two attempts and raise that original error, retaining policy as the destination label. Keyword timeout calls must still enforce the budget. Retain default-None retries, explicit total-attempt caps, and immediate failure of dropped connections when _resend_after_disconnect=False. Verify the suggested signature change before adoption.

Comment thread nemo_gym/server_utils.py
if _max_connection_retries is not None and retries >= _max_connection_retries:
raise
first_connection_error_at = first_connection_error_at or time.monotonic()
if _connection_retry_deadline_passed(first_connection_error_at, _connection_retry_timeout_s):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RISK — Enforce the window while a reconnect is pending.

Failure / blast radius: The deadline is checked only after another connection exception arrives. With a one-second budget, let the first attempt immediately raise ClientConnectorError; after the 0.5-second backoff, let the next connection acquisition remain pending. The next client.request() await has no remaining-budget timeout, and Gym's shared session has neither a total nor connection timeout. Reconnection or pool-slot waiting can therefore outlive the configured window arbitrarily. This affects callers opting into the new budget; the refused-port tests cover only immediately failing attempts.

Correction: In _request_with_retries, save the last connection exception and use the remaining budget to bound subsequent connection acquisition, including pool waiting. On budget expiry, raise that saved exception. Check expiry before launching another retry and bound its backoff. Do not blanket-timeout the entire HTTP attempt: a successfully reconnected engine must still be allowed a long generation. Preserve stricter caller timeouts and cancellation. Exact ClientTimeout composition needs implementation verification, so no drop-in patch is suggested; the invariant is bounded reconnect waiting after the first failure without newly limiting successful inference.

Preservation / acceptance — proposed, not run: Add an integration regression whose first connection fails and whose second connector acquisition blocks beyond the budget; expect completion near the deadline with the saved connection exception, not TimeoutError. Separately establish the retry connection promptly but delay response headers beyond the budget; that response must still succeed. Check that None continues waiting, existing attempt caps still win, and no-replay dropped connections still raise immediately while never-connected failures remain retryable. Enforcing expiry before another attempt also requires updating the new 0.2-second dropped-connection test, whose current two-attempt assertion explicitly permits a post-expiry retry.

Comment thread nemo_gym/openai_utils.py
"_internal": self.internal,
"_max_num_tries": self.max_num_tries,
"_max_connection_retries": self.max_connection_retries,
"_connection_retry_timeout_s": self.connection_retry_timeout_s,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RISK — Keep one connection window across HTTP-status retries.

Failure / blast radius: This forwards a duration for every inner transport invocation, but _request_with_retry invokes request() again after a retryable HTTP status. Each invocation initializes a fresh first-error timestamp. For one logical call with a 1-second budget: a connection failure at t=100, an HTTP 503 at t=100.5 with Retry-After: 1, and another connection failure at t=101.5 start a new window instead of raising. Mixed connection/status failures therefore exceed the documented per-request window; continuously refused ports do not exercise this reset.

Correction: Create connection-budget state once per logical _request_with_retry invocation and retain its first-failure timestamp across its transport calls. Extend request(), _traced_request(), and _request_with_retries() to accept and propagate that state without forwarding it to aiohttp; direct transport callers should still receive fresh local state. Keep state local to the logical call, never on the reusable client. The state representation requires a coordinated interface change, so no standalone replacement line is suggested. The invariant is that a status retry cannot renew an already-started connection window.

Preservation: Do not turn this into a blanket deadline on inference or status backoff. Status-only 429/503 sequences must retain their existing wait budgets. Separate logical calls need independent windows; None, single-attempt mode, permanent-error handling, and per-attempt request/connect timeouts must remain unchanged.

Acceptance — proposed, not run: Add a deterministic integration regression using the t=100/100.5/101.5 sequence: the post-503 connection error must propagate without another connection backoff or attempt. A separate logical call must receive a fresh window. With a finite connection budget, retain the status-only case in test_a_429_with_retry_after_waits_that_long_then_succeeds: one 3-second sleep and success. Retain the transport-forwarding assertions for _max_num_tries=1, _max_connection_retries=2, and ClientTimeout(total=300, connect=60).

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

area:model Model servers, inference providers, and model adapters bug Something isn't working internal_sync Public PR created by internal-to-public sync automation needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants