Skip to content

feat(polymarket): publish event candidate evidence - #338

Merged
proerror77 merged 1 commit into
mainfrom
codex/event-candidate-evidence-336
Jul 24, 2026
Merged

feat(polymarket): publish event candidate evidence#338
proerror77 merged 1 commit into
mainfrom
codex/event-candidate-evidence-336

Conversation

@proerror77

@proerror77 proerror77 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Change contract

For each source-closed explicit Polymarket event, publish one event-local, content-addressed, no-clobber candidate triplet containing only the evidence rows that actually exist, while keeping the complete evidence path strict and treating every candidate as an untrusted producer carrier that requires independent verification.

Closes #336.

Out of scope

Independent Ready/Partial/Rejected verification, catalog receipts and queries, OSS acquisition/downloading, cohort or snapshot construction, evaluator/MCTS behavior, deployment, and collector cutover.

Dependency / merge order

Depends on #318 / PR #330 (merged). Merge this PR before #337, then #319.

Focused validation

  • cargo test -p hft-collector --locked — pass (216 lib tests passed, 2 ignored; all binary/integration groups passed)
  • cargo test -p hft-collector --locked candidate_normalization_preserves_zero_missing_surfaces_without_rows — pass through the real segment-validation and public candidate-normalization seam
  • cargo test -p hft-collector --locked event_local_trade_union_allows_sparse_reference_hours — pass; complete trust boundary remains strict
  • cargo check -p hft-collector --tests --locked --target x86_64-unknown-linux-gnu — pass; Linux-only no-clobber/publication counterexamples compile
  • rustfmt --check on all four touched Rust files — pass
  • git diff --check — pass
  • Matt Standards review — PASS at exact head edca5290e787e6c45cdd0bcab38e53a167d64425
  • Matt Spec review — PASS at the same exact head
  • Scope guardrail — 4 files, 670 additions + 78 deletions = 748 changed lines

Safety counterexamples

  • Missing Down book, trade completion, Chainlink reference, and settlement remain explicit zero-count surfaces; no rows are synthesized.
  • A complete sibling event cannot fill the selected event's missing token LOB.
  • Candidate token repair cannot promote a candidate qualification to Ready; it remains Partial + independent_verification_required.
  • A present completion proof is verified; an absent proof is accurately disclosed in candidate manifest semantics.
  • Same bytes replay as Unchanged; conflicting bytes at the immutable path fail closed.

Rollout / rollback impact

No runtime rollout in this PR. Rollback removes candidate publication and restores qualification-only handling for non-Ready events; the existing complete v2/v3 evidence path is unchanged.

Summary by CodeRabbit

  • New Features

    • Added support for publishing candidate evidence when complete independent verification is not yet available.
    • Candidate evidence now includes dedicated validation, manifests, integrity checks, and qualification status.
    • Added candidate-specific normalization for single-market evidence with flexible completion requirements.
    • Added clearer qualification results indicating when independent verification is required.
  • Bug Fixes

    • Improved handling of sparse evidence surfaces, preserving valid candidates even when some data types have no rows.
    • Refined research selection and validation to apply appropriate coverage requirements across evidence modes.

@coderabbitai

coderabbitai Bot commented Jul 24, 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: 52 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 Plus

Run ID: 210e22a5-fe8f-4418-90cd-5e50f7460a24

📥 Commits

Reviewing files that changed from the base of the PR and between edca529 and e35428c.

📒 Files selected for processing (4)
  • rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
  • rust_hft/tools/collector/src/polymarket_research_import.rs
  • rust_hft/tools/collector/src/polymarket_research_normalize.rs
  • rust_hft/tools/collector/src/polymarket_research_select.rs
📝 Walkthrough

Walkthrough

The collector adds candidate Polymarket evidence normalization and immutable triplet publication for non-ready events, with candidate-specific validation, manifests, qualifications, surface counts, and replay/no-clobber tests.

Changes

Polymarket candidate evidence

Layer / File(s) Summary
Candidate selection and surface validation
rust_hft/tools/collector/src/polymarket_research_select.rs, rust_hft/tools/collector/src/polymarket_research_import.rs
Selection and validation now use separate quote-coverage and evidence-surface controls, allowing candidate inputs to omit absent evidence surfaces.
Candidate evidence normalization
rust_hft/tools/collector/src/polymarket_research_normalize.rs, rust_hft/tools/collector/src/polymarket_research_import.rs
Candidate normalization selects exactly one market, validates present completion proofs, computes explicit surface counts, and emits candidate evidence data and NDJSON.
Candidate artifact contracts and manifests
rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
Candidate publication types, qualification input construction, dataset validation, manifest generation, and candidate verifier metadata are added.
Candidate publication and batch qualification
rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
Non-ready events can publish candidate triplets and candidate qualifications, while immutable replay, no-clobber behavior, and candidate publication scenarios are tested.

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

Sequence Diagram(s)

sequenceDiagram
  participant Collector
  participant CandidateNormalizer
  participant CandidatePublisher
  participant Qualification
  Collector->>CandidateNormalizer: normalize candidate event
  CandidateNormalizer->>CandidatePublisher: provide candidate data and manifest inputs
  CandidatePublisher->>Qualification: bind candidate digests and verifier contract
  Qualification-->>Collector: return candidate artifact and qualification
Loading

Possibly related issues

  • proerror77/monday issue 337: Concerns incomplete Polymarket candidate evidence and independent verification.
  • proerror77/monday issue 319: Describes the candidate evidence path used by independent ready/partial event verification.
  • proerror77/monday issue 318: Defines foundational immutable event qualification behavior used by this publication pipeline.

Possibly related PRs

  • proerror77/monday#96: Introduced the normalization module extended here with candidate evidence types and entrypoints.
  • proerror77/monday#98: Established the immutable evidence publication pipeline extended here for candidate triplets.
  • proerror77/monday#286: Modified the same research import and selection validation paths extended for candidate requirements.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.91% 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 matches the main change: publishing Polymarket candidate evidence.
Description check ✅ Passed The description includes all major required sections and is detailed, though Scope exception is omitted.
Linked Issues check ✅ Passed The changes implement the candidate triplet, no-clobber publication, per-surface counts, digest binding, and strict Ready-path preservation required by #336.
Out of Scope Changes check ✅ Passed The diff stays within candidate-evidence publication, normalization, and selection logic; no unrelated work stands out.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/event-candidate-evidence-336

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: edca5290e7

ℹ️ 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 mut event_config = config.evidence.clone();
event_config.market_ids = vec![market_id.clone()];
match normalize_candidate(&event_config).and_then(|evidence| {

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 Fall back to candidate publication when complete verification fails

When a source-closed producer declares an event Ready but the actual tape is missing a surface, execution bypasses this candidate branch, complete normalization fails, and the later deterministic-error arm publishes only a rejected qualification. Thus an untrusted readiness claim can suppress the sparse candidate triplet containing the evidence rows that do exist; run candidate normalization after deterministic complete-verification failures as well.

Useful? React with 👍 / 👎.

.filter(|_| contracts.len() == 1)
.ok_or_else(|| anyhow!("candidate evidence requires exactly one market"))?;
let (trades, settlements) = reference_records(reference_path, contracts)?;
let completions = aggregated_trade_completions(inputs)?;

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 Scope completion aggregation to the candidate event

When two accepted reference segments contain a completion proof for the same sibling market, this call fails before producing the selected event's candidate because aggregated_trade_completions aggregates every market and rejects every duplicate. Same-hour/sparse multi-segment inputs are otherwise admitted and sibling trades and settlements are explicitly deduplicated, so an unrelated repeated proof can suppress a valid event-local candidate; filter completion identities to the selected market before checking duplicates.

Useful? React with 👍 / 👎.

validate_candidate_dataset(&evidence)?;
ensure_canonical_directory(output_root)?;
let digest = &evidence.report.content_sha256;
let directory = output_root.join(format!("sha256={digest}"));

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 Include provenance in the candidate artifact identity

When the same event rows are normalized from a different valid source triplet or reference set containing only changed sibling data, the NDJSON digest remains unchanged while the manifest changes because it embeds validated_inputs. Since the directory and manifest filename here are keyed only by the NDJSON digest, the second publication encounters the first manifest with different bytes and fails no-clobber instead of publishing the otherwise valid candidate; incorporate the manifest/provenance digest into the immutable identity or make the manifest a function of the content bytes alone.

Useful? React with 👍 / 👎.

@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_research_select.rs (1)

508-538: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Two positional bool control inputs are swap-prone. event_local and require_quote_coverage are both plain booleans passed positionally at three call sites. They also overlap: when require_quote_coverage == true, event_local is ignored entirely. A future caller (or an accidental argument swap, e.g. candidate's (true, false) becoming (false, true)) would silently switch the segment-validation pipeline and quote-coverage enforcement without a compile error. Consider collapsing these into a single explicit policy enum (e.g. Strict / EventLocal / Candidate) so each flow selects exactly one variant.

🤖 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_research_select.rs` around lines 508
- 538, The with_selected_research_contracts_policy API uses two overlapping
positional booleans that can be swapped without compiler errors. Replace
event_local and require_quote_coverage with a single explicit policy enum
representing the strict, event-local, and candidate flows, then update the three
call sites and the dispatch logic in with_selected_research_contracts_policy so
each variant selects exactly one validation pipeline and preserves
quote-coverage enforcement for the strict path.
🤖 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_research_select.rs`:
- Around line 508-538: The with_selected_research_contracts_policy API uses two
overlapping positional booleans that can be swapped without compiler errors.
Replace event_local and require_quote_coverage with a single explicit policy
enum representing the strict, event-local, and candidate flows, then update the
three call sites and the dispatch logic in
with_selected_research_contracts_policy so each variant selects exactly one
validation pipeline and preserves quote-coverage enforcement for the strict
path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d3afbaa-4da9-454e-8487-8256a5b30315

📥 Commits

Reviewing files that changed from the base of the PR and between 0e99711 and edca529.

📒 Files selected for processing (4)
  • rust_hft/tools/collector/src/polymarket_evidence_artifact.rs
  • rust_hft/tools/collector/src/polymarket_research_import.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/event-candidate-evidence-336 branch from edca529 to e35428c Compare July 24, 2026 06:49
@proerror77
proerror77 merged commit d5dabc5 into main Jul 24, 2026
36 checks passed
@proerror77
proerror77 deleted the codex/event-candidate-evidence-336 branch July 24, 2026 08:44
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.

Publish immutable event-local Polymarket candidate evidence

1 participant