Skip to content

fix(polymarket): admit bounded legacy trade rate limits - #503

Merged
proerror77 merged 2 commits into
mainfrom
codex/polymarket-legacy-429-admission
Jul 30, 2026
Merged

fix(polymarket): admit bounded legacy trade rate limits#503
proerror77 merged 2 commits into
mainfrom
codex/polymarket-legacy-429-admission

Conversation

@proerror77

@proerror77 proerror77 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Change contract

Allow only the Gate's legacy-Python startup admission to accept one to three exact trades-endpoint HTTP 429 errors while preserving the original errors in immutable evidence and keeping shared cutover/Rust health policies strict.

Out of scope

Legacy Python retry/backoff or redeployment, Rust collector behavior, CI restructuring, research, snapshot/235, evaluator/MCTS, and production cutover.

Dependency or merge order

None. Merge directly to main; the resulting exact-main artifact feeds the existing Polymarket runtime rollout.

Focused validation

  • RED before implementation: control-plane test failed with gate policy rejected a bounded legacy trades rate limit.
  • GREEN: bash deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • GREEN: bash -n deployment/aliyun/polymarket-raw-ops-shadow-gate.sh deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • GREEN: shellcheck deployment/aliyun/polymarket-raw-ops-shadow-gate.sh deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • GREEN: both jq policies parse successfully.
  • Spec review: APPROVE.
  • Standards review: APPROVE.

Counterexamples cover four rate limits, wrong endpoint, HTTP 500, timeout, mixed lists, strict shared legacy policy, strict Rust policy, and verbatim Gate evidence preservation.

Rollout and rollback impact

After merge, build a new exact-main immutable release, rerun the existing real closed-segment preflight, then run the strict 900-second Gate. Any other legacy error, identity/freshness failure, Rust/data/OSS/parity failure, or Gate failure remains fail-closed and preserves Python. Rollback uses the previous immutable control bundle.

Issue relationship

Closes #502

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 47 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 Plus

Run ID: bfea85ad-f1fe-458f-9ed4-c73f2af4d463

📥 Commits

Reviewing files that changed from the base of the PR and between bc5319a and 46c9c82.

📒 Files selected for processing (3)
  • deployment/aliyun/polymarket-raw-ops-shadow-gate.sh
  • deployment/aliyun/polymarket-shadow-gate-policy.jq
  • deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The policy and tests implement the bounded 429 admission rules for legacy startup health while keeping Rust and strict failure cases unchanged.
Out of Scope Changes check ✅ Passed The diff stays focused on Gate policy and tests; no unrelated collector, CI, or rollout logic changes appear.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and accurately captures the main change: admitting bounded legacy trade rate limits.
Description check ✅ Passed The description covers all required template sections and includes validation, rollout, out-of-scope, and issue linkage.
✨ 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-legacy-429-admission

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.

@proerror77
proerror77 enabled auto-merge (squash) July 30, 2026 14:10

@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: bc5319ae5c

ℹ️ 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 thread deployment/aliyun/polymarket-shadow-gate-policy.jq Outdated
Comment thread deployment/aliyun/polymarket-shadow-gate-policy.jq Outdated
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
deployment/aliyun/polymarket-shadow-gate-policy.jq (1)

41-56: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Rate-limit exemption leaks into the completion snapshot, beyond the stated "startup health" scope.

legacy_health_snapshot is shared by both .baseline_health_snapshot (Line 137) and .baseline_health_completion_snapshot (Line 152). Adding bounded_legacy_trade_rate_limits here therefore also relaxes the completion health check, even though the PR objectives scope this admission to "legacy Python startup health" / the "initial legacy baseline admission" only. As written, a legacy collector that is still hitting the trades rate limit right up to cutover (at the completion snapshot, just before production_eligible/passed) can pass Gate, which undermines exactly the stability guarantee the completion check exists to enforce.

No test exercises baseline_health_completion_snapshot.api_errors with a rate-limit error to catch this (all coverage targets baseline_health_snapshot).

🐛 Proposed fix: parameterize the exemption by call site
-def legacy_health_snapshot:
+def legacy_health_snapshot($allow_bounded_rate_limits):
   (.updated_at | utc_iso8601_unix | type == "number")
   and (.last_success_at | type == "string" and length > 0)
   and (.target_markets | positive_integer)
-  and (.api_errors | bounded_legacy_trade_rate_limits)
+  and (.api_errors
+    | if $allow_bounded_rate_limits then bounded_legacy_trade_rate_limits
+      else . == [] end)
   and .malformed_trade_rows == 0
   and .truncated_trade_markets == []
   and .stale_trade_markets == []
   and .stale_settlement_markets == []
   and (.overdue_unresolved_markets
     | type == "array" and all(.[]; type == "string" and length > 0));

Then update the two call sites:

-    and (.baseline_health_snapshot | legacy_health_snapshot)
+    and (.baseline_health_snapshot | legacy_health_snapshot(true))
-        (.baseline_health_completion_snapshot | legacy_health_snapshot)
+        (.baseline_health_completion_snapshot | legacy_health_snapshot(false))

As per coding guidelines, "Make surgical changes: every changed line must trace to the request" and "retain validation, security, data-loss prevention, and trust-boundary checks" — the completion check is a trust boundary that this shared def unintentionally weakens beyond the requested startup-only scope.

🤖 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/polymarket-shadow-gate-policy.jq` around lines 41 - 56,
Restrict the rate-limit exemption to the startup baseline only: parameterize
legacy_health_snapshot (and its api_errors validation) with an allow-rate-limit
flag, enable it for baseline_health_snapshot, and disable it for
baseline_health_completion_snapshot. Preserve strict completion validation so
any rate-limit error fails the completion health check.

Source: Coding guidelines

🧹 Nitpick comments (1)
deployment/aliyun/polymarket-raw-ops-shadow-gate.sh (1)

478-496: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Bounded rate-limit check duplicated between jq policy and shell script.

The length <= 3 / regex logic in legacy_start_health_policy_clean exactly mirrors bounded_legacy_trade_rate_limits in polymarket-shadow-gate-policy.jq. Two independent copies of a security-relevant boundary (the "3" threshold and exact regex) risk silent drift if one is updated without the other.

Minimal mitigation: cross-reference both definitions with a comment, or better, extract the check into a shared jq snippet sourced by both call sites.

🤖 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/polymarket-raw-ops-shadow-gate.sh` around lines 478 - 496,
Cross-reference the duplicated bounded rate-limit validation in
legacy_start_health_policy_clean and bounded_legacy_trade_rate_limits so their
shared threshold and exact error-pattern boundary are clearly linked. Prefer
reusing a shared jq snippet from both call sites; otherwise add explicit
comments identifying the corresponding definition and requiring both
implementations to remain synchronized.
🤖 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 2570-2603: Extend the legacy rate-limit tests after the existing
baseline_health_snapshot cases by creating a fixture that mutates
.baseline_health_completion_snapshot.api_errors with the bounded legacy trades
rate-limit error, then run POLICY against it and assert rejection with a
failing-test message. Keep the existing baseline_health_snapshot acceptance and
excess/mixed rejection cases unchanged.

---

Outside diff comments:
In `@deployment/aliyun/polymarket-shadow-gate-policy.jq`:
- Around line 41-56: Restrict the rate-limit exemption to the startup baseline
only: parameterize legacy_health_snapshot (and its api_errors validation) with
an allow-rate-limit flag, enable it for baseline_health_snapshot, and disable it
for baseline_health_completion_snapshot. Preserve strict completion validation
so any rate-limit error fails the completion health check.

---

Nitpick comments:
In `@deployment/aliyun/polymarket-raw-ops-shadow-gate.sh`:
- Around line 478-496: Cross-reference the duplicated bounded rate-limit
validation in legacy_start_health_policy_clean and
bounded_legacy_trade_rate_limits so their shared threshold and exact
error-pattern boundary are clearly linked. Prefer reusing a shared jq snippet
from both call sites; otherwise add explicit comments identifying the
corresponding definition and requiring both implementations to remain
synchronized.
🪄 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: 3d795f83-07b4-4f0b-827b-efb2c90b97e8

📥 Commits

Reviewing files that changed from the base of the PR and between 6d869ef and bc5319a.

📒 Files selected for processing (3)
  • deployment/aliyun/polymarket-raw-ops-shadow-gate.sh
  • deployment/aliyun/polymarket-shadow-gate-policy.jq
  • deployment/aliyun/test-polymarket-raw-ops-control-plane.sh

Comment thread deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
@proerror77
proerror77 merged commit 61c959c into main Jul 30, 2026
45 checks passed
@proerror77
proerror77 deleted the codex/polymarket-legacy-429-admission branch July 30, 2026 14:27
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): admit bounded legacy trade API rate limits

1 participant