Buffer replay before network delivery and preserve the live handoff

KL
2mo ago
+496-18

Extract the replay-to-live handoff changes from #3511, on top of #3540. Serialize the replay snapshot and live-route registration against event storage, then deliver buffered history outside the lock so a slow reader cannot block sibling responses.

Keep shutdown handling with the lock: normal exit finishes active store writes but cancels a router waiting for replay. The buffer spills above 1 MiB, and the regressions run on both AnyIO backends with locked dependencies.

Validation

macOS, Python 3.14: ./scripts/test passes with 6,013 passed, 9 skipped, 1 xfailed, 100% line/branch coverage, and strict-no-cover passing. Ruff lint/format and Pyright pass.

Stack

Part 2 of 5. Depends on #3540; retarget to main after that merges. No HTTPX2 update is needed for this change.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.