feat(polymarket): select governed research contracts - #93
Conversation
|
Warning Review limit reached
Next review available in: 51 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@codex review |
There was a problem hiding this comment.
💡 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)?; |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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")?, |
There was a problem hiding this comment.
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 👍 / 👎.
| let tokens = json_strings(market.get("clobTokenIds"), "clobTokenIds")?; | ||
| let outcomes = json_strings(market.get("outcomes"), "outcomes")?; |
There was a problem hiding this comment.
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 👍 / 👎.
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 intomainon July 17, 2026 before this PR. Merge this PR after that base only.Focused validation:
cargo +1.91 fmt -p hft-collector -- --checkcargo +1.91 test --locked -p hft-collector --libcargo +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 warningsRollout/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_attimestamps before emitting a validated report.