Repository navigation
Description
On .NET Framework, a terminal socket that the server closes with code 1012 ends in a transport exception instead of a peer closure. .NET 10 and .NET 11 see a clean close.
What happens
opencode closes every socket that borrows a location with 1012 location shut down when that location shuts down: a reload, a VCS init or a debug eviction (packages/server/src/handlers/pty-socket.ts:35-46 at the pinned v2.3.0). The PTY and persistent-PTY doors hold such sockets.
On .NET Framework, the SDK's terminal socket is ClientWebSocket (src/OpenCode.Sdk/Internal/Terminal/ClientTerminalWebSocket.cs, ReceiveAsync). There, a received close frame with 1012 does not arrive as a close. It throws:
System.Net.WebSockets.WebSocketException: Invalid data format for the specific protocol operation
WebSocketErrorCode = NativeError, NativeErrorCode = HResult = 0x83760002, socket State = Aborted
So a PTY session on net472 ends with a transport exception where net10.0 and net11.0 end with a peer closure. Client-hosted MCP is not affected: it retries after both.
Evidence
A raw TCP server wrote the 101 handshake and one close frame by hand, so no server-side WebSocket stack validated the code. The client was ClientWebSocket, run with one ReceiveAsync:
| Close code sent | .NET Framework 4.8.10008 | .NET 10.0.14 |
|---|---|---|
| 1000 | clean close, code and reason intact | clean close |
| 1011 | clean close | clean close |
| 1012 | WebSocketException, 0x83760002, Aborted |
clean close |
| 1013 | same exception | clean close |
| 1014 | same exception | clean close |
| 4000 | clean close | clean close |
Windows' native WebSocket component, which .NET Framework's ClientWebSocket and HttpListener use, rejects the close codes that were registered with IANA after RFC 6455 (1012–1014). On .NET 10, HttpListener also refuses to send 1012, with the same error.
Options
- (a) On .NET Framework only, map exactly this receive failure (
WebSocketError.NativeErrorwith native code 0x83760002) to a peer closure whose close code is unknown. It is narrow and recognisable, but the code and reason are lost. - (b) Keep the behaviour, and document it as a .NET Framework platform limit in
docs/architecture/client-runtime.md.
Recommendation: (a) plus a canon line that names the limit and the mapping. (a) is a platform-specific mapping, so the choice is the maintainer's.
Found while writing the client-hosted MCP live tests. Refs #529
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsQueue
Activity
Blind-Striker commentedon Nov 16, 2026
Decision: option (b). Document the .NET Framework behaviour, and add no mapping and no new transport.
Option (c), a managed WebSocket on .NET Framework, was researched and dropped:
System.Net.WebSockets.WebSocketProtocolpackage (5.1.3, net462/netstandard2.0) carries the .NET 5-era managed protocol code. Its close-status validation accepts only 1000-1003 and 1007-1011. It closes withProtocolErrorand throws on 1012-1014, the same failure as today. The 1012-1014 acceptance came with dotnet/runtime #83827 (.NET 8) and never reached that package. The package's own notes also call it obsolete.ManagedWebSocket(about 2,000 lines) plus our own client handshake, and owning that protocol stack. That cost is out of proportion for one close code on one target.Done-when:
client-runtime.mdstates that on .NET Framework a server close with 1012, 1013 or 1014 surfaces as aWebSocketException(native error 0x83760002) and the socket isAborted, while .NET 10+ reports the close normally. The terminal guide repeats it where it describes closes.