Skip to content

feat(data): expose verified Binance replay timeline - #131

Merged
proerror77 merged 3 commits into
mainfrom
codex/binance-verified-timeline
Jul 18, 2026
Merged

proerror77 merged 3 commits into
mainfrom
codex/binance-verified-timeline

Conversation

@proerror77

@proerror77 proerror77 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Change contract

Expose a chronological, read-only replay timeline from VerifiedBinanceMarketTape and fail closed when received_at_ns moves backwards across the ordered sealed segment set.

Out of scope

  • PIT row materialization or evaluator changes
  • Collector, uploader, OSS selection, or deployment changes
  • Aggregate-trade semantics or replay-sequence rules
  • Requiring strictly increasing timestamps; equal timestamps remain valid

Dependency / merge order

None. Depends only on verifier contracts already merged in #128, #129, and #130. The PIT materializer adapter will be a separate dependent PR after this one merges.

Focused validation

  • Review budget: 1 changed file, +157/-6, below the 25-file / 750-line split threshold.
  • Red GitHub/Linux counterexample run 29639489544: 9 existing verifier tests passed and only receive_time_cannot_move_backwards_across_segments failed because the old verifier returned a Verified handle after a cross-segment receive-time rollback.
  • First green attempt run 29639613536 stopped at rustfmt before tests; no behavior evidence was claimed from it.
  • Intermediate green run 29639676442 passed rustfmt and all 10 verifier tests.
  • Exact-head GitHub/Linux focused run 29639937252 passed rustfmt and all 11 verifier tests for 7d0c1ecdf1680c4a93779781c56f2008ed915da1.
  • Exact-head standard CI run 29639912698 passed Rust Workspace, Rust HFT Engine Fast Lane, production image/Kubernetes contract, and the repository security lanes.
  • Typed surface evidence asserts segment receive bounds/event count and per-symbol Snapshot, Diff, and Checkpoint events. A separate positive counterexample proves equal close/open timestamps remain ordered and legal.

Rollout / rollback impact

Data-contract-only, fail-closed tightening. No runtime service change. Reverting this PR removes the timeline projection and returns to accepting cross-segment receive-time rollback; dependent PIT materialization must not roll out without it.

Summary by CodeRabbit

  • New Features

    • Replay results now include ordered market events for each symbol, including snapshots, updates, and checkpoints.
    • Verification metadata now reports event counts and receive-time ranges for each segment.
  • Bug Fixes

    • Verification now detects and rejects events received out of chronological order.
    • Replay event ordering and timestamp consistency are now validated across segments.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Replay verification now records ordered per-symbol replay and checkpoint events, rejects backward receive-time movement across segments, and exposes receive-time bounds, event counts, and typed event lists through the verified tape surfaces.

Changes

Replay event sequencing

Layer / File(s) Summary
Replay event contracts and metadata
rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs
Adds typed replay/checkpoint events, an events accessor on ReplayedBinanceBook, and receive-time bounds and event counts on segment identities.
Verification event capture
rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs
Tracks receive-time monotonicity, records replay and checkpoint events per symbol, and attaches ordered events to finalized books.
Sequencing validation
rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs
Tests backward-time rejection, equal timestamps across segments, identity metadata, event ordering, and event variants.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant verify_binance_market_tape
  participant ReplaySequenceValidator
  participant ReplayedBinanceBook
  verify_binance_market_tape->>ReplaySequenceValidator: Observe diff and checkpoint rows
  ReplaySequenceValidator-->>verify_binance_market_tape: Return replay events
  verify_binance_market_tape->>ReplayedBinanceBook: Store ordered replay and checkpoint events
  verify_binance_market_tape->>verify_binance_market_tape: Reject backward received_at_ns
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 clearly matches the main change: exposing a verified Binance replay timeline.
Description check ✅ Passed The description covers the required contract, out-of-scope, dependencies, validation, 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-verified-timeline

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.

@proerror77
proerror77 marked this pull request as ready for review July 18, 2026 10:00
@proerror77

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@proerror77
proerror77 merged commit 89a060c into main Jul 18, 2026
17 checks passed

@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: 7d0c1ecdf1

ℹ️ 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 on lines +232 to +235
if last_received_at_ns.is_some_and(|last| received_at_ns < last) {
bail!("market-tape receive time moved backwards");
}
last_received_at_ns = Some(received_at_ns);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject rollback in exposed segment bounds

When a later segment manifest declares start_received_at_ns earlier than the previous segment's declared end but its first row is still >= the last row seen, this row-level check passes and identity() now exposes overlapping segment bounds as verified. That lets downstream callers of segments() see a timeline that moves backward even though verification succeeded; compare declared segment bounds across the ordered set or derive the exposed bounds from the observed rows before returning them.

Useful? React with 👍 / 👎.

Comment on lines +232 to +235
if last_received_at_ns.is_some_and(|last| received_at_ns < last) {
bail!("market-tape receive time moved backwards");
}
last_received_at_ns = Some(received_at_ns);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope receive ordering to replayed book timelines

This check runs across every archived row, but the newly exposed timeline is per ReplayedBinanceBook and excludes agg_trade/session_start rows. In the inspected collector, depth and aggregate-trade messages are produced by separate websocket tasks, timestamped before enqueueing, and then written in receiver order, so a valid agg_trade or another symbol's row with a larger receive time can be written before this book's next diff with a smaller receive time even though the book's own replay remains ordered; track the last receive time per replayed symbol or only validate the emitted book events.

Useful? React with 👍 / 👎.

replayed
.get_mut(symbol)
.context("market-tape replay event symbol is undeclared")?
.extend(events.into_iter().map(ReplayedBinanceBookEvent::Replay));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate levels before exposing replay events

When an earlier snapshot or diff contains a non-positive price/quantity that is later corrected before the final checkpoint, the existing final-book check can still pass, but this new events() surface now returns that invalid level as verified replay data. Validate the levels in each ReplaySequenceEvent before extending the public timeline, or reject the artifact before returning VerifiedBinanceMarketTape.

Useful? React with 👍 / 👎.

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.

1 participant