Skip to content

collector: gate CEX L2 continuity evidence - #265

Merged
proerror77 merged 2 commits into
mainfrom
codex/cex-l2-shadow-gate-224
Jul 23, 2026
Merged

collector: gate CEX L2 continuity evidence#265
proerror77 merged 2 commits into
mainfrom
codex/cex-l2-shadow-gate-224

Conversation

@proerror77

@proerror77 proerror77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Change contract

Require the packaged Binance collector verifier and Rust LOB shadow gate to prove sealed binance.lob_continuity.v1 continuity for every canonical OSS round-trip before a candidate can be promoted.

Out of scope

  • ECS/systemd operations or production cutover
  • Collector capture/runtime behavior
  • Snapshot, evaluator, MCTS, or other research logic

Dependencies and merge order

Depends on merged PR #264; merge this PR after #264.

Focused validation

  • cargo test -p hft-collector --bin binance-lob-archiver (40 passed)
  • bash deployment/aliyun/test-rust-lob-control-plane.sh
  • bash deployment/aliyun/test-rust-lob-release-adoption.sh
  • shellcheck deployment/aliyun/host-rust-lob-shadow-gate.sh deployment/aliyun/test-rust-lob-control-plane.sh deployment/aliyun/test-rust-lob-release-adoption.sh
  • bash -n for the three changed shell scripts
  • git diff --check
  • Counterexample: policy rejects a second OSS segment whose LOB capture session differs from the first.
  • Matt Standards review: no blocker. Matt Spec review: no blocker.

The repository-wide cargo fmt --all -- --check still reports pre-existing formatting drift outside this change; the new Rust hunk was aligned to rustfmt output.

Rollout and rollback

No production mutation in this PR. A later named single controller must package this merged gate, run the isolated one-hour shadow gate, and read back canonical artifacts before cutover. Roll back this layer by reverting this PR; v2 evidence then remains acceptable only to the prior policy.

Scope exception

None.

Closes no issue: #224 remains open until the live shadow gate and canonical artifact readback are completed.

Summary by CodeRabbit

  • New Features

    • Added strict order book continuity verification for archived market data.
    • Validation now covers reconnect boundaries, session consistency, sequence gaps, time rollbacks, symbol coverage, latency, and bid/ask depth.
    • Verification evidence now includes detailed order book continuity metrics for each market segment.
  • Bug Fixes

    • Improved deployment gates to reject incomplete or inconsistent order book evidence, including invalid reconnect transitions or mismatched capture sessions.
  • Tests

    • Added coverage for the new verification mode and negative cases involving invalid continuity data.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The gate now performs strict LOB continuity verification, records continuity metrics in round-trip evidence, validates them for spot and USDM markets, and emits schema v3 payloads with expanded test coverage.

Changes

LOB continuity gate

Layer / File(s) Summary
Segment verifier continuity mode
rust_hft/tools/collector/src/bin/binance-lob-archiver.rs
Adds --require-lob-continuity, routes verification through the combined trade/LOB verifier, and tests the flag dependency.
Manifest continuity readback
deployment/aliyun/host-rust-lob-shadow-gate.sh
Requires complete LOB continuity manifests, captures continuity metrics, derives aggregate evidence, and updates the gate schema to v3.
Schema v3 policy validation
deployment/aliyun/rust-lob-shadow-gate-policy.jq
Validates continuity settings, reconnect boundaries, latency and level bounds, and evidence aggregates for spot and USDM.
Gate payload and rejection coverage
deployment/aliyun/test-rust-lob-control-plane.sh, deployment/aliyun/test-rust-lob-release-adoption.sh
Updates fixtures to schema v3 and adds capture-session continuity rejection coverage.

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

Sequence Diagram(s)

sequenceDiagram
  participant GateScript
  participant Archiver
  participant OSSManifest
  participant GatePolicy
  GateScript->>Archiver: request strict segment verification
  Archiver->>OSSManifest: verify trade and LOB continuity
  OSSManifest-->>GateScript: return continuity metrics
  GateScript->>GatePolicy: submit schema v3 gate evidence
  GatePolicy-->>GateScript: accept or reject evidence
Loading

Possibly related PRs

  • proerror77/monday#29: Adds earlier fail-closed shadow-gate and policy foundations for the same gate flow.
🚥 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 change: gating CEX L2 continuity evidence.
Description check ✅ Passed All required template sections are present and filled with relevant, specific 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/cex-l2-shadow-gate-224

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.

@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: 10f8711833

ℹ️ 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 +649 to +650
and .lob_continuity.contract == "binance.lob_continuity.v1"
and .lob_continuity.capture_session_id == $session_id

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Pass session_id to the LOB manifest jq check

For every manifest whose end time reaches the gate window, this second jq invocation references $session_id without defining it. The --arg session_id on the earlier discovery invocation is local to that separate process, so jq exits with '$session_id is not defined' and the production shadow gate always takes the failure path before verifying any OSS segments. Add the argument to this invocation or combine the checks.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 2bf102f: the session argument is now bound on the same jq invocation that evaluates the LOB continuity contract, with a focused regression assertion.

--argjson gap_from_previous_ns "$gap_ns" \
--argjson bytes "$bytes" \
--argjson agg_trade_count "$agg_trade_count" \
--argjson lob_continuity "$lob_continuity" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Read full-catalog LOB summaries from a file

With the configured full-catalog run, lob_continuity.symbols contains hundreds to more than 1,000 verbose per-symbol objects, so the compact summary is substantially larger than Linux's per-argument limit (a representative 1,000-symbol summary is about 340 KB). Expanding the whole value into this single --argjson argument therefore makes the shell fail to execute jq with Argument list too long, preventing round-trip evidence from being produced even after the earlier jq-variable issue is fixed. Have jq read the manifest/summary from a file instead of passing it through argv.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 2bf102f: the full continuity summary is now read directly from the canonical manifest via --slurpfile; the control-plane test rejects any --argjson lob_continuity regression.

@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)
deployment/aliyun/test-rust-lob-control-plane.sh (1)

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

Duplicate schema-v3 LOB-evidence fixture construction across two test scripts. Both scripts independently hand-build the same market/usdm_market/gate JSON shape (session id, reconnect-boundary pattern, latency/level bounds, usdm override map) with only literal values differing. One shared root cause: no common fixture helper for schema-v3 LOB continuity evidence.

  • deployment/aliyun/test-rust-lob-control-plane.sh#L80-113: extract the market/usdm_market/gate JSON construction into a shared shell helper (e.g. a sourced lob-gate-fixture.sh) parameterized by session id, symbol counts, and hashes.
  • deployment/aliyun/test-rust-lob-release-adoption.sh#L146-185: source and call the same shared helper instead of re-implementing the fixture shape here.
🤖 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 `@deployment/aliyun/test-rust-lob-control-plane.sh` at line 1, Extract the
duplicated schema-v3 LOB evidence JSON construction from the test flow in
test-rust-lob-control-plane.sh into a shared sourced shell helper, parameterized
by session ID, symbol counts, and hashes. Update
test-rust-lob-release-adoption.sh to source and call that helper, preserving
each script’s existing literal values while removing its local
market/usdm_market/gate fixture construction.
🤖 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 `@deployment/aliyun/test-rust-lob-control-plane.sh`:
- Line 1: Extract the duplicated schema-v3 LOB evidence JSON construction from
the test flow in test-rust-lob-control-plane.sh into a shared sourced shell
helper, parameterized by session ID, symbol counts, and hashes. Update
test-rust-lob-release-adoption.sh to source and call that helper, preserving
each script’s existing literal values while removing its local
market/usdm_market/gate fixture construction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cf398508-517c-49fb-b6c1-9239ffaa61b5

📥 Commits

Reviewing files that changed from the base of the PR and between 7c0a69e and 2bf102f.

📒 Files selected for processing (5)
  • deployment/aliyun/host-rust-lob-shadow-gate.sh
  • deployment/aliyun/rust-lob-shadow-gate-policy.jq
  • deployment/aliyun/test-rust-lob-control-plane.sh
  • deployment/aliyun/test-rust-lob-release-adoption.sh
  • rust_hft/tools/collector/src/bin/binance-lob-archiver.rs

@proerror77

Copy link
Copy Markdown
Owner Author

This was generated by AI during triage.

CI classification before merge:

  • The original reviewed head 10f87118 completed the full Linux Rust Workspace successfully.
  • The review-fix head 2bf102f9 passed the CEX: WebSocket L2 delta 时序与连续性 collector #224 checks on every cloud attempt: test-rust-lob-control-plane.sh and test-rust-lob-release-adoption.sh.
  • The shared Rust Workspace failed three times only after those checks, in unchanged test-trading-ecs-host-contract.sh, which exited silently. Debug rerun did not expose a script line.
  • The exact full control-plane command chain passes locally on 2bf102f9; the unrelated trading host test also passed ten consecutive local runs.
  • Clippy, Semgrep, security, both image contracts, CodeRabbit, and two independent read-only reviews are green on the review-fix head.

This is classified as an unrelated runner/test instability, not a #224 behavior failure. No trading-host code or test change is being mixed into this collector PR. The production shadow gate remains unrun and issue #224 stays open.

@proerror77
proerror77 merged commit a2018be into main Jul 23, 2026
29 of 32 checks passed
@proerror77
proerror77 deleted the codex/cex-l2-shadow-gate-224 branch July 24, 2026 08:44
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