Recover a Sequence Gap Before Reusing an Agent Order Book
By DX Research Group · · Market data
Use a feed-specific continuity check and a recovery receipt to identify when reconstructed market state becomes usable again.
A sequence gap should change the usability of the affected reconstructed state. Reconnecting a socket restores transport; it leaves the collector responsible for rebuilding any state whose continuity broke. We would expose that distinction to the agent through an explicit unavailable-book result and preserve the recovery path in its decision trace.
Coinbase's full-channel instructions describe queuing stream messages, obtaining a snapshot, and replaying messages beyond the snapshot sequence. This procedure belongs to that channel. A different feed may use ranges, channel-specific sequences, or snapshot messages with different semantics.
The missing message can change the best bid
Assume a fictional feed where every subscribed book event increments a per-product sequence by one. The last applied sequence is 500, with a best bid of 100 for size 5. Message 501 removes that bid, but the collector loses it. Message 502 updates the ask to 101 and arrives normally.
Applying 502 to the old book produces a plausible 100/101 spread. Its plausibility is irrelevant to continuity: the displayed bid should already be gone. An agent estimating execution against this book receives invented liquidity.
The expected state after receiving 502 is therefore gap_detected, with expected sequence 501 and observed sequence 502. Keep the last complete book for diagnosis, but label it as historical. A replacement REST snapshot at sequence 510 can start recovery if the documented protocol supports that alignment.
Recovery has a beginning and an end
Record the last continuous sequence, the first unexpected message, and the snapshot used for reconstruction. Buffer messages during the snapshot request. Replay according to the venue's ordering rules, then mark the book usable only after the snapshot and buffered stream form a documented continuous state.
A snapshot response can arrive successfully while recovery still fails. The buffer may overflow, another gap may occur, or the snapshot may belong to the wrong product. Each case should retain its own reason so a repeated reconnect cannot masquerade as successful reconstruction.
Decide separately what actions remain admissible while the book is unavailable. An entry policy may require valid depth; a close or cancellation may depend on different information. The feed adapter should report data status, while the action policy interprets that status under the user's mandate.
Replay the break rather than only the reconnect
A proposed acceptance fixture would drop 501, duplicate 502, delay the snapshot, and disconnect again during recovery. Expected outputs include a continuity failure and an eventual recovery receipt with the correct final book. Completion latency can be measured from gap detection to the first usable reconstruction, alongside the number of affected agent turns.
Our feed-health note covers age and transport status; sequence recovery adds structural completeness. Our decision-trace schema supplies the join back to a turn. This test establishes that a collector handles the constructed failure. Any claim about fewer execution losses would require an additional action-level comparison with costs and market exposure held explicit.