Skip to content

feat(polymarket): select governed research contracts - #93

Merged
proerror77 merged 2 commits into
mainfrom
codex/polymarket-research-surfaces
Jul 17, 2026
Merged

proerror77 merged 2 commits into
mainfrom
codex/polymarket-research-surfaces

Conversation

@proerror77

Copy link
Copy Markdown
Owner

Change contract: Select exactly one governed BTCUSDT and one governed SOLUSDT five-minute Polymarket contract per requested slot from already-validated market/reference research segments, and emit the bound metadata needed for downstream research without reopening raw validation.

Out of scope: Normalizing selected contracts into later research surfaces, artifact publication/materialization, trading/runtime activation, and any change to raw segment validation beyond exposing the validated paths/closure seam this selector needs.

Dependency or merge order: Base is main; validator PR #89 (feat(polymarket): validate research raw segments) was merged into main on July 17, 2026 before this PR. Merge this PR after that base only.

Focused validation:

  • cargo +1.91 fmt -p hft-collector -- --check
  • cargo +1.91 test --locked -p hft-collector --lib
  • cargo +1.91 test --locked -p hft-collector polymarket_research_select::tests::
  • cargo +1.91 clippy --locked -p hft-collector --lib --features collector-binance --no-deps -- -D warnings

Rollout/rollback impact: Rollout is research-only and fail-closed; no live execution path changes. Rollback is reverting this PR, which removes selector/export reporting while leaving merged raw-segment validation intact.

Notes: Diff is 3 files, +602/-11, one Research selector contract under the 750-line split threshold. The selector now rejects invalid market_metadata.retrieved_at timestamps before emitting a validated report.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@proerror77, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 51 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b669c88-ae10-44b9-a66d-43cc4206d889

📥 Commits

Reviewing files that changed from the base of the PR and between 3aaf49b and 05eb7f7.

📒 Files selected for processing (3)
  • rust_hft/tools/collector/src/lib.rs
  • rust_hft/tools/collector/src/polymarket_research_import.rs
  • rust_hft/tools/collector/src/polymarket_research_select.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-research-surfaces

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

@proerror77
proerror77 merged commit 11bc92b into main Jul 17, 2026
16 checks passed
@proerror77
proerror77 deleted the codex/polymarket-research-surfaces branch July 17, 2026 10:14

@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: 05eb7f7f68

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

let (start, end) = selection(config)?;
with_validated_research_segments(&config.segments, |inputs, market_path, reference_path| {
let mut contracts = discover(market_path, start, end)?;
enrich_metadata(reference_path, &mut contracts)?;

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 Require settlement coverage for selected contracts

When the selected interval includes a market that has metadata but no market_settlement record, this still succeeds because the input validation only requires at least one settlement somewhere in the reference segment and this path only enriches selected IDs from market_metadata. That allows select_research_contracts to report unlabelled/open contracts as governed research inputs, which can corrupt settlement-probability training or evaluation that relies on official Polymarket resolutions; please scan market_settlement for every selected market and fail closed when any selected contract is missing its official label.

Useful? React with 👍 / 👎.

metadata_recorded_at: metadata.recorded_at.clone(),
discovery_source_sequence: contract.discovery_sequence,
metadata_source_sequence: metadata.sequence,
raw_market: metadata.raw_market.clone(),

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 Redact post-settlement fields from raw metadata

When the first market_metadata row for a selected market comes from the collector's closed-market lane, the raw Gamma market can already contain closed/outcomePrices; I checked that closed markets are discovered in polymarket_raw.rs:1609 and metadata is emitted before settlement at polymarket_raw.rs:1895-1903. Emitting that full raw_market in the selection report gives downstream research access to label-like post-settlement fields before the official label path, so either require pre-close metadata here or redact settlement/result fields before exposing it.

Useful? React with 👍 / 👎.

.and_then(Value::as_str)
})
.ok_or_else(|| anyhow!("raw market has no event start"))?;
timestamp(value, "raw market event start")

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 Preserve accepted Gamma timestamp formats

For markets whose Gamma startDate/event start uses the offset-less format already accepted by validate_market_metadata/scan_tape (for example 2026-07-17T05:30:00), this new RFC3339-only parse rejects an otherwise validated research segment before selection. Use the same market timestamp parser/normalization as the upload validator for raw market start and end times, otherwise valid archived metadata can no longer be selected.

Useful? React with 👍 / 👎.

event_end,
up_token,
down_token,
price_to_beat: decimal_text(update.get("price_to_beat"), "price_to_beat")?,

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 Bind selected thresholds to Chainlink evidence

This copies price_to_beat from event_discovered but the selector never verifies that the selected market has a Chainlink reference_price observation at the event opening; the segment validator only proves there is at least one reference price somewhere in the hour. A selected slot with a missing or stale opening Chainlink tick can therefore be reported as governed and anchor downstream probabilities to an unverifiable threshold, so selection should fail closed unless each selected contract has the required point-in-time Chainlink opening reference.

Useful? React with 👍 / 👎.

Comment on lines +314 to +315
let tokens = json_strings(market.get("clobTokenIds"), "clobTokenIds")?;
let outcomes = json_strings(market.get("outcomes"), "outcomes")?;

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 Accept native Gamma token arrays

For reference metadata whose raw Gamma clobTokenIds/outcomes are native JSON arrays, the segment already passes validate_market_metadata because the upload validator accepts both arrays and JSON-encoded strings, but this selector now requires a JSON string and rejects the same validated input. Mirror the existing parser here so governed selection does not fail on otherwise valid archived market metadata.

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.

1 participant