fix: label market-data receive boundaries - #446
Conversation
📝 WalkthroughWalkthroughThe change replaces frame-oriented WebSocket metrics with complete-message delivery metrics, adds explicit latency capture boundaries, gates receive-latency cohorts in the engine, and propagates timestamps through Binance snapshots, live parsing, collectors, and latency documentation. ChangesWebSocket message timing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant WsClient
participant BinanceAdapter
participant EventIngester
participant Engine
WsClient->>BinanceAdapter: deliver message with WsMessageMetrics
BinanceAdapter->>BinanceAdapter: create userspace delivery LatencyTracker
BinanceAdapter->>EventIngester: publish tracked market event
EventIngester->>Engine: attach capture boundary
Engine->>Engine: record receive-cohort latency
🚥 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5c24cc7cf
ℹ️ 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".
…y-396 # Conflicts: # rust_hft/data-pipelines/adapters/adapter-binance/src/lib.rs # rust_hft/market-core/engine/src/dataflow/ingestion_ultra.rs
…y-396 # Conflicts: # rust_hft/market-core/engine/src/lib.rs
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rust_hft/market-core/engine/src/lib.rs (1)
1450-1462: 🎯 Functional Correctness | 🔵 TrivialMixed-boundary adapters can starve the Fill end-to-end DoD latency metric.
recent_market_event_timestampis nowNonewhenever the most-recently strategy-processed pending event'scapture_boundaryisn't a receive-latency cohort (e.g. Bitget, still taggedAdapterPublish). In a deployment mixing Bitget with Binance/Bybit, this anchor can be frequently cleared by Bitget events interleaved via the round-robin consumer loop, making thehandle_execution_eventFill "端到端DoD延遲" (infra_metrics::MetricsRegistry::global().record_end_to_end_latency) sparse or absent even when cohort-tagged market data is flowing normally. This is the intended tradeoff of excluding non-receive boundaries from the cohort, but worth confirming it matches the operational expectations for multi-venue deployments (dashboards/alerts relying on this specific gauge may need to account for reduced sample density).🤖 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/market-core/engine/src/lib.rs` around lines 1450 - 1462, Update run_strategies_sync and the receive_latency_anchor handling so non-receive-latency events such as AdapterPublish do not clear an existing recent_market_event_timestamp; only replace the anchor when the pending event belongs to a receive-latency cohort. Preserve the existing exclusion of non-cohort events from latency measurement while keeping the latest valid cohort anchor available for handle_execution_event and record_end_to_end_latency.
🤖 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/market-core/engine/src/lib.rs`:
- Around line 1450-1462: Update run_strategies_sync and the
receive_latency_anchor handling so non-receive-latency events such as
AdapterPublish do not clear an existing recent_market_event_timestamp; only
replace the anchor when the pending event belongs to a receive-latency cohort.
Preserve the existing exclusion of non-cohort events from latency measurement
while keeping the latest valid cohort anchor available for
handle_execution_event and record_end_to_end_latency.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3984bdd1-de8e-4b44-936e-940059b02bba
📒 Files selected for processing (24)
rust_hft/apps/binance-md/src/main.rsrust_hft/data-pipelines/adapters/adapter-binance/src/lib.rsrust_hft/data-pipelines/adapters/adapter-binance/src/websocket.rsrust_hft/data-pipelines/adapters/adapter-bitget/src/bitget_stream.rsrust_hft/data-pipelines/adapters/adapter-bitget/src/zero_copy_stream.rsrust_hft/data-pipelines/adapters/adapter-bybit/src/lib.rsrust_hft/data-pipelines/core/src/binance_market_tape.rsrust_hft/infra-services/core/metrics/src/lib.rsrust_hft/market-core/core/src/latency.rsrust_hft/market-core/core/src/lib.rsrust_hft/market-core/core/src/unified_timestamp.rsrust_hft/market-core/engine/src/binance_md/latency.rsrust_hft/market-core/engine/src/binance_md/parser.rsrust_hft/market-core/engine/src/binance_md/replay.rsrust_hft/market-core/engine/src/dataflow/ingestion.rsrust_hft/market-core/engine/src/dataflow/ingestion_ultra.rsrust_hft/market-core/engine/src/lib.rsrust_hft/market-core/engine/tests/live_hotpath_contract.rsrust_hft/market-core/integration/src/latency.rsrust_hft/market-core/integration/src/lib.rsrust_hft/market-core/integration/src/ws.rsrust_hft/market-core/ports/src/events.rsrust_hft/market-core/ports/src/traits.rsrust_hft/tools/collector/src/bin/binance-lob-archiver.rs
Change contract
Make every CEX market-data receive timestamp identify its actual capture boundary, and exclude adapter-publish and REST-snapshot-completion anchors from receive-latency cohorts.
Out of scope
Dependency / merge order
Stacked on PR #443. Merge #443 first, then this PR. This branch is based on exact #443 head 755ab9f.
Focused validation
Workspace all-target check passes with only pre-existing unrelated warnings in Hyperliquid and runtime modules.
Rollout / rollback impact
No deployment in this PR; live remains disabled. Rollout changes metric taxonomy and cohort admission only. Roll back this PR as one unit after #443 if consumers require the old labels.
Closes #396
Summary by CodeRabbit
Improvements
Documentation