Skip to content

feat(research): publish verified CEX ResearchSnapshot V2 - #786

Merged
proerror77 merged 6 commits into
mainfrom
codex/lob-pit-materializer-v2
Aug 10, 2026
Merged

feat(research): publish verified CEX ResearchSnapshot V2#786
proerror77 merged 6 commits into
mainfrom
codex/lob-pit-materializer-v2

Conversation

@proerror77

@proerror77 proerror77 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Change contract

Materialize Binance Spot and USD-M market tapes into the V3 outer artifact carrying a verified ResearchSnapshot V2: PIT tick/step/min-notional, authenticated maker/taker fees, independent funding and OI, signed real lifecycle latency/slippage, and aggregate-trade flow.

Issue relationship

Refs #794

Rebase baseline

Rebased onto origin/main be9e746a, which already contains #787 (signed arrival-cost evidence), #788 (verification), #789 (fee-account binding), and #793 (fee snapshot timers). The previous draft history merged those prerequisite branches; the rebuilt history is two commits on top of main: the materializer itself, plus the review-closure fixes.

Review thread disposition (all 17 resolved)

Fixed in the follow-up commit:

  • Fee/reference evidence triplets are republished into the artifact directory under content-addressed names, so snapshot digests resolve to immutable bytes (resolvable-location thread).
  • Aggregate-trade fixture assertions now match the (previous, current] bucket semantics (count 1.0 / base 2.0 / quote 201.0 / imbalance 1.0 for the (1s, 2s] row).
  • The test fixture is parameterized per market: the happy path is Spot, and a new test proves USD-M materialization fails closed until a derivatives execution path exists.

Resolved by delegating to the merged alpha_domain::runtime_latency_evidence verifier (the drifted collector-local copy is deleted):

  • event_id dedup before filtering, conflicting duplicates fail closed;
  • per-fill instrument_market_{market} identity, USD-M hard-fails;
  • arrival-price benchmark (arrival_slippage_bps) instead of limit-price-clamped realized_slippage_bps; fills without the metric are skipped as inapplicable;
  • streaming line-bounded log parsing.

Resolved by main (verified in code, evidence posted per thread):

  • Mission consumer admits V3 outer + V2 snapshot (mission_runner.rs:61,727-742; V2 outer read-only bail at :457-466);
  • runtime account namespace binding (feat: bind CEX fee evidence to runtime account #789; runtime_attribution.rs:807,863);
  • sparse-fee bounded gap (MAX_FEE_EVIDENCE_GAP_NS 90s, test rejects_sparse_fee_evidence) — implemented in this PR;
  • funding reschedule semantics (strictly pre-settlement latest observation; multi-settlement buckets);
  • latency manifest keyed by its own content; latency method string matches CexReplaySnapshotV2::validate.

Out of scope

Trading runtime mutation, derivatives execution, order authority, credential provisioning, production unit enablement, and production data deletion.

Focused validation

  • cargo check -p hft-collector --locked --target x86_64-unknown-linux-gnu: clean.
  • cargo clippy -p hft-collector --locked --tests --target x86_64-unknown-linux-gnu: clean.
  • cargo test -p hft-collector --locked --bin lob-pit-materializer: 8/8 pass (run on macOS via a temporary uncommitted RUSAGE_THREAD cfg shim, since the crate's libc::RUSAGE_THREAD use is Linux-only; Linux CI remains the authoritative lane).
  • Full cargo test -p hft-collector --locked lib suite: 326 passed, 4 failed in binance_fee_upload tests — pre-existing macOS tempdir-canonicalization failures on code untouched by this PR (identical to origin/main); expected green on Linux CI.

Size note

The diff adds 869 non-generated lines (mostly the materializer test module), above the 750 guideline. Requesting reviewer judgment on an atomic exception rather than splitting tests from the code they pin.

Rollout and rollback

No runtime mutation in this PR. Production activation remains fail-closed until authenticated fee credentials, resolvable evidence artifacts, and matching signed LiveSmall lifecycle evidence are available. Rollback is the squash commit.

Scope exception

None.

Summary by CodeRabbit

  • New Features

    • Added support for updated market snapshots and point-in-time data schemas.
    • Added USD-M funding data, holding-period funding costs, open interest, fee schedules, instrument rules, and derivatives reference data.
    • Added authenticated evidence handling, immutable evidence republishing, and runtime-latency data.
    • Expanded support for spot and USD-M market selections.
  • Bug Fixes

    • Improved coverage and consistency validation for published market data.
    • Added safeguards for account mismatches and sparse fee information.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The LOB materializer now produces V3 snapshots and PIT rows. It validates and republishes authenticated fee, USD-M reference, and runtime-latency evidence. USD-M rows include funding, funding costs, and open interest.

Changes

LOB PIT materializer

Layer / File(s) Summary
Evidence contracts and snapshot assembly
agent-worktree.yml, rust_hft/tools/collector/Cargo.toml, rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
The collector accepts and validates fee, USD-M reference, and runtime-latency artifacts. It republishes immutable evidence triplets and assembles V3 snapshots with validated modalities.
PIT row and derivatives features
rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
PIT rows derive event and future timestamps and add USD-M funding-rate, holding-interval funding-cost, and open-interest features.
Market-aware fixtures and validation
rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Tests cover spot and USD-M fixtures, evidence publication, account mismatches, sparse coverage, funding calculations, and schema V3 output validation.

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

Possibly related issues

Possibly related PRs

  • proerror77/monday#406 — This PR extends the same LOB materialization pipeline and evolves its CEX snapshot handling.
  • proerror77/monday#777 — This PR integrates the fee snapshots and instrument-rule artifacts introduced by that PR.
  • proerror77/monday#787 — This PR consumes the signed runtime arrival-latency evidence introduced by that PR.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant lob_pit_materializer
  participant EvidenceArtifacts
  participant PITRows
  CLI->>lob_pit_materializer: provide materialization and evidence inputs
  lob_pit_materializer->>EvidenceArtifacts: validate and republish fee, reference, and latency artifacts
  EvidenceArtifacts-->>lob_pit_materializer: return validated evidence
  lob_pit_materializer->>PITRows: materialize V3 rows with funding and open interest
  PITRows-->>CLI: return snapshot and materialization report
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but the required scope exception is incomplete for 869 non-generated lines and conflicts with the stated size note. Replace “Scope exception: None” with the required split or inseparable-contract rationale and name the approving reviewer; add a dedicated dependencies section if needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: publishing a verified CEX ResearchSnapshot V2.
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/lob-pit-materializer-v2

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

Copy link
Copy Markdown
Owner Author

@codex review exact head f6e3465

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

ℹ️ 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 Outdated
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs Outdated
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 1073149

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 67467e7

@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: 67467e7667

ℹ️ 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 Outdated
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 2c5ab91: verify V3 consumer dependency, crossed-funding accounting, signed market/account/availability latency scope, and content-addressed latency manifest.

@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: 2c5ab91804

ℹ️ 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 Outdated
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs Outdated
Base automatically changed from codex/runtime-latency-evidence to codex/runtime-arrival-instrumentation August 9, 2026 21:06
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head d6aecaf: verify PIT funding reschedule semantics; a later pre-settlement schedule replaces the stale funding instant.

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

ℹ️ 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 Outdated
Comment thread rust_hft/tools/collector/src/runtime_latency_evidence.rs Outdated
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head ce65be5: verify schedule replacement uses only observations strictly before settlement, preserving a charge when the next schedule arrives at settlement.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: ce65be5056

ℹ️ 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".

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 8a861d6: verify typed fee/reference/runtime evidence readback, fee/runtime account equality, bounded fee PIT gaps, independent funding/OI clocks, and V3 materialization identity. This remains draft until #787/#788/#789 merge and main is integrated.

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

funding.sort_by_key(|point| point.available_at);
open_interest.sort_by_key(|point| point.available_at);

P2 Badge Reject conflicting observations at the same reference clock

When two valid reference artifacts contain different funding or OI values with the same received_at_ns, these stable sorts preserve CLI argument order, and the later .rev().find(...) selects whichever artifact was supplied last. Reordering the same authenticated evidence set can therefore change feature rows and the V3 materialization digest; reject same-clock conflicts or resolve them with a content-derived deterministic rule.

AGENTS.md reference: AGENTS.md:L67-L68


metrics.insert(
"evidence_available_at_us".to_string(),
Utc::now().timestamp_micros().max(0) as f64,

P2 Badge Record availability only after durable feedback publication

When the materialization cutoff falls between this timestamp and RuntimeFeedbackLog::append completing its later sign, write, and sync_data, the verifier accepts the fill as pre-snapshot evidence even though no signed durable record existed at the claimed availability time. This creates a PIT leak at the boundary; bind availability to a durable append/readback receipt rather than stamping the unsigned event before publication.

AGENTS.md reference: AGENTS.md:L67-L68

ℹ️ 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".

Base automatically changed from codex/runtime-arrival-instrumentation to main August 9, 2026 23:36
Sonic Shih added 2 commits August 10, 2026 14:30
Materialize verified Binance Spot/USD-M market tapes into the V3 outer
materialization carrying CexReplaySnapshotV2: PIT instrument rules,
account-bound maker/taker fees, independent funding and OI timelines,
aggregate-trade flow, and signed runtime lifecycle latency evidence.

Rebased onto origin/main be9e746, which already contains the signed
arrival-cost evidence (#787), its verification (#788), fee-account
binding (#789), and fee snapshot timers (#793). Refs #794.
- Delegate runtime latency verification to the hardened
  alpha_domain::runtime_latency_evidence verifier instead of a drifted
  collector-local copy: event IDs are deduplicated before filtering
  (conflicting duplicates fail closed), every fill must carry an
  authenticated instrument_market_{market} identity, and USD-M fails
  closed until a derivatives execution path exists.
- Republish verified fee and reference evidence triplets into the
  materialization artifact directory under content-addressed names so
  the digests recorded in the snapshot resolve to immutable bytes.
- Restructure the test fixture per market: the happy path is Spot
  (signed LiveSmall latency evidence exists only for Spot), a new test
  proves USD-M materialization fails closed, and the aggregate-trade
  assertions now match the (previous, current] bucket semantics.
@proerror77
proerror77 force-pushed the codex/lob-pit-materializer-v2 branch from af055b9 to 9806c34 Compare August 10, 2026 06:36
@proerror77
proerror77 marked this pull request as ready for review August 10, 2026 06:37

@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: 9806c349c4

ℹ️ 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 Outdated
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs Outdated
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Sonic Shih added 4 commits August 10, 2026 16:33
- Publish the complete digest-anchored runtime feedback log and the
  trusted-key document into the artifact directory under their content
  digests, so independent readers can reverify every signed lifecycle
  event and no resolvable-evidence gap remains for the key document.
- Charge USD-M funding settlements over each row's actual
  (current, future] holding interval, matching how the evaluator
  applies funding_bps to the held position; a settlement that precedes
  the holding interval is no longer charged and multi-bucket horizons
  collect every settlement.

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
rust_hft/tools/collector/src/bin/lob-pit-materializer.rs (1)

1790-1844: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add coverage for the USD-M end-to-end path and the funding-reschedule branches.

rejects_usdm_without_a_derivatives_execution_path asserts that USD-M materialization fails. charges_funding_over_the_holding_interval calls materialize_rows directly with a hand-built ResearchContextV2. As a result, no test exercises bind_usdm_reference output through a successful materialization. The following new behavior has no assertion:

  • CexDerivativesReferenceV2 assembly, including funding and open_interest CexPitSeriesEvidenceV2 observation counts and max_gap_ns.
  • evaluation_funding_bps_per_bucket population at lines 399-407.
  • The USD-M required-modality set at lines 420-421 and the Funding / OpenInterest row modalities.

Two funding branches at lines 1174-1175 are also unasserted, and the PR objectives call both out:

  • A later pre-settlement observation announces a different next_funding_at, so the settlement is dropped.
  • A replacement observation arrives exactly at the settlement time, so the charge is preserved because the predicate is available_at < scheduled.

Add cases to charges_funding_over_the_holding_interval for both branches, and add a successful USD-M materialization test once the runtime-latency fixture supports the derivatives execution path.

Also applies to: 1875-1887

🤖 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/src/bin/lob-pit-materializer.rs` around lines 1790 -
1844, Add coverage for the USD-M end-to-end materialization path, using the
runtime-latency fixture once it supports derivatives execution, and assert
successful CexDerivativesReferenceV2 assembly, funding/open-interest evidence
counts and max_gap_ns, evaluation_funding_bps_per_bucket, required modalities,
and Funding/OpenInterest row modalities. Extend
charges_funding_over_the_holding_interval to assert both rescheduling branches:
drop a settlement when a later pre-settlement observation changes
next_funding_at, and preserve the charge when a replacement observation arrives
exactly at settlement time.
🤖 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.

Inline comments:
In `@rust_hft/tools/collector/src/bin/lob-pit-materializer.rs`:
- Around line 611-621: Update
rust_hft/tools/collector/src/bin/lob-pit-materializer.rs at lines 611-621 to set
CexArtifactTripletV2.success_sha256 to the SHA-256 hex digest of
success.as_bytes(); at lines 728-734, return the marker digest from
republish_evidence_triplet instead of artifact.data_sha256, and have
republish_evidence_triplet return the digest it computes from the read marker
bytes; at lines 906-914, apply the same marker-digest correction to the USD-M
reference triplet. Extend preserves_report_evidence_and_point_in_time_rows with
assertions that each published _SUCCESS file’s digest matches its recorded
success_sha256.
- Line 185: Update the V2 materialization reader branch to deserialize
CexReplaySnapshotV2, matching the BINANCE_LOB_PIT_MATERIALIZATION_SCHEMA_V3
handling in mission_runner.rs. Replace the stale CexReplaySnapshotV1 type while
preserving the existing V2 materialization flow.
- Around line 399-407: Update the funding bound calculation in the
derivatives_reference mapping to preserve the (current, future] interval
semantics of funding_cost_bps. Ensure evaluation_funding_bps_per_bucket is
either renamed to reflect the full holding interval or populated with a
per-bucket average by applying label_horizon_buckets consistently before
cex_snapshot_costs() compares the values.

---

Nitpick comments:
In `@rust_hft/tools/collector/src/bin/lob-pit-materializer.rs`:
- Around line 1790-1844: Add coverage for the USD-M end-to-end materialization
path, using the runtime-latency fixture once it supports derivatives execution,
and assert successful CexDerivativesReferenceV2 assembly, funding/open-interest
evidence counts and max_gap_ns, evaluation_funding_bps_per_bucket, required
modalities, and Funding/OpenInterest row modalities. Extend
charges_funding_over_the_holding_interval to assert both rescheduling branches:
drop a settlement when a later pre-settlement observation changes
next_funding_at, and preserve the charge when a replacement observation arrives
exactly at settlement time.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d14cd6a0-99f7-4558-9709-5633df43deb0

📥 Commits

Reviewing files that changed from the base of the PR and between 78cbd88 and e55ead8.

⛔ Files ignored due to path filters (1)
  • rust_hft/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • agent-worktree.yml
  • rust_hft/tools/collector/Cargo.toml
  • rust_hft/tools/collector/src/bin/lob-pit-materializer.rs

Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
Comment thread rust_hft/tools/collector/src/bin/lob-pit-materializer.rs
@proerror77
proerror77 merged commit 2fb07d9 into main Aug 10, 2026
81 of 83 checks passed
@proerror77
proerror77 deleted the codex/lob-pit-materializer-v2 branch August 10, 2026 11:21
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