Skip to content

fix(polymarket): bind evidence to explicit episodes - #183

Merged
proerror77 merged 2 commits into
mainfrom
codex/polymarket-explicit-episode-evidence
Jul 20, 2026
Merged

fix(polymarket): bind evidence to explicit episodes#183
proerror77 merged 2 commits into
mainfrom
codex/polymarket-explicit-episode-evidence

Conversation

@proerror77

@proerror77 proerror77 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Change contract

Require every published Polymarket evidence artifact to name its exact non-empty market-ID episode set, and fail closed unless producer selection, v3 manifest, sealed rows, typed verification, and the checked-in Polymarket mission policy pins agree.

Acceptance evidence

  • cargo test --manifest-path rust_hft/prediction-markets/Cargo.toml -p ploy-market-data — 45 passed.
  • cargo test --manifest-path rust_hft/tools/collector/Cargo.toml — 185 passed, 2 existing ignored.
  • Targeted v3 tests prove seal -> verify_polymarket_evidence retains both independent Up/Down token books and rejects an order-book row for an unrequested market.
  • Existing governed-policy test proves both BTC/SOL mission templates pin the current policy fingerprint after the verifier change.
  • git diff --check passes. Linux-only publication tests remain for GitHub CI.

Out of scope

No Binance LOB behavior, collector deployment/cutover, cloud mutation, data publication, snapshot construction/evaluator/MCTS, or execution policy behavior change.

Dependency / merge order

Base: main. Implements issue #182 under PRD issue #181, and unblocks the separate #173 evidence-compile rerun after merge and image publication.

Rollout / rollback impact

No runtime rollout. New compiler outputs use manifest v3 and require explicit --market-id; the verifier retains v2 compatibility for already-published artifacts. Rollback is a source/image rollback with no data overwrite.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 46 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: d4875c91-86b3-4bc2-939f-d9d534de28db

📥 Commits

Reviewing files that changed from the base of the PR and between 43f4d47 and e3937ae.

📒 Files selected for processing (8)
  • 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-market-data/src/polymarket_evidence/artifact.rs
  • rust_hft/prediction-markets/crates/ploy-market-data/src/polymarket_evidence/verified.rs
  • rust_hft/tools/collector/src/bin/polymarket-raw-ops.rs
  • rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
  • rust_hft/tools/collector/src/polymarket_research_normalize.rs
  • rust_hft/tools/collector/src/polymarket_research_select.rs
📝 Walkthrough

Walkthrough

Polymarket evidence selection now requires explicit market IDs. Discovery, normalization, publication, manifest sealing, and verification propagate and enforce those IDs through updated v2/v3 schemas, dynamic symbol lists, and fail-closed validation.

Changes

Explicit market selection and evidence binding

Layer / File(s) Summary
CLI-driven market selection
rust_hft/tools/collector/src/bin/polymarket-raw-ops.rs, rust_hft/tools/collector/src/polymarket_research_select.rs
The publish command requires --market-id; research selection validates requested IDs, filters discovery results, and verifies that every requested market was found.
Dynamic normalized evidence and publication
rust_hft/tools/collector/src/polymarket_research_normalize.rs, rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
Normalized reports use v2 schemas with dynamic market IDs and symbols; published manifests use v3 and the NDJSON filename uses the new evidence prefix.
V3 manifest and row enforcement
rust_hft/prediction-markets/crates/ploy-market-data/src/polymarket_evidence/artifact.rs
Manifest validation supports legacy v2 and explicit v3 contracts, validates selection invariants, and requires evidence rows to match the manifest’s selected markets and symbols.
V3 verification coverage
rust_hft/prediction-markets/crates/ploy-market-data/src/polymarket_evidence/verified.rs
Tests cover successful v3 verification and rejection of rows belonging to an unrequested market.

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

Possibly related issues

Possibly related PRs

  • proerror77/monday#98 — Introduced the immutable Polymarket evidence artifact publisher and CLI extended here for v3 selection.
  • proerror77/monday#96 — Introduced normalization types and logic extended here with v2 reports and explicit selection.
  • proerror77/monday#152 — Modified the evidence sealing and validation path extended here with explicit market-ID enforcement.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as PublishPolymarketEvidence
  participant Selection as ResearchSelection
  participant Normalizer as normalize_raw
  participant Publisher as publish_normalized
  participant Verifier as verify_polymarket_evidence
  CLI->>Selection: provide market_ids
  Selection->>Selection: validate and filter requested markets
  Selection-->>Normalizer: return selected contracts
  Normalizer->>Normalizer: derive market_ids and symbols
  Normalizer-->>Publisher: provide normalized_evidence.v2
  Publisher->>Publisher: emit evidence_artifact.v3 manifest
  Publisher-->>Verifier: provide manifest and evidence triplet
  Verifier->>Verifier: enforce explicit market selection
  Verifier-->>CLI: accept or reject evidence
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% 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 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.
Title check ✅ Passed The title is concise and accurately summarizes the main change: binding Polymarket evidence to explicit episodes.
Description check ✅ Passed The description covers the required contract, validation, dependencies, rollout, and tests, with only the scope-exception section missing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-explicit-episode-evidence

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.

@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 (1)
rust_hft/tools/collector/src/polymarket_evidence_artifact.rs (1)

148-152: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Hardcoded symbol allow-list duplicates the existing SYMBOLS constant in the same crate.

["BTCUSDT", "SOLUSDT"] is inlined here, but polymarket_research_select.rs (same crate, rust_hft/tools/collector) already defines/uses a SYMBOLS constant for the identical allow-list. If the supported symbol set is ever extended, this literal could silently drift from the canonical list and either wrongly reject valid evidence or (if under-restricted) accept an unintended symbol.

♻️ Suggested fix: reuse the shared constant
-        || report
-            .symbols
-            .iter()
-            .any(|symbol| !["BTCUSDT", "SOLUSDT"].contains(&symbol.as_str()))
+        || report
+            .symbols
+            .iter()
+            .any(|symbol| !crate::polymarket_research_select::SYMBOLS.contains(&symbol.as_str()))
#!/bin/bash
# Confirm SYMBOLS visibility in polymarket_research_select.rs to validate reuse is feasible
rg -n 'const SYMBOLS' rust_hft/tools/collector/src/polymarket_research_select.rs
🤖 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/polymarket_evidence_artifact.rs` around lines
148 - 152, Replace the inline symbol allow-list in the report validation
condition with the existing shared SYMBOLS constant from
polymarket_research_select, preserving the current empty-symbol and
unsupported-symbol checks. Ensure the constant is accessible from
polymarket_evidence_artifact and use it as the sole source of supported symbols.
🤖 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/tools/collector/src/polymarket_evidence_artifact.rs`:
- Around line 148-152: Replace the inline symbol allow-list in the report
validation condition with the existing shared SYMBOLS constant from
polymarket_research_select, preserving the current empty-symbol and
unsupported-symbol checks. Ensure the constant is accessible from
polymarket_evidence_artifact and use it as the sole source of supported symbols.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4b4a7fe-8770-45a9-b1be-6885202728e6

📥 Commits

Reviewing files that changed from the base of the PR and between d47527a and 43f4d47.

📒 Files selected for processing (6)
  • rust_hft/prediction-markets/crates/ploy-market-data/src/polymarket_evidence/artifact.rs
  • rust_hft/prediction-markets/crates/ploy-market-data/src/polymarket_evidence/verified.rs
  • rust_hft/tools/collector/src/bin/polymarket-raw-ops.rs
  • rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
  • rust_hft/tools/collector/src/polymarket_research_normalize.rs
  • rust_hft/tools/collector/src/polymarket_research_select.rs

@proerror77
proerror77 force-pushed the codex/polymarket-explicit-episode-evidence branch from 43f4d47 to 9847c88 Compare July 20, 2026 16:35
@proerror77
proerror77 merged commit 500771f into main Jul 20, 2026
31 checks passed
@proerror77
proerror77 deleted the codex/polymarket-explicit-episode-evidence branch July 22, 2026 00:31
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