piker/ai/prompt-io
Gud Boi b95e7c796e .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: 97eb834799
Original-equivalent: d50ab6124c
Related-history: 3d83b61f3f
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 12:48:06 -04:00
..
claude Port service+tests to latest `tractor` APIs 2026-10-07 03:10:41 -04:00
opencode .data: reconnect after websocket reader close errors 2026-10-28 12:48:06 -04:00
20261007T165453Z_bde2457b_prompt_io.md Fix endpoint config and daemon startup from PR94 review 2026-10-10 14:20:52 -04:00
20261007T165453Z_bde2457b_prompt_io.raw.md Fix endpoint config and daemon startup from PR94 review 2026-10-10 14:20:52 -04:00
20261010T232852Z_1fa45dfa_prompt_io.md Use `tractor`'s reviewed address-unpacking branch 2026-10-11 00:43:06 -04:00
20261010T232852Z_1fa45dfa_prompt_io.raw.md Use `tractor`'s reviewed address-unpacking branch 2026-10-11 00:43:06 -04:00