Repository navigation
fix(sdk): register agent event handlers before connect - #504
willwashburn wants to merge 1 commit into
Conversation
agent.on.<event>(...) threw "WebSocket not connected. Call connect() first." whenever a handler was registered before connect(), even though the underlying WsClient.on() never required a live socket. Split WsClient construction into a lazy ensureWs() that both on.* and connect() share, so handlers registered up front attach to the same instance connect() later opens. Fixes AgentWorkforce/skills#157. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to Pre-connect event registration is supported, and repeated connect calls do not open an additional socket. The change is ready to merge after normal checks. Pre-merge checks |
|
AgentClient.onregisters event handlers beforeconnect(). LazyensureWs()constructs the WebSocket client without opening a socket, andconnect()opens that same instance. Registering a handler does not open a socket.Fixes #492
Replaces draft #494.
Checks
npm run test:typesinpackages/sdk-typescript— passnpx vitest run src/__tests__/agent-ws.test.tsinpackages/sdk-typescript— 40 passedNeed help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
SDK-only behavior change that relaxes a prior error path; WebSocket open timing is unchanged and tests cover the new registration order.
Overview
The TypeScript SDK
AgentClientno longer requiresconnect()before registeringagent.on.*handlers. Previously those calls threw "WebSocket not connected. Call connect() first."A private
ensureWs()lazily builds the sameWsClientinstance (including open/close lifecycle wiring) without opening a socket;connect()only callsensureWs().connect(). Handlers registered early attach to that client and run after the socket opens. Registering handlers alone still does not create a WebSocket.Tests in
agent-ws.test.tswere flipped from expecting throws to covering pre-connect()registration for message, lifecycle, reconnect, and wildcard events. Root and package changelogs note this as an [Unreleased - Patch] fix.Reviewed by Cursor Bugbot for commit c021fe6. Bugbot is set up for automated code reviews on this repo. Configure here.