fix: cleaner tests, better error handling, and protocol improvements#1035
Merged
threepointone merged 2 commits intomainfrom Mar 1, 2026
Merged
fix: cleaner tests, better error handling, and protocol improvements#1035threepointone merged 2 commits intomainfrom
threepointone merged 2 commits intomainfrom
Conversation
Upgrade several dev dependencies (e.g. @types/node, lint-staged, partyserver and related lockfile updates) and propagate those version bumps across package.json files. Rename the state notification hook used in tests and test agents from onStateUpdate to onStateChanged (including helper names, error messages and test strings). Change Agent warning behavior to only warn about sendIdentityOnConnect when custom routing could leak identity (checks URL path), and move the experimental forever API warning from module top-level to the Agent constructor so it only logs when instantiated.
Multiple fixes and improvements across MCP, agent SQL handling, docs, and tests: - Return JSON-RPC -32600 error for malformed RPC messages instead of throwing, aligning with JSON-RPC 2.0 and updating RPC transport tests. - McpAgent now suppresses agent protocol frames (identity/state/MCP servers) for MCP bridge connections by detecting the MCP method header. - Removed noisy CORS one-time warning about Authorization with wildcard origin. - Make this.sql throw SqlError directly (includes query) so SQL errors can be caught without double-logging or being swallowed by onError. - Remove an explicit transaction in the in-memory session provider; rely on Durable Objects' synchronous I/O batching and simplify writes. - Update sendIdentityOnConnect warning text to clarify when instance names are sent and how to opt out. - Rename doc reference from onStateUpdate to onStateChanged. - Tests: assert JSON-RPC error responses and close WebSocket connections in routing tests to avoid teardown logs. These changes tighten protocol behavior, improve error semantics, reduce noisy warnings, and stabilize tests.
🦋 Changeset detectedLatest commit: 0cd330c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
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
This PR improves error handling, reduces test noise, and fixes several protocol-level issues across the Agent and MCP subsystems.
Changes
Agent core (
src/index.ts)this.sqlthrowsSqlErrordirectly — Previously, SQL errors were routed throughthis.onError(), which logged the error and re-threw it, causing confusing double error logs. Nowthis.sqlwraps failures inSqlErrorand throws directly.onErroris reserved for WebSocket connection errors and unhandled server errors.sendIdentityOnConnectwarning rewritten — The warning is now informational rather than a deprecation notice. It only fires when using custom routing (where the instance name is not visible in the URL), and tells the developer the exact name being sent. The old warning fired on every agent class regardless of routing.MCP subsystem (
src/mcp/)JSON-RPC error responses (
rpc.ts) —RPCServerTransport.handle()now returns a proper JSON-RPC-32600 Invalid Requesterror response for malformed messages instead of throwing an unhandled exception. This aligns with the JSON-RPC 2.0 spec.McpAgent protocol message suppression (
index.ts) —McpAgentnow overridesshouldSendProtocolMessages()to suppressCF_AGENT_IDENTITY,CF_AGENT_STATE, andCF_AGENT_MCP_SERVERSframes on MCP transport connections (detected via thecf-mcp-methodheader). Regular WebSocket connections to a hybrid McpAgent are unaffected.SSE handler MCP header (
utils.ts) — AddedMCP_HTTP_METHOD_HEADERto the SSE handler's internal WebSocket upgrade request soshouldSendProtocolMessagescan detect SSE-originated MCP connections.CORS warning removed (
utils.ts,worker-transport.ts) — Removed the noisy one-time warning aboutAuthorizationinAccess-Control-Allow-Headerswith wildcard origin. The combination is valid for non-credentialed requests and the warning was unhelpful.Session provider (
src/experimental/memory/session/providers/agent.ts)BEGIN TRANSACTION/COMMIT/ROLLBACK— Durable Objects auto-coalesce all synchronous SQL writes within a single I/O gate into one atomic batch, making explicit transactions unnecessary. The old code threw"cannot start a transaction within a transaction"errors because the DO runtime already wraps synchronous writes.Lifecycle rename
onStateUpdate→onStateChanged(server-side) — The server-side lifecycle hook has been renamed. The old name still works (backward-compatible shim with a one-time console warning). The client-sideonStateUpdatecallback inuseAgent/AgentClientis unchanged.Test improvements
routing.test.ts— All WebSocket upgrade tests now properly accept and close WebSockets after assertions, eliminating 17 "other end of WebSocketPipe was destroyed" log lines on teardown.state.test.ts— Updated to useonStateChangednaming throughout.rpc.test.ts— Updated to expect JSON-RPC error response instead of thrown exception.state.ts,readonly.ts) — RenamedonStateUpdatetoonStateChanged.Docs
docs/client-sdk.md— Fixed server-side method reference fromonStateUpdate()toonStateChanged().Changesets
security-hardening.md— Rewrote stale deprecation warnings bullet to reflect actual behavior.fix-sql-error-handling.md— Documents theSqlErrordirect-throw change.fix-mcp-protocol-handling.md— Documents JSON-RPC error responses, McpAgent protocol suppression, and CORS warning removal.Test results
All tests pass:
routing.test.ts— 25 tests, no WebSocketPipe noisestate.test.ts— all state management tests withonStateChangedrpc.test.ts— JSON-RPC error response handlingworkflow.test.ts— 42 tests (remaining workerd logs are expected miniflare teardown artifacts)email-routing.test.ts— 39 tests