Skip to content

Isolate stale USD-M raw trades - #851

Merged
proerror77 merged 1 commit into
mainfrom
codex/stale-raw-trade-isolation
Aug 12, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/stale-raw-trade-isolation

Conversation

@proerror77

@proerror77 proerror77 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • isolate USD-M raw-trade frames whose received_at-E exceeds 30s into an archived audit event without restarting the websocket shard
  • preserve normal raw-trade sequence continuity across the one audited stale ID while keeping parser/depth/aggTrade/forceOrder failures fail-closed
  • mark affected symbols incomplete in the v2 manifest; strict and raw-trade continuity verifiers reject incomplete segments
  • add exact CUSDT offline Segment→manifest→strict verifier→FakeOss upload/readback/cleanup coverage

Validation

  • cargo test -p hft-data --lib --locked (85 passed)
  • cargo test -p hft-collector --bin binance-lob-archiver --locked (98 passed; local macOS shim temporarily maps RUSAGE_THREAD to RUSAGE_SELF, restored byte-exact)
  • cargo clippy --target x86_64-unknown-linux-gnu -p hft-data --lib --locked -- -D warnings
  • cargo clippy --target x86_64-unknown-linux-gnu -p hft-collector --bin binance-lob-archiver --locked -- -D warnings
  • git diff --check

Base: aa69b52e70d9bc63a9be758d5fd42d9e078775a4
Head: 26e224651b9d5051c2d145cb6e68d1a4350b9cba

Summary by CodeRabbit

  • New Features

    • Stale market trades are preserved as auditable events instead of terminating data collection.
    • Archived records now include source-clock diagnostics and affected symbols.
    • Stream continuity resumes after an explicitly audited stale trade.
  • Bug Fixes

    • Malformed trade payloads continue to be rejected.
    • Strict verification now detects incomplete or replay-unsafe segments and mismatched symbol declarations.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@proerror77, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fc446d4b-1834-4396-838d-bfc5e4c9c049

📥 Commits

Reviewing files that changed from the base of the PR and between 26e2246 and 151692a.

📒 Files selected for processing (2)
  • rust_hft/data-pipelines/core/src/binance_market_tape.rs
  • rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
📝 Walkthrough

Walkthrough

The PR adds stale raw-trade parsing and auditing. The collector archives delayed trades, resumes sequence validation, and marks affected symbols incomplete. Segment manifests persist these symbols, and artifact verification validates their declarations and stale-row metadata.

Changes

Stale raw-trade auditing

Layer / File(s) Summary
Market Tape stale-trade contracts
rust_hft/data-pipelines/core/src/binance_market_tape.rs
Raw-trade parsing accepts audited stale clocks without weakening strict parsing. Event validation recognizes stale_raw_trade. Sequence validation resumes after one audited stale trade. Tests cover malformed payloads and sequence advancement.
Collector stale-event handling
rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
The collector creates StaleRawTrade events, preserves frames and clock diagnostics, archives stale rows, and resumes continuity from the stale trade ID.
Segment replay-safety tracking
rust_hft/tools/collector/src/lob_archiver.rs
Segments record affected symbols, mark stale-trade segments replay-unsafe, and persist incomplete symbols during close and recovery.
Artifact incompleteness verification
rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs
Verification validates stale-row fields, clocks, streams, symbols, and producer shards. Manifest declarations must exactly match observed incomplete symbols. Raw-trade continuity rejects incomplete segments.

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

Sequence Diagram(s)

sequenceDiagram
  participant BinanceStream
  participant event_from_frame_for_shard
  participant Segment
  participant ManifestVerifier
  BinanceStream->>event_from_frame_for_shard: provide delayed raw-trade frame
  event_from_frame_for_shard->>Segment: emit StaleRawTrade audit event
  Segment->>Segment: record incomplete symbol and archive row
  Segment->>ManifestVerifier: provide finalized manifest and stale row
  ManifestVerifier->>ManifestVerifier: validate row and symbol declaration
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: isolating stale USD-M raw trades.
Description check ✅ Passed The description explains the behavior and validation, but it omits the required Issue relationship and Runtime impact and rollback sections.
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.
✨ 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/stale-raw-trade-isolation

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 force-pushed the codex/stale-raw-trade-isolation branch from 26e2246 to 813e317 Compare August 12, 2026 08:16

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs (1)

2547-2579: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding tamper-case coverage for the new stale_raw_trade arm.

The two new tests cover the manifest declaration contract in both directions. The row-level integrity checks added at lines 661-733 have no direct coverage.

The uncovered checks are the non-forgeability guarantees of the audit row: row symbol versus frame symbol, row stream versus frame stream, row E/T versus frame clocks, the three delta values, and the producer_id shard bound. A row that fakes a smaller recv_minus_event_ms would currently be caught by line 708, but no test pins that behavior.

The existing stale_book_ticker_producer_id_must_be_declared test at line 2615 shows the pattern. Each case is a one-field mutation of stale_raw_trade_row.

🧪 Example: pin the delta-tampering rejection
    #[test]
    fn stale_raw_trade_clock_audit_must_match_its_frame() {
        let root = tempdir();
        let mut rows = valid_v2_rows();
        let mut stale = stale_raw_trade_row(START_NS + 330_000_000);
        stale["recv_minus_event_ms"] = json!(30_000);
        rows.insert(5, stale);
        let rows = with_stream_coverage_v2(rows, &["BTCUSDT"], &V2_STREAM_TYPES);
        let (triplet, anchor) =
            write_triplet_v2(root.path(), &rows, &["BTCUSDT"], &V2_STREAM_TYPES);
        let error = verify_binance_market_tape(vec![
            seal_binance_market_tape_triplet(&triplet, &anchor).unwrap(),
        ])
        .unwrap_err();
        assert!(error
            .to_string()
            .contains("stale raw trade clock audit does not match its frame"));
    }
🤖 Prompt for 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.

In `@rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs` around
lines 2547 - 2579, Add direct tamper-case tests for the row-level checks of
stale_raw_trade validation, following
stale_book_ticker_producer_id_must_be_declared. Mutate one field at a time in
stale_raw_trade_row to cover symbol, stream, E/T clocks, all three delta values,
and producer_id shard-bound mismatches, then assert verification rejects each
mutation with the corresponding audit-mismatch error.
🤖 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.

Nitpick comments:
In `@rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs`:
- Around line 2547-2579: Add direct tamper-case tests for the row-level checks
of stale_raw_trade validation, following
stale_book_ticker_producer_id_must_be_declared. Mutate one field at a time in
stale_raw_trade_row to cover symbol, stream, E/T clocks, all three delta values,
and producer_id shard-bound mismatches, then assert verification rejects each
mutation with the corresponding audit-mismatch error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e5c188a5-f3a3-4cd1-b758-17a6d6405963

📥 Commits

Reviewing files that changed from the base of the PR and between aa69b52 and 26e2246.

📒 Files selected for processing (4)
  • rust_hft/data-pipelines/core/src/binance_market_tape.rs
  • rust_hft/data-pipelines/core/src/binance_market_tape_artifact.rs
  • rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
  • rust_hft/tools/collector/src/lob_archiver.rs

@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: 26e224651b

ℹ️ 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
@proerror77
proerror77 force-pushed the codex/stale-raw-trade-isolation branch from 813e317 to 151692a Compare August 12, 2026 08:38
@proerror77
proerror77 merged commit a0a2726 into main Aug 12, 2026
44 checks passed
@proerror77
proerror77 deleted the codex/stale-raw-trade-isolation branch August 12, 2026 08:49
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