fix(polymarket): sanitize legacy state at Rust handoff - #528
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 43 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 (3)
📝 WalkthroughWalkthroughThe cutover control plane now validates legacy Python collector state, removes transient failure fields during Python-to-Rust promotion, atomically installs the transformed state, and records hashes, metadata, and counts in cutover evidence. Contract tests cover valid, invalid, and Rust-to-Rust paths. ChangesLegacy state handoff
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant ShadowGate
participant Cutover
participant LegacyState
participant RustCollector
participant CutoverEvidence
ShadowGate->>LegacyState: validate ownership, mode, type, and JSON schema
ShadowGate->>Cutover: allow validated promotion
Cutover->>LegacyState: snapshot and remove transient failure fields
LegacyState-->>Cutover: return hashes, counts, and metadata
Cutover->>RustCollector: restart after handoff
Cutover->>CutoverEvidence: record handoff result
🚥 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
🧹 Nitpick comments (1)
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh (1)
1664-1697: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd rejection cases for a wrong group, a non-integer
trade_seenvalue, and an unknown baseline mode.The rejection tests cover malformed JSON, a non-object market, mode 660, owner
root, and a symlink. Three branches of the shared admission contract stay untested:
group == hftcollectoron line 204 ofdeployment/aliyun/polymarket-raw-ops-cutover.sh.state_groupnever changes fromhftcollector.type == "number" and floor == .fortrade_seenvalues.- The
legacy_python || rust_releaseallow-list, which must reject any other mode.Each case costs one assertion and protects the fail-closed admission contract from a silent regression.
♻️ Proposed additional rejection cases
state_owner=hftcollector + state_group=root + if verify_legacy_state_handoff_preflight legacy_python "$state"; then + printf 'legacy-state handoff admitted a foreign-group state file\n' >&2 + exit 1 + fi + state_group=hftcollector + printf '{"markets":{},"trade_seen":{"condition-a":{"id-a":1.5}}}\n' >"$state" + if verify_legacy_state_handoff_preflight legacy_python "$state"; then + printf 'legacy-state handoff admitted a non-integer trade sequence\n' >&2 + exit 1 + fi + printf '{"markets":{},"trade_seen":{}}\n' >"$state" + if verify_legacy_state_handoff_preflight unknown_mode "$state"; then + printf 'legacy-state handoff admitted an unknown baseline mode\n' >&2 + exit 1 + fi rm "$state" ln -s state-target.json "$state"🤖 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 `@deployment/aliyun/test-polymarket-raw-ops-control-plane.sh` around lines 1664 - 1697, Add rejection assertions in the legacy-state preflight test flow around verify_legacy_state_handoff_preflight: temporarily set state_group to a non-hftcollector value and expect rejection, write state JSON with a non-integer trade_seen value and expect rejection, and invoke the preflight with an unknown baseline mode and expect rejection. Restore shared test state as needed so the existing rust_release allow-list check remains valid.
🤖 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 `@deployment/aliyun/test-polymarket-raw-ops-control-plane.sh`:
- Around line 1709-1722: Guard cutover_stop_collector_line with the same
positive-integer regex used for the handoff line variables before the numeric
ordering comparisons in the cutover validation block. Add a targeted
counterexample test that removes or fails to match the collector stop command
and verifies the check exits nonzero, while preserving the existing fail-closed
ordering behavior.
---
Nitpick comments:
In `@deployment/aliyun/test-polymarket-raw-ops-control-plane.sh`:
- Around line 1664-1697: Add rejection assertions in the legacy-state preflight
test flow around verify_legacy_state_handoff_preflight: temporarily set
state_group to a non-hftcollector value and expect rejection, write state JSON
with a non-integer trade_seen value and expect rejection, and invoke the
preflight with an unknown baseline mode and expect rejection. Restore shared
test state as needed so the existing rust_release allow-list check remains
valid.
🪄 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: 205fd178-f014-4cda-9c4b-8105b88057ca
📒 Files selected for processing (3)
deployment/aliyun/polymarket-raw-ops-cutover.shdeployment/aliyun/polymarket-raw-ops-shadow-gate.shdeployment/aliyun/test-polymarket-raw-ops-control-plane.sh
Change contract
At a stopped legacy Python-to-Rust Polymarket collector transition, atomically remove only the four legacy transient failure-clock fields from
collector-state.json, while preserving all durable market, completion, settlement, and trade-deduplication state and binding the before/after state to cutover evidence.This is a small, already-diagnosed runtime defect, so a separate PRD is unnecessary; the linked runtime issue is the authoritative behavior contract.
Out of scope
Dependency or merge order
None. Base is exact
9384b0e71dc0435c98c4d01cb215b279baa11f1e.Focused validation
deployment/aliyun/test-polymarket-raw-ops-control-plane.shbash -non the Gate, cutover, and focused test scriptsshellcheckon the same three filesgit diff --checkRollout / rollback impact
Rollout remains fail-closed. Gate and cutover both require the direct state file to be owned by
hftcollector:hftcollector, mode0640, under the trusted0750spool. The cutover applies the transform only after the legacy process is stopped and before Rust starts. Automatic rollback retains the transformed durable state and the exact pre-handoff snapshot remains in immutable cutover evidence; it never restores a stale whole-state snapshot over newer durable writes.Issue relationship
Refs #527