fix(tests): catch ConnectionError in WorkOS callback drain calls (Python 3.12+)#6
Merged
Merged
Conversation
…hon 3.12+) The callback-state tests open a localhost listener in a daemon thread, hit it via urllib.urlopen(), then call urlopen() once more to drain the listener so the daemon thread exits cleanly. The drain call only caught urllib.error.URLError. Python 3.12+ propagates raw ConnectionResetError unwrapped when the server thread closes the socket mid-read (in http.client._read_status). ConnectionResetError is a sibling of URLError under OSError, not a subclass, so it leaked through and crashed the test on the matrix's 3.12 / 3.13 jobs while 3.11 was forgiving. Surfaced as a flake on the feat/agent-context merge to main; same code passed on the PR run minutes earlier. Widen the except to (URLError, ConnectionError) at every drain site in the file. ConnectionError is the parent of all four ConnectionXxxError variants and is more semantically pointed than a broad OSError catch. The tests' actual assertions live on the threaded login result, not the urlopen response, so swallowing network errors on these specific drain calls is safe. Verified locally on Python 3.14 (4/4 pass) and via the rerun matrix once this lands.
6 tasks
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.
Why
feat/agent-context(#5) merged green on the PR but failed on the merge-to-main run, then again on a manual rerun — same code, different runs. Test:The failure is on Python 3.12 and 3.13 specifically; 3.11 is forgiving. Pure flake — none of the changes in #5 touched WorkOS auth or the localhost callback handler.
Root cause
The callback-state tests open a localhost listener in a daemon thread, hit it with urlopen, then call urlopen one more time to drain the listener so the thread exits cleanly. Each drain
try/exceptonly caughturllib.error.URLError.Python 3.12+ propagates raw
ConnectionResetErrorunwrapped (when the server thread closes the socket mid-response inhttp.client._read_status).ConnectionResetErroris a sibling ofURLErrorunderOSError— not a subclass. So it leaked through the except and crashed the test on 3.12/3.13.Fix
Widen the except at each of the 5 drain sites in the file from
URLErrorto(URLError, ConnectionError).ConnectionErroris the parent ofConnectionResetError,ConnectionAbortedError, etc., so it's semantically pointed (vs. catching the broaderOSError). The tests' real assertions live on the threaded login result, not the drainurlopenresponse — swallowing network errors on these specific calls is safe.Test plan
uv run pytest tests/test_auth/test_workos_callback_state.py -v— 4/4 pass locally on 3.14uv run pytest tests/ -q— full suite 432 pass, 5 skipped (no regression)