fix: add request timeouts and mask API key in repr#1262
Open
planetf1 wants to merge 1 commit into
Open
Conversation
Add explicit timeouts to two previously unbounded requests calls, and mask the API key in OpenAIBackend.__repr__ / __str__. Timeouts -------- RESTHandler.emit() uses timeout=2: this handler fires synchronously on every log event, so a slow or unreachable webhook endpoint would block the calling thread on every log write. 2 s is enough to confirm liveness; beyond that the record should be dropped. is_vllm_server_with_structured_output() uses timeout=10: this probe runs once at OpenAIBackend.__init__() time, not on every request, so a longer timeout costs nothing in throughput. vLLM's /version endpoint is trivial (no GPU path), but cloud or VPN round-trips can be slow; 10 s covers realistic slow-network cases while still failing fast on a dead server. A false timeout here silently degrades structured output behaviour, so erring toward patience is correct. API key masking --------------- __repr__ and __str__ previously inherited the default object repr, which could expose the API key in logs, exception messages, or debug output. Both now return *** in place of the key. Identified in the 2026-05-12 security audit. Closes generative-computing#1246 Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
e8ed118 to
465f56f
Compare
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.
Add explicit timeouts to two previously unbounded `requests` calls, and
mask the API key in `OpenAIBackend.repr` / `str`.
Timeouts
`RESTHandler.emit()` uses `timeout=2`: this handler fires synchronously
on every log event, so a slow or unreachable webhook endpoint would block
the calling thread on every log write. 2 s is enough to confirm liveness;
beyond that the record should be dropped.
`is_vllm_server_with_structured_output()` uses `timeout=10`: this probe
runs once at `OpenAIBackend.init()` time, not on every request, so a
longer timeout costs nothing in throughput. vLLM's `/version` endpoint is
trivial (no GPU path), but cloud or VPN round-trips can be slow; 10 s covers
realistic slow-network cases while still failing fast on a dead server. A
false timeout here silently degrades structured output behaviour, so erring
toward patience is correct.
API key masking
`repr` and `str` previously inherited the default object repr,
which could expose the API key in logs, exception messages, or debug output.
Both now return `***` in place of the key.
Identified in the 2026-05-12 security audit.
Closes #1246