Skip to content

Record complete Polymarket trade sets - #153

Merged
proerror77 merged 4 commits into
mainfrom
codex/polymarket-trade-completion-marker
Jul 19, 2026
Merged

proerror77 merged 4 commits into
mainfrom
codex/polymarket-trade-completion-marker

Conversation

@proerror77

Copy link
Copy Markdown
Owner

Change contract: The Polymarket reference collector emits an event-local trade completion proof only after authoritative settlement, exhausted pagination, stable post-settlement polls, and retention of the exact canonical v2 trade ID set until proof emission.

Out of scope: Downstream multi-hour research import, evidence sealing, strategy evaluation, and live execution.

Dependency or merge order: None. Merge this PR before the stacked reference-segment-set and evidence-binding PRs.

Focused validation: cargo test --manifest-path rust_hft/Cargo.toml -p hft-collector --lib (167 passed, 2 ignored); cargo clippy --manifest-path rust_hft/Cargo.toml -p hft-collector --all-targets --features collector-binance -- -D warnings; cargo fmt --manifest-path rust_hft/Cargo.toml -- --check; git diff --check. Independent correctness and standards reviews at fixed head 1870d88 reported no findings.

Rollout/rollback impact: Adds a raw collector marker and state-version migration; legacy completed markets reopen collection fail-closed. Roll back by reverting this PR; downstream consumers must not merge before this base. Live execution remains disabled.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 12 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: 64a4badf-61ba-4234-a7c5-dccec4844800

📥 Commits

Reviewing files that changed from the base of the PR and between 1ddea8d and 1870d88.

📒 Files selected for processing (2)
  • rust_hft/tools/collector/src/polymarket_raw.rs
  • rust_hft/tools/collector/src/polymarket_upload.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-trade-completion-marker

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: 1870d8880e

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

self.config.trade_finalization_stable_polls,
)
{
updates.push(trade_completion_update(

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 Emit metadata alongside recovered completion proofs

When a previously tracked market is absent from discovery and its authoritative detail fetch is deferred until after the hour-seeding cycle, market_metadata_update at lines 2294-2303 returns None because the unchanged metadata hash was persisted from an earlier hour. This path can still append the completion here after its stable polls, but the resulting hourly tape contains no metadata identity for that market; the uploader then unconditionally rejects it at polymarket_upload.rs:1176-1185 as contradicting market metadata, permanently blocking archival of that closed segment. Ensure the market has metadata in the current tape before emitting its completion proof.

Useful? React with 👍 / 👎.

self.config.trade_finalization_stable_polls,
)
{
updates.push(trade_completion_update(

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 Reset stability when intervening polls see new trades

If Gamma temporarily returns no valid settlement during an otherwise successful trade poll that discovers a new trade, the settlement_available guard prevents advance_trade_finalization from running, so its new_trade_count > 0 reset never happens and the prior stable-poll count survives. On the next poll where settlement is valid and no trade is new, this block can emit a completion proof after only one stable poll following the newly discovered trade instead of the configured number, allowing late trades to be missed. Reset the counter for every destabilizing trade result even when settlement is unavailable.

Useful? React with 👍 / 👎.

Comment on lines +1806 to +1807
if state.markets.len() > max_markets
|| state.trade_seen.len() > max_markets

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 Bound state against both discovery lanes

max_markets is explicitly a per-lane limit (DEFAULT_MAX_MARKETS_PER_LANE), and GammaDiscovery::append_page maintains independent open and closed counters, so a valid discovery can retain up to twice this many distinct markets and condition maps. Comparing the combined state.markets and state.trade_seen sizes to only one lane's limit causes the collector to reject otherwise valid cycles or existing state whenever the two lanes together exceed max_markets, even though neither lane exceeded its configured cap. Use a checked combined-lane bound here.

Useful? React with 👍 / 👎.

@proerror77
proerror77 merged commit b0647fd into main Jul 19, 2026
20 checks passed
@proerror77
proerror77 deleted the codex/polymarket-trade-completion-marker 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.

1 participant