fix(sdk): validate timeout before best-effort swallow in connections() (TS + Python)#120
Merged
Merged
Conversation
…) (TS + Python) - TS: connections() now validates the effective timeout before the catch-all fallback (parity with close()), so an invalid value (0, negative, NaN, Infinity) surfaces instead of silently returning the cached list. - Python: async connections() suppresses TimeoutError alongside ApiError on the best-effort read (parity with close() and the TS client); unrelated errors keep propagating. Behavior-preserving for valid inputs. Closes #118 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Two small hardening follow-ups to @AndreLFSMartins's timeout/cancellation work in #49 — picking these up as noted in #118 to finish the set, applied to the current code.
packages/core/src/session.ts):connections()now resolves and validates the effective timeout before the best-efforttry(same shape asclose()), so an invalidtimeout(0, negative, NaN, Infinity) rejects instead of being silently swallowed into the cached-list fallback. No request is issued for invalid values.packages/python/src/codespar/_async_session.py):connections()suppressesTimeoutErroralongsideApiErroron the best-effort read (parity withclose()and the TS client). Unrelated exceptions keep propagating. The sync client delegates to the async implementation, so one edit covers both.Tests added for both sides (invalid-timeout fail-fast + cached-fallback regression in Vitest; timeout→cache, empty-cache, and unrelated-error-propagates in pytest).
Behavior-preserving for valid inputs.
Closes #118
🤖 Generated with Claude Code