📶 fix: Ride Out Transient Worker Status Failures Within the Worker's Lease - #16463
Merged
Merged
Conversation
Collaborator
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Before each turn that uses an attached (BYOM) code environment, LibreChat polls the Code API for the worker's status. Any failure of that one HTTP request, including a connect timeout at the proxy in front of the Code API, was treated as the machine being gone: the turn failed with "The attached code environment is unavailable. Reconnect the machine and try again." The poller also shares one in-flight request across concurrent turns, so a single blip failed every turn starting at that moment.
On one deployment the worker stayed connected and kept completing calls every minute, yet 5 turns failed within two minutes because 2 status requests from the cluster timed out connecting to Cloudflare's edge. That was 3 failed status requests out of 4,788 in a day, and each one cost the user a turn.
A transient transport failure (timeout, network error, or a 5xx from the Code API or its proxy) says nothing about the worker. The worker's own heartbeat lease does. The poller now remembers the last
readyobservation per base URL, worker and credential. When a poll fails transiently while that observation's lease is still running, the remembered status answers for it, with the lease time that remains. With no valid observation, the poll is retried once. Rejections (4xx), malformed responses and non-ready statuses fail as before and discard the remembered status. ThebypassCachepath, which validates a workspace selection before it is persisted, is unchanged and still gets exactly one fresh observation.How it works
The remembered lease is measured from when the request started, so it never outlives the lease the Code API reported. If the worker really disconnected, its lease runs out within about a minute and polls fail normally, and any workspace call made in the meantime still fails with its own typed error at execution.
Type of change
Testing
Tested environments/configuration:
Automated tests:
packages/api:npx jest src/code(402 passed, 1 skipped). New cases inbridge.spec.tscover each behaviour against the real poller with a scripted fetch:bypassCachenever uses it;npx tsc --noEmitinpackages/api; eslint on the changed files.