← Blog
0.7.0 · OS · SRDX · FIX

SRDX Relay Fix — Drain Loopback Ring Before Input Recv

June 22, 2026 · sigil-os 277842a · Sigil-Docs
srdx relay bugfix os 0.7.0

sigil-os 277842a fixes a test ordering bug in cc0/srdx_relay_bcast.sg where the T6 input-receive test was reading leftover broadcast frame data from conn=0's loopback ring instead of the injected button bytes. bcast_stub_drain_ring(conn) is added as a test helper that resets rptr=wptr, discarding unread bytes before the input write. All 7 tests now PASS.


The bug

T4 wrote broadcast data; T6 read it as buttons
srdx_relay_bcast.sg uses a loopback ring buffer for the test stub — conn=0 shares a single ring for both broadcast frame output (T4 writes a 16-byte encoded frame header + payload) and input receive simulation (T6 writes 4 bytes of button state, then calls srdx_input_recv(0) to read them back). T4 ran first in the test sequence and left 16 bytes unread in the ring. T6 then called bcast_stub_write_input(0, 85) (buttons=85=0x55) followed by srdx_input_recv(0), but recv consumed the leftover broadcast bytes first, returning 0 (the first bytes of the encoded frame header) instead of 85. T6 failed: got buttons=0 not 85.
The fix — drain ring before input write
bcast_stub_drain_ring(conn): sets rptr = wptr on conn's loopback ring — atomically discards all unread bytes. One call before bcast_stub_write_input in T6 flushes the stale broadcast frame bytes. The test sequence now: T4 broadcasts → T6 drains ring → T6 writes buttons=85 → T6 srdx_input_recv(0) → returns 85 ✅. All 7 tests PASS: srdx_relay init=1 add=1 bcast=1 cnt=1 recv_all=1 inp=1 tick=1 K. Badge R=74 G=200 B=160.

Note: bcast_stub_drain_ring is a test helper only — it is not called in production code. The production srdx_bcast_tick function uses separate send and receive paths that do not share a loopback ring.