fix(collector): fence segment rotation - #358
Conversation
📝 WalkthroughWalkthroughThe Binance LOB archiver now coordinates websocket and snapshot producers through epoch-based rotation barriers, drains events before segment boundaries, refactors segment closing, and rejects events timestamped before a segment’s start. ChangesRotation and segment integrity
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant run_session
participant WebsocketProducer
participant SnapshotProducer
participant EventQueue
participant Segment
run_session->>WebsocketProducer: publish rotation epoch
run_session->>SnapshotProducer: publish rotation epoch
WebsocketProducer->>EventQueue: emit RotationBarrier
SnapshotProducer->>EventQueue: emit RotationBarrier
run_session->>EventQueue: drain captured events
run_session->>Segment: close and begin next segment
run_session->>WebsocketProducer: publish resume epoch
run_session->>SnapshotProducer: publish resume epoch
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rust_hft/tools/collector/src/bin/binance-lob-archiver.rs`:
- Around line 973-984: Update the rotation handling in the session loop around
begin_segment_rotation so failures from rotation or closing the outgoing segment
are captured in failure and exit through the loop’s existing break-based
teardown path instead of propagating with ?. Keep the closing and next segment
values scoped as needed, preserve assignment of the next segment on success, and
ensure shutdown, draining, replay-safety marking, segment closure, and health
reporting still execute.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a99a838f-3a4d-4954-8f1d-0989047afd73
📒 Files selected for processing (2)
rust_hft/tools/collector/src/bin/binance-lob-archiver.rsrust_hft/tools/collector/src/lob_archiver.rs
f07e06f to
dee7249
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f07e06fc2d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
dee7249 to
82a4a8c
Compare
Change contract
Atomically fence every Binance collector segment rotation so every producer drains events captured before the rotation boundary, preserves original received timestamps, and rejects residual pre-boundary events. Preserve snapshot retry delay and budget across rotation pauses, and fail closed immediately if a producer exits while barriers are pending.
Out of scope
Research, snapshot/evaluator behavior, historical backfill, funding/OI/reference collectors, and any production cutover before a fresh full shadow gate succeeds.
Dependency or merge order
None. Base: main. This independent runtime-safety fix follows the already-merged #224 code contract and must merge before a new shadow candidate is built.
Focused validation
Rollout / rollback impact
Deploy only as an isolated shadow collector under the single ECS controller. Promote only after a fresh >=3600-second gate proves positive agg_trade, zero LOB sequence gaps, manifest/SHA/_SUCCESS readback, and replay-safe ordering. Roll back by keeping or restoring the existing production collector binary; no data is rewritten.
Atomic scope exception
This two-file, 1,835 non-generated-line diff exceeds the normal review-size threshold but cannot safely split: producer barriers, pause-safe waits, retry preservation, bounded proof handling, resume-before-compression, failure teardown, and the fail-closed segment guard form one boundary-safety and rollback unit. Named reviewers /root/collector_boundary_spec_review and /root/collector_boundary_standards_review accepted the atomic boundary exception; the latest scoped review fixes are covered by targeted counterexamples and require fresh CI before merge.
PRD
Not required: this is a narrowly specified regression fix for the existing collector behavior contract.
Refs #224