Skip to content

fix(sdk/python): prevent memory event websocket from blocking agent startup - #165

Merged
AbirAbbas merged 5 commits into
mainfrom
fix/memory-events-startup-hang
Jan 30, 2026
Merged

fix(sdk/python): prevent memory event websocket from blocking agent startup#165
AbirAbbas merged 5 commits into
mainfrom
fix/memory-events-startup-hang

Conversation

@AbirAbbas

Copy link
Copy Markdown
Contributor

Summary

  • Memory event client websocket connection was blocking the FastAPI startup handler, preventing uvicorn from ever binding to the port when the connection failed
  • Moved memory event connection to a background task (asyncio.create_task) so startup completes regardless of websocket connectivity
  • Added websockets v14+ compatibility: detect library version and use extra_headers (v14+) or additional_headers (v13 and below)

Test plan

  • Start agent without control plane running — verify uvicorn binds to port and shows "Application startup complete"
  • Start agent with control plane running — verify memory events connect in background
  • Test with websockets <14 and >=14 installed
  • CI passes

🤖 Generated with Claude Code

@AbirAbbas
AbirAbbas force-pushed the fix/memory-events-startup-hang branch from 42f34fe to 4f3191d Compare January 29, 2026 22:29
@github-actions

github-actions Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Performance

SDK Memory Δ Latency Δ Tests Status
Python 0.0 KB -100% 0.00 µs -100%

✓ 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
AbirAbbas force-pushed the fix/memory-events-startup-hang branch from 4f3191d to e75c272 Compare January 29, 2026 23:08
…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
AbirAbbas force-pushed the fix/memory-events-startup-hang branch from 57f4540 to 85aeb3a Compare January 29, 2026 23:50
AbirAbbas and others added 3 commits January 29, 2026 18:52
…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>
@AbirAbbas
AbirAbbas merged commit 4a63bec into main Jan 30, 2026
23 checks passed
@AbirAbbas
AbirAbbas deleted the fix/memory-events-startup-hang branch January 30, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant