Skip to content

fix(polymarket): admit bounded quote recovery - #286

Merged
proerror77 merged 1 commit into
mainfrom
codex/polymarket-bounded-recovery-283
Jul 23, 2026
Merged

fix(polymarket): admit bounded quote recovery#286
proerror77 merged 1 commit into
mainfrom
codex/polymarket-bounded-recovery-283

Conversation

@proerror77

@proerror77 proerror77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Change contract

For explicit market evidence only, accept a source-closed, content-addressed market tape whose global canonical/complete flags are false because of unrelated market coverage or disclosed transient quote failures, provided every selected Up/Down token has full-depth 1-second quotes and each selected failure/gap recovers within 30 seconds.

Out of scope

Collector runtime or deployment changes; reference acquisition; verifier semantics owned by #284/#285; snapshot, evaluator/MCTS, and publication logic; fabricated or rewritten source evidence.

Dependency / merge order

#285 is merged at dc0331d. This PR must merge before evidence compilation in #270. No stacked PR remains.

Focused validation

  • cargo test -p hft-collector explicit_market_ -- --nocapture
  • cargo test -p hft-collector
  • cargo clippy -p hft-collector --all-targets --no-deps -- -D warnings
  • rustfmt --edition 2021 --check on the two changed files
  • git diff --check
  • Independent spec and standards reviews: 0 blocking findings
  • Counterexamples cover unresolved/late recovery, silent gaps over 30 seconds, missing token coverage, incomplete quote quality, source-open tape, sequence gaps, and truncated depth

Rollout / rollback impact

The relaxation is reachable only through explicit-market normalization; the strict importer remains fail-closed. Rollback is a single commit and restores rejection of globally noncanonical tapes. No runtime collector rollout occurs in this PR.

A PRD is unnecessary because this is the focused defect contract already scoped in #283 and implemented test-first.

Closes #283

Summary by CodeRabbit

  • New Features

    • Added event-local recovery for selected market research when bounded quote collection failures occur.
    • Added quote coverage checks to verify timely, continuous market quotes and successful recovery within the allowed window.
  • Bug Fixes

    • Improved validation of quote freshness, continuity, discovery timing, and segment-end availability.
    • Preserved strict validation for market identity, reference data, and depth requirements during recovery.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Event-local Polymarket validation now permits bounded quote recovery, adds selected-token quote coverage checks, and preserves strict validation for reference segments and non-event-local imports.

Changes

Polymarket quote recovery

Layer / File(s) Summary
Event-local import policy
rust_hft/tools/collector/src/polymarket_research_import.rs
Adds conditional completeness and event-type validation for primary market segments while keeping reference and strict paths unchanged.
Selected-token quote coverage
rust_hft/tools/collector/src/polymarket_research_select.rs
Validates quote freshness, recovery timing, continuity gaps, discovery timing, and bounded segment-end coverage before consumption.
Recovery validation tests
rust_hft/tools/collector/src/polymarket_research_import.rs
Adds helpers and explicit-market tests for bounded recovery and rejection of incomplete, unbounded, contradictory, or non-full-depth evidence.

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

Possibly related issues

  • Issue 284 — Related event-local handling of authenticated quote_collection_failure events in verifier acceptance.
  • Issue 270 — Uses the event-local quote recovery validation in the selected evidence-cohort workflow.

Possibly related PRs

  • proerror77/monday#152 — Extends related event-local completion and event-type validation in the research importer.
  • proerror77/monday#154 — Adjusts overlapping Polymarket allowed event-type handling in the collector.
  • proerror77/monday#238 — Adds the quote_collection_failure update path consumed by this validation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.09% 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 is concise and accurately reflects the main change: admitting bounded quote recovery for Polymarket.
Description check ✅ Passed All required sections are present and substantively filled out; the template is mostly followed.
Linked Issues check ✅ Passed The code changes match #283 by allowing explicit-market recovery within 30s while keeping strict non-explicit validation intact.
Out of Scope Changes check ✅ Passed The diff stays within collector research-import/select policy and tests, with no runtime, deployment, or verifier changes.
✨ 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-bounded-recovery-283

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

133-165: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use the earlier fallback when validating quote recovery gaps.

The recovery message is only reachable after a failure and before any successful quote has set last_recorded_at. For the interrupted-stream case—where an earlier quote exists—the code rejects as a generic availability gap before reaching the recovery branch, so callers may not see the intended recovery-specific validation. Either surface the same recovery failure for recovered-outstanding failures, or fold it back into a clearer recovery-specific check.

🤖 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 133
- 165, Update the quote handling branch in the collector so pending_failure_at
is validated before the last_recorded_at availability-gap check. Ensure
interrupted streams with an earlier quote use the recovery-specific 30-second
validation and error, while retaining the existing gap checks for quotes without
a pending failure.
🤖 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 133-165: Update the quote handling branch in the collector so
pending_failure_at is validated before the last_recorded_at availability-gap
check. Ensure interrupted streams with an earlier quote use the
recovery-specific 30-second validation and error, while retaining the existing
gap checks for quotes without a pending failure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 97303ac7-e991-4bd1-907b-d22f1659f625

📥 Commits

Reviewing files that changed from the base of the PR and between dc0331d and 06dbcb5.

📒 Files selected for processing (2)
  • rust_hft/tools/collector/src/polymarket_research_import.rs
  • rust_hft/tools/collector/src/polymarket_research_select.rs

@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: 06dbcb55c0

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

if state.pending_failure_at.is_some() {
bail!("selected token {token} has an unresolved quote collection failure");
}
let coverage_end = segment_end.min(contract.event_end);

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 Validate coverage through the selected market window

When a tape with a recovered quote failure ends before the selected contract does—for example, collection stops at 05:01 for a 05:00–05:05 market—using the observed segment_end as the boundary lets the last quote at shutdown pass even though the remaining market interval is absent. This artifact can reach the relaxed path because scan_tape always emits source_session_closed: true and does not prove that the UTC partition completed (polymarket_upload.rs:1389-1412); before this change its disclosed failure made it noncanonical and fail closed. Measure the trailing gap against the earlier of event_end and the segment's UTC-hour boundary rather than the last observed record.

Useful? React with 👍 / 👎.

@proerror77
proerror77 merged commit f5affe7 into main Jul 23, 2026
20 of 21 checks passed
@proerror77
proerror77 deleted the codex/polymarket-bounded-recovery-283 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.

Prediction evidence: admit only bounded recovered quote gaps per explicit market

1 participant