Skip to content

fix(binance): isolate replay-safe capture epochs - #124

Merged
proerror77 merged 3 commits into
mainfrom
codex/binance-capture-epoch
Jul 18, 2026
Merged

proerror77 merged 3 commits into
mainfrom
codex/binance-capture-epoch

Conversation

@proerror77

@proerror77 proerror77 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Change contract\nEach Binance websocket session is a fresh capture epoch, and only a safe scheduled rotation whose active books are all bridged and whose epoch archived a valid aggregate trade for every active symbol may seed replay-safe segment_open checkpoints at one pre-close rotation boundary.\n\nOut of scope\nBinance artifact verification and PR #120; cross-event aggregate-trade f/l continuity; downloader or OSS selection; research mapping; deployment, ECS, collector cutover, and live trading.\n\nDependency or merge order\nBased on main 44b554b after PR #119. Merge this producer contract before rebasing and finalizing PR #120.\n\nFocused validation\n- cargo test --locked -p hft-collector --features collector-binance --bin binance-lob-archiver: 36 passed\n- cargo test --locked -p hft-collector --features collector-binance: 159 library passed, 2 ignored; 36 archiver passed; 10 materializer passed; remaining bins passed\n- cargo clippy --locked -p hft-collector --all-targets --features collector-binance --no-deps -- -D warnings: passed\n- cargo fmt --package hft-collector -- --check: passed\n- git diff --check: passed\n- Red-to-green counterexamples cover per-symbol aggregate-trade coverage, unseeded rotation remaining unsafe after a later trade, and one pre-close timestamp shared by segment close/start/open.\n- Existing counterexamples cover snapshot-only epochs, trusted epochs without aggregate trades, reconnect-local state, and scheduled rotation seeding versus gap non-seeding.\n- Exact head 861335c: GitHub CI and CodeRabbit passed; independent Standards and Spec reviews found no issues; all review threads resolved.\n- Scope: one file, 403 insertions and 66 deletions, below the repository split threshold.\n\nRollout or rollback impact\nNo deployment or schema change. The producer changes only capture-epoch and segment-boundary replay safety. Reconnect, gap, exclusion, unseeded, and incomplete epochs remain fail-closed. Rollback is a revert of this PR; live trading remains disabled.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The archiver now tracks aggregate-trade observation in session-owned state. Segment rotation and closure use shared replay-readiness gating before seeding or writing checkpoints, and lifecycle tests cover the updated replay-safety behavior.

Changes

Replay checkpoint gating

Layer / File(s) Summary
Session-owned aggregate-trade state
rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
run_session owns and propagates ProcessState, while aggregate-trade processing records observed symbols.
Replay-readiness checkpoint lifecycle
rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
Segment rotation and closure use shared readiness checks and centralized checkpoint writing to control replay safety.
Aggregate-trade gating test coverage
rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
Tests cover aggregate-trade setup and updated snapshot-only, trusted-epoch, and scheduled-rotation expectations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant run_session
  participant process_event
  participant rotate_segment
  participant replay_checkpoint_ready
  participant write_checkpoints
  run_session->>process_event: process aggregate-trade event
  process_event->>process_event: record observed symbol
  run_session->>rotate_segment: rotate with ProcessState
  rotate_segment->>replay_checkpoint_ready: evaluate replay readiness
  replay_checkpoint_ready-->>rotate_segment: readiness result
  rotate_segment->>write_checkpoints: write checkpoints when ready
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main Binance replay-safety change.
Description check ✅ Passed The description covers all required template sections with concrete validation, scope, dependency, and rollout details.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/binance-capture-epoch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread rust_hft/tools/collector/src/bin/binance-lob-archiver.rs Fixed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd167ca2bb

ℹ️ 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".

Comment thread rust_hft/tools/collector/src/bin/binance-lob-archiver.rs Outdated
Comment thread rust_hft/tools/collector/src/bin/binance-lob-archiver.rs Outdated
Comment thread rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants