fix(sdk/python): prevent memory event websocket from blocking agent startup - #165
Merged
Conversation
AbirAbbas
force-pushed
the
fix/memory-events-startup-hang
branch
from
January 29, 2026 22:29
42f34fe to
4f3191d
Compare
Contributor
Performance
✓ No regressions detected |
websockets v14+ renamed the `additional_headers` parameter to `extra_headers`. Since the SDK does not pin a websockets version, users installing fresh get v14+ and hit: create_connection() got an unexpected keyword argument 'additional_headers' This causes the memory event websocket connection to fail during agent startup, and the blocking reconnect retry loop (exponential backoff up to 31s) prevents uvicorn from completing initialization. - Detect websockets major version at import time and use the correct parameter name (extra_headers for v14+, additional_headers for older) - Update unit test mock to accept either parameter name Co-Authored-By: Claude <noreply@anthropic.com>
AbirAbbas
force-pushed
the
fix/memory-events-startup-hang
branch
from
January 29, 2026 23:08
4f3191d to
e75c272
Compare
…startup When the control plane websocket is unreachable, the memory event client's connect() method would block indefinitely during FastAPI startup due to exponential backoff retries (up to 31s). This prevented uvicorn from ever binding to its port. - Add 5s timeout to initial websocket connection attempt - Background the reconnect retry loop so startup completes immediately - Remove incorrect websockets version detection (additional_headers is correct for all modern versions v13+) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
AbirAbbas
force-pushed
the
fix/memory-events-startup-hang
branch
from
January 29, 2026 23:50
57f4540 to
85aeb3a
Compare
…cking reconnect - Test that v14+ uses additional_headers parameter - Test that pre-v14 uses extra_headers parameter - Test that failed connection backgrounds the retry loop instead of blocking Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace monkeypatched version tests with real version detection tests that validate against the actually installed websockets library. Add a websockets-compat CI job that runs memory events tests against both websockets 12.0 (extra_headers) and 15.0.1 (additional_headers) in parallel. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.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.
Summary
asyncio.create_task) so startup completes regardless of websocket connectivityextra_headers(v14+) oradditional_headers(v13 and below)Test plan
🤖 Generated with Claude Code