Skip to content

fix(polymarket): verify executable top against depth - #303

Merged
proerror77 merged 1 commit into
mainfrom
codex/polymarket-tradeable-top-302
Jul 23, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/polymarket-tradeable-top-302

Conversation

@proerror77

@proerror77 proerror77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Change contract

Verify each Polymarket top bid/ask against the unique best executable level in retained full depth using the collector's strict 0.02 < price < 0.98 predicate; accept an absent top only when that side has no executable level.

Closes #302.

Out of scope

Collector or producer behavior; evidence bytes, manifests, digests, or republishing; snapshot sampling; research projection; evaluator/MCTS; execution policy; Paper or Live.

Dependency / merge order

Independent focused verifier fix on current main. Merge this PR, publish its exact-main research image, then rerun #232 against the unchanged evidence anchor. No stacked PR.

Focused validation

  • cargo test -p ploy-market-data — 63 passed
  • cargo test -p ploy-research checked_in_btc_and_sol_templates_pin_current_brief_and_rust_policy -- --nocapture — passed
  • cargo fmt -p ploy-market-data -- --check — passed
  • cargo clippy -p ploy-market-data --all-targets --no-deps -- -D warnings — passed
  • git diff --check — passed
  • Exact-boundary positive fixture covers ask depth 0.02/0.03 with top 0.03 and complementary bid depth 0.98/0.97 with top 0.97.
  • Counterexamples cover missing executable top, non-executable top, wrong price/size, duplicate best level, and a crossed executable book whose top still matches depth.
  • Independent spec and standards reviews: APPROVE, no blockers.

Cloud reproduction / pending acceptance

snapshot-issue232-main-0724b failed at the old absolute-depth predicate. Pinned read-only diagnostic snapshot-issue232-book-tradeable-proof-0724b checked all 532 book rows, retained 2,128 boundary levels, and found zero top mismatches under the collector predicate. Post-merge exact-main cloud acceptance remains pending by design.

Rollout / rollback impact

One verifier predicate plus targeted tests and mechanically required governed mission pins. Rollout is the exact-main research image; rollback is a one-commit revert. Immutable evidence and successful artifacts are unchanged.

Workflow

Matt diagnosing-bugs established the cloud counterexample; Matt TDD reproduced it before the surgical fix; Matt implement and two-axis code-review completed the focused issue. A PRD was unnecessary because this is one reproduced producer/verifier contract drift.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Polymarket order book validation by focusing on executable market depth, while correctly preserving non-tradeable boundary levels.
    • Added safeguards to reject crossed or inconsistent executable top-of-book data.
    • Improved handling when only boundary depth is available.
  • Configuration

    • Updated search policy snapshots for BTC and SOL five-minute research missions.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b82abc0-2cac-450c-a100-ed3408527d57

📥 Commits

Reviewing files that changed from the base of the PR and between 888c3fe and 3fd723c.

📒 Files selected for processing (3)
  • 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/verified.rs

📝 Walkthrough

Walkthrough

The PR updates two Polymarket research mission snapshot identifiers and changes orderbook verification to compare top-of-book values with executable depth, including boundary-level handling, crossed-book rejection, and targeted tests.

Changes

Polymarket orderbook verification

Layer / File(s) Summary
Executable depth matching and validation
rust_hft/prediction-markets/crates/ploy-market-data/src/polymarket_evidence/verified.rs
validate_book now matches bids and asks against the best tradeable depth level, preserves boundary levels, updates rejection text, and adds coverage for executable, crossed, and boundary-only cases.

Research mission policy snapshots

Layer / File(s) Summary
Mission snapshot references
rust_hft/prediction-markets/config/research_missions/polymarket-{btc,sol}-5m.example.json
The BTC and SOL five-minute mission examples reference new search_policy_snapshot_id SHA-256 values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • proerror77/monday#145: Updates the same BTC/SOL research mission snapshot identifiers, but changes a different substantive pipeline.
  • proerror77/monday#146: Updates the same mission snapshot identifiers, while its substantive logic concerns repricing and fillability.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main verifier fix and matches the changeset.
Description check ✅ Passed The description is mostly complete and matches the template; only the optional Scope exception section is not explicitly written as None.
Linked Issues check ✅ Passed The verifier now checks the unique executable top against depth and preserves the required edge-case rejections, matching #302.
Out of Scope Changes check ✅ Passed The extra research mission snapshot pins appear to support the verifier rollout, and no clearly unrelated changes stand out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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-tradeable-top-302

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: 3fd723c61d

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

Comment on lines +467 to +469
(None, Some(levels)) => levels
.iter()
.all(|level| !polymarket_tradeable_price(level.price)),

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 Filter non-executable levels before projecting depth

When a side contains a boundary level plus an executable top (for example, the new 0.02/0.03 ask fixture), this accepts the row but retains the 0.02 level. project_verified_polymarket_evidence copies every retained level into ResearchPmBookSnapshot (polymarket_evidence_projection.rs:155-179), while sweep_buy_to_stake_with_config and the sell sweep accept every price strictly between 0 and 1 (factors_v2.rs:8204-8207, 11126-11128). Consequently the executable-PnL evaluator consumes liquidity that this verifier explicitly classifies as non-executable, overstating fills and corrupting settlement/PnL labels whenever boundary depth is present. Apply the same strict predicate to projected/swept depth, rather than only when selecting the top.

Useful? React with 👍 / 👎.

@proerror77
proerror77 merged commit be68583 into main Jul 23, 2026
30 checks passed
@proerror77
proerror77 deleted the codex/polymarket-tradeable-top-302 branch July 23, 2026 23:26
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.

Fix Polymarket verifier tradeable top/depth contract

1 participant