fix(pm-collector): bound incomplete-market trade-ID retention - #590
Conversation
…ication Refs #587 The production Rust collector writes polymarket_trade_collection_complete proofs for every finalized market, but the parity verifier's KINDS allowlist only knew metadata/trades/settlements, so the first Rust->Rust shadow gate died with 'invalid update kind'. Completion proofs are per-lane polling bookkeeping emitted on independent schedules, not shared market evidence: admit them in the tape parser but exclude them from the comparison window. Legacy->Rust gates never hit this because the legacy Python lane did not emit completion records. Counterexample test: completion rows in both lanes still pass parity.
Refs #589 compact_trade_dedupe only compacts completed-market IDs; incomplete markets retain every trade ID until their completion proof is emitted. At current 5m/15m crypto volume (~550k IDs/hour, 3.99M retained — all on incomplete markets) the 4M fail-closed cap becomes a guaranteed crash loop, which also kills the shadow gate's baseline-identity checks. Evict the oldest incomplete-market IDs once retained IDs exceed 3/4 of the cap; validate_state_bounds stays fail-closed for accumulation the eviction cannot cover. Evictions are observable via the new trade_ids_evicted health field. Counterexample tests: oldest-first eviction spares complete-market IDs and clears emptied conditions; no-op under budget; complete-market overflow still fails closed.
|
Warning Review limit reached
Next review available in: 39 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR adds parity handling for trade-collection completion records and introduces budget-based eviction for incomplete-market trade IDs. Startup and collection paths apply eviction, persist startup changes, report evictions, and validate overflow behavior. ChangesParity completion records
Trade-ID retention eviction
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@rust_hft/tools/collector/src/polymarket_raw.rs`:
- Around line 2049-2058: Update the eviction candidate selection around
state.trade_seen to use a bounded max-heap containing timestamps and references
to condition/trade IDs, retaining only the oldest excess entries without cloning
every candidate. After selection, clone the condition_id and trade_id only for
the chosen victims before applying eviction, preserving the existing incomplete
filtering and age ordering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4db17ed0-7dd0-42e8-b2b3-8832fef43861
📒 Files selected for processing (2)
rust_hft/tools/collector/src/polymarket_parity.rsrust_hft/tools/collector/src/polymarket_raw.rs
💡 Codex Reviewmonday/rust_hft/tools/collector/src/polymarket_raw.rs Lines 2061 to 2063 in cc2a07a When an evicted condition still returns those trades—particularly for markets with fewer than the 20,000 rows fetched in full—this removal forgets IDs that the next poll immediately retrieves again. AGENTS.md reference: AGENTS.md:L115-L116 monday/rust_hft/tools/collector/src/polymarket_parity.rs Lines 337 to 340 in cc2a07a For any completion row, this branch returns before schema validation; AGENTS.md reference: AGENTS.md:L115-L116 monday/rust_hft/tools/collector/src/polymarket_raw.rs Lines 2049 to 2055 in cc2a07a At the production trigger of roughly four million retained IDs, this builds and sorts a vector containing a cloned condition ID and cloned 64-byte trade ID for every incomplete entry before removing only the excess. The vector alone requires hundreds of megabytes for tuples and cloned buffers, while normal cycles already hold both ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…te case Review on #590: the first pass cloned every candidate condition/trade ID (up to ~4M strings during recovery). Select the eviction cutoff from timestamps only (~8B each), then evict strictly-older plus deterministic ties. Also return early when no incomplete IDs exist so the complete-market overflow path cannot index an empty vector.
Change contract
Stop the reference collector's 4M-cap crash loop: bound incomplete-market trade-ID retention by evicting the oldest incomplete IDs before the cap is reached. Refs #589.
compact_trade_dedupeonly compacts completed-market IDs; incomplete markets retain every ID forever. Production state on 2026-08-02: 3,998,592 retained IDs — all on incomplete markets, oldest 7 days — crashing every ~24 min and killing shadow-gate baseline checks. At ~550k IDs/hour, no age-based horizon fits the cap.evict_oldest_incomplete_trade_idskeeps retained IDs ≤ 3/4 of the cap, oldest-first; complete-market IDs are never evicted.validate_state_bounds(which stays fail-closed for overflow eviction cannot cover).trade_ids_evictedhealth field for observability (additive; the gate's health policy is not closed-world).Issue relationship
Refs #589
Out of scope
Dependencies and merge order
None. Unblocks the pending raw-ops cutover (candidate rebuild → gate → cutover).
Focused validation
cargo test -p hft-collector polymarket_raw::— 78 passed, 0 failed.Rollout and rollback
Scope exception
None
Summary by CodeRabbit
New Features
Bug Fixes