Skip to content

CEX: admit immutable Binance replay snapshots - #406

Merged
proerror77 merged 3 commits into
mainfrom
codex/cex-immutable-replay-snapshot-400
Jul 27, 2026
Merged

proerror77 merged 3 commits into
mainfrom
codex/cex-immutable-replay-snapshot-400

Conversation

@proerror77

@proerror77 proerror77 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Closes #400

Change contract

Admit one existing authenticated Binance combined market-tape replay as a versioned immutable CEX snapshot whose digest becomes the alpha-harness mission dataset identity, and fail closed before evaluation when modality, lineage, digest, sequence, range, or point-in-time availability evidence is invalid.

Out of scope

Dependency or merge order

None. This branch is based on 0cf2cdadb0ebcb65209e11b595059fcd8a16a18e and can merge independently. Polymarket #324 merged separately through PR #405 and is now in the base. #401 depends on this issue; #402 depends on #401.

Focused validation

  • cargo test -p hft-research-manifest — 9 passed
  • cargo test -p hft-collector --bin lob-pit-materializer — 7 passed
  • cargo test -p alpha-harness — 118 passed
  • The exact strict Clippy command used by CI passed on head 5832fdc355147f75f820cb289afda800b4a526a8.
  • Red-to-green counterexamples cover strict dual-modality evidence, selected-symbol aggregate-trade evidence, snapshot-to-mission identity, ordered segment-derived feature revision, snapshot/feature range mismatch, decision-clock look-ahead, label horizon beyond authenticated tape, and a real artifact label timestamp exceeding the segment end by 1ns.
  • Targeted rustfmt --check and git diff --check passed.
  • Independent spec review found no remaining blocker.
  • Review size: 7 files; 937 non-generated source lines changed (903 additions, 34 deletions), above the 750-line assessment threshold.
  • Atomic exception approved by named reviewer Codex standards reviewer /root/standards_review_400: these files form one fail-closed authenticated-tape → immutable-snapshot → CEX-admission → mission-dataset contract; splitting would create an unsafe producer/consumer schema gap and coupled rollback order.

Rollout or rollback impact

Research-only. No deployment, collector cutover, publication, promotion, or live execution is performed. The producer and consumer move together to binance-lob-pit-v2; rollback is a single PR revert. Existing unrelated research paths remain unchanged.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

CEX replay snapshot admission

Layer / File(s) Summary
Snapshot and dataset manifest contracts
rust_hft/research-core/manifest/...
Defines validated CEX replay snapshot identities, deterministic SHA-256 digests, and dataset manifests derived from snapshot content.
Authenticated materialization evidence
rust_hft/tools/collector/...
Publishes validated snapshot evidence and requires trade-summary and LOB-continuity verification data.
Mission snapshot validation and dataset wiring
rust_hft/alpha-harness/app/src/mission_runner.rs
Validates snapshot/materialization lineage, admits a separate dataset manifest, and binds it to mission execution.
Alpha-harness dataset admission and loading
rust_hft/alpha-harness/app/src/data_mission.rs
Registers CEX replay datasets with feature lineage and supports immutable revision checks, row loading, and label specifications.

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

Sequence Diagram(s)

sequenceDiagram
  participant Collector
  participant MaterializationReport
  participant MissionRunner
  participant AlphaHarness
  participant AlphaStore
  Collector->>MaterializationReport: publish validated snapshot and digest
  MissionRunner->>MaterializationReport: validate snapshot lineage and hashes
  MissionRunner->>AlphaHarness: admit CEX replay dataset
  AlphaHarness->>AlphaStore: register dataset revision linked to features
  AlphaHarness-->>MissionRunner: return dataset manifest
  MissionRunner->>AlphaHarness: execute mission with dataset manifest
Loading

Possibly related issues

  • proerror77/monday#205 — Establishes the immutable CEX replay snapshot and dataset manifest contracts implemented here.
  • proerror77/monday#401 — Covers Binance CEX replay admission and identity plumbing used by this change.

Possibly related PRs

  • proerror77/monday#91 — Related materializer changes provide replay snapshot and per-segment provenance evidence.
  • proerror77/monday#131 — Related replay timeline changes provide received-time and event-count evidence used in snapshot validation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement an immutable Binance snapshot admission path with required modalities, deterministic digesting, PIT checks, and counterexample tests.
Out of Scope Changes check ✅ Passed No obvious unrelated code changes stand out; the edits stay within the replay-snapshot admission and harness/manifest plumbing.
Title check ✅ Passed The title is concise and accurately summarizes the main change: admitting immutable Binance replay snapshots.
Description check ✅ Passed The description covers all required template sections with concrete details; only the dependency heading wording differs slightly.
✨ 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-immutable-replay-snapshot-400

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: 8dbe45bbc0

ℹ️ 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/lob-pit-materializer.rs
Comment thread rust_hft/alpha-harness/app/src/mission_runner.rs
Comment thread rust_hft/alpha-harness/app/src/data_mission.rs
@proerror77
proerror77 force-pushed the codex/cex-immutable-replay-snapshot-400 branch from 06da643 to 4846f6f Compare July 27, 2026 01:47

@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 (3)
rust_hft/alpha-harness/app/src/mission_runner.rs (1)

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

Re-sign the snapshot so this test isolates the modality gate.

Setting snapshot_sha256 to an all-zero digest makes the manifest invalid in two independent ways. The assertion currently passes only because snapshot.validate() runs before the digest comparison in validate_materialization. Using resign_materialization (as the sibling tests do) proves the stronger property: a correctly signed snapshot missing aggregate_trade is still rejected.

🧪 Proposed change
-        materialization["snapshot_sha256"] = serde_json::json!("0".repeat(64));
-        std::fs::write(
-            &fixture.materialization_path,
-            serde_json::to_vec_pretty(&materialization).unwrap(),
-        )
-        .unwrap();
-        let mut args = fixture.args;
-        args.materialization_sha256 = sha256_file(&fixture.materialization_path).unwrap();
-
-        let error = execute(args).unwrap_err();
+        let mut fixture = fixture;
+        fixture.materialization = materialization;
+        resign_materialization(&mut fixture);
+
+        let error = execute(fixture.args.clone()).unwrap_err();

Note resign_materialization deserializes the snapshot into CexReplaySnapshotV1 to hash it, which works here because the replacement JSON is still structurally valid for that type.

🤖 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/alpha-harness/app/src/mission_runner.rs` around lines 659 - 670,
Update the test around execute to replace the snapshot_sha256 zeroing and manual
file write with the existing resign_materialization helper, preserving the
removal of aggregate_trade and recomputing args.materialization_sha256
afterward. Keep the assertion that execute rejects the correctly signed snapshot
with the “required modalities” error.
rust_hft/research-core/manifest/src/lib.rs (1)

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

Add a direct counterexample for the range-containment branch.

Digest determinism, segment ordering, and dataset identity are covered, but "event range is outside source segments" — the branch that blocks a snapshot claiming events outside its authenticated tape — has no unit-level counterexample here. It's cheap to pin down at this layer rather than relying on the mission-runner integration tests.

As per coding guidelines, "Safety boundaries require targeted counterexample tests, not only workspace compilation."

🧪 Proposed test
+    #[test]
+    fn cex_replay_snapshot_rejects_events_outside_source_segments() {
+        let mut snapshot = cex_snapshot();
+        snapshot.last_event_time = DateTime::parse_from_rfc3339("2026-07-14T00:00:20Z")
+            .unwrap()
+            .with_timezone(&Utc);
+
+        assert_eq!(
+            snapshot.validate().unwrap_err(),
+            ManifestError::InvalidCexReplaySnapshot("event range is outside source segments")
+        );
+    }
🤖 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/research-core/manifest/src/lib.rs` around lines 430 - 472, Add a
focused unit test alongside the existing CEX replay snapshot validation tests
that modifies the snapshot’s event range to extend beyond its authenticated
source segment bounds, then asserts validate() returns
ManifestError::InvalidCexReplaySnapshot("event range is outside source
segments"). Keep the test limited to exercising this range-containment branch.

Source: Coding guidelines

rust_hft/tools/collector/Cargo.toml (1)

38-38: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Declare hft-research-manifest through the workspace dependency table.

rust_hft/Cargo.toml defines [workspace.dependencies], while this crate and several adjacent crates use a direct { path = ... } for hft-research-manifest. Use { workspace = true } from the workspace manifest so dependency graph changes remain centralized. Include cargo metadata --locked --no-deps as validation evidence for this workspace-graph change.

🤖 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/tools/collector/Cargo.toml` at line 38, Update the
hft-research-manifest dependency declaration in the collector crate to use the
workspace dependency table via workspace = true instead of a direct path. Ensure
the dependency is defined centrally in rust_hft/Cargo.toml’s
[workspace.dependencies], then validate the workspace graph with cargo metadata
--locked --no-deps.

Source: Coding guidelines

🤖 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/alpha-harness/app/src/mission_runner.rs`:
- Around line 659-670: Update the test around execute to replace the
snapshot_sha256 zeroing and manual file write with the existing
resign_materialization helper, preserving the removal of aggregate_trade and
recomputing args.materialization_sha256 afterward. Keep the assertion that
execute rejects the correctly signed snapshot with the “required modalities”
error.

In `@rust_hft/research-core/manifest/src/lib.rs`:
- Around line 430-472: Add a focused unit test alongside the existing CEX replay
snapshot validation tests that modifies the snapshot’s event range to extend
beyond its authenticated source segment bounds, then asserts validate() returns
ManifestError::InvalidCexReplaySnapshot("event range is outside source
segments"). Keep the test limited to exercising this range-containment branch.

In `@rust_hft/tools/collector/Cargo.toml`:
- Line 38: Update the hft-research-manifest dependency declaration in the
collector crate to use the workspace dependency table via workspace = true
instead of a direct path. Ensure the dependency is defined centrally in
rust_hft/Cargo.toml’s [workspace.dependencies], then validate the workspace
graph with cargo metadata --locked --no-deps.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 743e6f62-e33a-4bf1-a193-be8f8b3a30fd

📥 Commits

Reviewing files that changed from the base of the PR and between adfdcee and 4846f6f.

⛔ Files ignored due to path filters (1)
  • rust_hft/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • rust_hft/alpha-harness/app/src/data_mission.rs
  • rust_hft/alpha-harness/app/src/mission_runner.rs
  • rust_hft/research-core/manifest/Cargo.toml
  • rust_hft/research-core/manifest/src/lib.rs
  • rust_hft/tools/collector/Cargo.toml
  • rust_hft/tools/collector/src/bin/lob-pit-materializer.rs

@proerror77
proerror77 force-pushed the codex/cex-immutable-replay-snapshot-400 branch from 4846f6f to 5832fdc Compare July 27, 2026 02:31
@proerror77
proerror77 merged commit dfb27ef into main Jul 27, 2026
48 of 49 checks passed
@proerror77
proerror77 deleted the codex/cex-immutable-replay-snapshot-400 branch July 27, 2026 02:59
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.

CEX: admit one immutable Binance replay snapshot into alpha-harness

1 participant