Skip to content

Build verified Polymarket + Chainlink baseline snapshots - #228

Merged
proerror77 merged 1 commit into
mainfrom
codex/polymarket-chainlink-baseline
Jul 22, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/polymarket-chainlink-baseline

Conversation

@proerror77

@proerror77 proerror77 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Closes #226
Parent: #225
Follow-up consumer admission: #227

Change contract

Add one explicit verified Polymarket + Chainlink baseline profile that builds and seals the existing ResearchSnapshot from anchored Polymarket evidence while recording every Binance surface as intentionally omitted and leaving all current evaluator, trainer, and full-surface behavior fail-closed and unchanged.

Out of scope

Evaluator or MCTS admission; consumer component eligibility; collector code or deployment; fabricated or historical Binance backfill; Paper or Live; OMS or RiskGate; 15-minute or 1-hour products; profitability claims; #189 retirement.

Dependency or merge order

Depends only on verified immutable Polymarket evidence and ResearchSnapshot seams already on main. Merge this PR before starting #227. #227 is the separate consumer rollout unit and must not be merged first.

Focused validation

  • cargo test -p ploy-research — 282 passed
  • cargo test -p ploy-research --features db --bin monday-prediction-snapshot — 7 passed
  • cargo test -p alpha-harness prediction_snapshot::tests — 7 passed
  • cargo clippy --locked -p ploy-research --features ml --all-targets --no-deps -- -D warnings
  • cargo clippy --locked -p alpha-harness -- -D warnings
  • cargo fmt --check --package ploy-research
  • cargo fmt --check --package alpha-harness
  • Two independent read-only code reviews: APPROVE, zero findings

Targeted counterexamples prove that baseline mode rejects Binance segment arguments, requires both Up and Down token books, rejects stale Chainlink availability, clears all unavailable CEX and continuous-path numeric features to NaN, and round-trips the sealed baseline manifest plus both snapshot digests.

Rollout or rollback impact

Rollout is opt-in through --polymarket-chainlink-baseline; no existing command selects it implicitly. Current evaluator, MCTS, report, and trainer paths continue rejecting the reduced-authority profile. Rollback removes the profile and builder; immutable baseline snapshots remain provenance-readable but are not reclassified or admitted to research consumers.

Summary by CodeRabbit

  • New Features

    • Added support for building prediction snapshots from Polymarket and Chainlink baseline evidence.
    • Added a dedicated baseline mode with validation for compatible symbols, inputs, and five-minute windows.
    • Baseline snapshots now clearly identify omitted Binance-derived data and preserve missing numeric values appropriately.
    • Updated BTC and SOL research mission examples to use refreshed snapshot references.
  • Bug Fixes

    • Improved handling of nullable numeric factor values during snapshot processing.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 040f81de-a207-44a8-ac3f-87ab54b372d6

📥 Commits

Reviewing files that changed from the base of the PR and between bc7f723 and 39f1c84.

📒 Files selected for processing (7)
  • rust_hft/alpha-harness/app/src/prediction_snapshot.rs
  • rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.json
  • rust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.json
  • rust_hft/prediction-markets/crates/ploy-research/src/bin/monday-prediction-snapshot.rs
  • rust_hft/prediction-markets/crates/ploy-research/src/factors.rs
  • rust_hft/prediction-markets/crates/ploy-research/src/lib.rs
  • rust_hft/prediction-markets/crates/ploy-research/src/research_snapshot.rs

📝 Walkthrough

Walkthrough

Adds an opt-in Polymarket + Chainlink baseline snapshot path. It validates exclusive CLI modes, omits Binance-derived surfaces, derives aligned Polymarket ticks, records baseline manifest metadata, handles nullable factors as NaN, and updates wrapper forwarding and mission snapshot identifiers.

Changes

Baseline snapshot pipeline

Layer / File(s) Summary
Nullable factor and baseline binding semantics
rust_hft/prediction-markets/crates/ploy-research/src/factors.rs, rust_hft/prediction-markets/crates/ploy-research/src/research_snapshot.rs
Nullable factor values now deserialize as NaN; baseline binding clears Binance freshness and derived-feature placeholders.
Baseline snapshot construction and manifest
rust_hft/prediction-markets/crates/ploy-research/src/research_snapshot.rs
Polymarket Up/Down books provide baseline ticks, while the new builder validates evidence and records omitted-Binance metadata.
Baseline CLI mode and execution routing
rust_hft/prediction-markets/crates/ploy-research/src/bin/monday-prediction-snapshot.rs
Adds explicit baseline parsing, rejects Binance segments in that mode, routes to the baseline builder, and tests the behavior.
Public exports and wrapper/config integration
rust_hft/prediction-markets/crates/ploy-research/src/lib.rs, rust_hft/alpha-harness/app/src/prediction_snapshot.rs, rust_hft/prediction-markets/config/research_missions/*.json
Re-exports baseline APIs, accepts the wrapper flag, and updates BTC/SOL mission snapshot identifiers.

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

Sequence Diagram(s)

sequenceDiagram
  participant CLI as monday-prediction-snapshot
  participant Evidence as VerifiedPolymarketEvidenceSet
  participant Builder as baseline snapshot builder
  participant Snapshot as ResearchSnapshot
  CLI->>Evidence: verify anchored Polymarket artifacts
  CLI->>Builder: request baseline snapshot
  Builder->>Evidence: read books, settlements, and Chainlink evidence
  Builder->>Snapshot: bind observations and write baseline manifest
  Snapshot-->>CLI: return sealed ResearchSnapshot
Loading

Possibly related issues

Possibly related PRs

  • proerror77/monday#133 — Adds the verified-artifacts snapshot pipeline and related observation binding in the same module.
  • proerror77/monday#209 — Extends the same prediction snapshot CLI with Polymarket-specific modes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.33% 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
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding verified Polymarket + Chainlink baseline snapshot support.
Description check ✅ Passed The description covers all major template sections; only the optional Scope exception section is omitted.
Linked Issues check ✅ Passed The changes satisfy #226: baseline CLI, Binance rejection, full-surface unchanged, manifest/digest handling, and fail-closed tests are present.
Out of Scope Changes check ✅ Passed The config and serde-helper updates support the baseline path and do not introduce unrelated behavior.
✨ 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/polymarket-chainlink-baseline

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
rust_hft/prediction-markets/config/research_missions/polymarket-btc-5m.example.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'

rust_hft/prediction-markets/config/research_missions/polymarket-sol-5m.example.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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: 39f1c84712

ℹ️ 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 +867 to +874
let observations =
crate::factors::build_unlabeled_factor_observations_with_lob_sampled_and_source_clocks(
&polymarket_updates,
&[],
&[],
options.max_quote_age_secs,
options.observation_sample_secs,
);

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 Use the accepted pre-open Chainlink reference

With the default max_quote_age_secs=30 and a valid artifact containing the verifier's required pre-open reference per event, project_verified_polymarket_evidence forwards only references whose source time is before the event start, while the factor builder does not set chainlink_price_to_beat until it sees a post-start reference. Consequently the book-driven observations created here all have chainlink_reference_fresh == false, and baseline binding rejects every row, so this mode cannot build a snapshot from the evidence contract it claims to support. Bind the verified pre-open reference directly or introduce a causal boundary transition that does not require an unavailable post-start reference.

Useful? React with 👍 / 👎.

Comment on lines +773 to +775
ensure!(
polymarket.event_start_gte() <= options.start && polymarket.event_start_lt() >= options.end,
"verified Polymarket evidence does not cover the baseline snapshot window"

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 Reject gaps inside the requested evidence window

When repeated anchored artifacts omit an intermediate range, this aggregate min/max check still passes because VerifiedPolymarketEvidenceSet explicitly permits gaps between members (polymarket_evidence/set.rs:390-404). For example, members covering 05:30 and 05:40 can satisfy a 05:30–05:45 request while the 05:35 cohort is absent; the remaining per-contract checks can pass and the sealed manifest still claims the entire requested interval. Validate that member ranges or selected five-minute contract slots are contiguous across [start, end) before constructing the snapshot.

Useful? React with 👍 / 👎.

} else {
anyhow::bail!("baseline token book identity does not match its event contract");
}
if has_up && has_down && emitted.insert(book.ts) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require contemporaneous books before emitting baseline ticks

When the Up and Down streams are separated by more than max_quote_age_secs, these persistent booleans still emit a tick as soon as each side has appeared at least once and continue emitting after either stream stops. The factor builder permits a row when only one ask remains fresh, so such ticks produce one-sided observations with fair_prob_up and related Polymarket probability fields set to NaN while the baseline manifest still reports the CLOB surface as sampled and healthy. Track the latest timestamp for each side and emit only when both token books are fresh at the candidate tick.

Useful? React with 👍 / 👎.

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.

Build verified Polymarket + Chainlink baseline ResearchSnapshot path

1 participant