piker/ai/prompt-io/opencode/20261028T160846Z_7242dcb9_w...

37 lines
1.5 KiB
Markdown
Raw Normal View History

.data: reconnect after websocket reader close errors A Binance Ping racing local socket closure makes trio-websocket's reader send a Pong while wsproto is LOCAL_CLOSING. That reader nursery error escapes proxy_msgs(), then tears down brokerd and pikerd instead of restoring quote delivery. Classify NoBsWs.recon_errors around the entire websocket context, with collapse_eg() outside it so a singleton reader exit group reaches the reconnect handler. Invalidate the stale connected event and socket reference before retrying. Keep retry sleep unshielded so parent cancellation stops recovery promptly. Deats, - Add real loopback websocket coverage: TCP, handshake, Ping, reader dispatch and wsproto's actual Pong validation. - Control only the first client Ping's protocol-state ordering, withholding its Close frame to prevent a peer response racing the deterministic LOCAL_CLOSING reproducer. - Require fresh data on a replacement connection, plus exactly one connection when cancelling at the reader or retry boundary. - Use RuntimeError for the unexpected-failure control: LocalProtocolError is now a recoverable connection failure. - Preserve the original unexpected exception with bare raise, and assert its identity in the test. Log recoverable errors with the websocket URL and the underlying traceback. This is a local follow-up, not another downstream cherry-pick. The earlier wrapper suppressed escaped communication failures; 97eb8347 deliberately re-raised them. Retain that outer error visibility rather than restoring suppression without recovery. The isolated baseline reproduces the live Pong failure; all 13 selected Binance/websocket cases pass with this fix. Human live qualification remains separate from these loopback regressions. Follow-up-to: 97eb834799cd8922d4efb96f442201291281c08a Original-equivalent: d50ab6124cd0e1646c82fa4a85d7c13bfff82611 Related-history: 3d83b61f3f7b982e84a4230dba5777f1407c78f1 Prompt-IO: ai/prompt-io/opencode/20261028T160846Z_7242dcb9_websocket_close.md (this patch was generated in some part by `opencode` using `gpt-6.1-sol` (`openai`))
2026-10-28 16:48:06 +00:00
---
created_at: 2026-10-28T16:08:46Z
generated_by:
harness: opencode
provider: openai
model: openai/gpt-6.1-sol
git_ref: 7242dcb9
diff_cmd: git diff HEAD~1..HEAD
---
Implemented a focused websocket-context reconnect fix and real
loopback reader/close regressions in the Binance landing worktree.
> `git diff HEAD~1..HEAD -- piker/data/_web_bs.py`
Move exception-group collapse outside the websocket context so
reader-nursery exit errors are classified by the reconnect loop.
Retry NoBsWs.recon_errors there, clear the stale connected event
and socket reference, and honor cancellation through unshielded
retry sleep. Retain unexpected-error propagation at the outer API.
> `git diff HEAD~1..HEAD -- tests/test_websocket.py`
Exercise real TCP, handshake, Ping frames, reader dispatch and
wsproto Pong validation. A narrow handler gate advances the real
protocol state to LOCAL_CLOSING without sending the Close frame,
preventing a peer reply from racing the controlled state. Require
fresh application data from the replacement connection. Separate
variants cancel at the reader gate and at the actual retry wait.
Update the existing unexpected-failure control to use ValueError
because LocalProtocolError is now intentionally recoverable.
The isolated original-code/new-test baseline fails with the exact
Pong-in-LOCAL_CLOSING error. The fixed isolated tree passes all 13
selected Binance/websocket cases. No live provider, broker orders
or production daemon operations were performed by the agent.