Skip to content

fix(collector): retry Gamma closed discovery after 500 - #626

Merged
proerror77 merged 1 commit into
mainfrom
codex/gamma-closed-lane-500
Aug 2, 2026
Merged

fix(collector): retry Gamma closed discovery after 500#626
proerror77 merged 1 commit into
mainfrom
codex/gamma-closed-lane-500

Conversation

@proerror77

@proerror77 proerror77 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Change contract

Retry a Gamma discovery request without tag_id=21 only when the closed lane exhausts its existing bounded HTTP retries with HTTP 500. Keep the same date window, cursor, target-market admission checks, and fail-closed behavior for every other error.

Acceptance evidence

  • A local Gamma server proves three tagged closed-lane 500 responses are followed by one untagged request with the original date bounds; only the existing supported target market is admitted.
  • Counterexamples prove open-lane 500, closed-lane non-500, and failed untagged fallback remain errors without relaxing the normal tagged query.

Out of scope

  • Removing the tag from normal discovery, changing other HTTP retry behavior, or accepting non-target markets.
  • Async uploader rollout, collector cutover, OSS cleanup, and research execution.

Dependency / merge order

No stacked dependency. Base is main at 612d0f9a57130d9f708f055d625b83b6839a1816, which already contains merged PR #620.

Focused validation

  • cargo test -p hft-collector --lib --locked — 280 passed, 2 ignored
  • cargo clippy -p hft-collector --all-targets --features collector-binance --no-deps --locked -- -D warnings
  • deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • git diff --check

Rollout / rollback impact

No automatic deployment. After merge, bind the new immutable candidate in the runtime control contract, establish a fresh reference-health baseline, and run the existing Gate before any cutover. Roll back by retaining the current runtime or reverting this single commit; no tape or OSS data is deleted by this change.

Issue relationship

Closes #625

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Closed-lane Gamma discovery now retries tagged HTTP 500 responses and performs one untagged fallback request. Integration tests verify request bounds, parameter removal, target filtering, and fail-closed behavior.

Changes

Closed-lane Gamma discovery

Layer / File(s) Summary
Closed-lane fallback behavior
rust_hft/tools/collector/src/polymarket_raw.rs
After bounded tagged-request retries return HTTP 500, closed-lane discovery sends one request without tag_id. Other errors remain failures.
Fallback request validation
rust_hft/tools/collector/src/polymarket_raw.rs
Integration tests verify retry counts, request parameters, target filtering, open-lane failures, non-500 errors, and failed fallbacks.

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

Possibly related issues

  • proerror77/monday issue 624 — Requests the same closed-lane Gamma HTTP 500 fallback behavior and associated validation.

Possibly related PRs

  • proerror77/monday#86 — Also modifies Polymarket Gamma discovery request handling and tests in polymarket_raw.rs.

Sequence Diagram(s)

sequenceDiagram
  participant Collector
  participant GammaServer
  participant TargetFilter
  Collector->>GammaServer: Send tagged closed-lane request
  GammaServer-->>Collector: Return HTTP 500
  Collector->>GammaServer: Retry tagged request
  GammaServer-->>Collector: Return HTTP 500
  Collector->>GammaServer: Send untagged fallback request
  GammaServer-->>Collector: Return market data
  Collector->>TargetFilter: Apply supported-market checks
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #625 by adding bounded closed-lane 500 fallback while preserving query, filtering, and fail-closed behavior.
Out of Scope Changes check ✅ Passed The changes are limited to the Gamma closed-lane retry and related tests, with no unrelated scope identified.
Title check ✅ Passed The title clearly and concisely describes the Gamma closed-discovery retry behavior.
Description check ✅ Passed The description covers the change, issue, scope, dependencies, validation, and rollout details; only the explicit Scope exception section is missing.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/gamma-closed-lane-500

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 merged commit 5f55f3f into main Aug 2, 2026
45 of 49 checks passed
@proerror77
proerror77 deleted the codex/gamma-closed-lane-500 branch August 2, 2026 18:12

@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: 2eb81a7d53

ℹ️ 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 +2379 to +2382
&& error
.downcast_ref::<reqwest::Error>()
.and_then(reqwest::Error::status)
== Some(reqwest::StatusCode::INTERNAL_SERVER_ERROR) =>

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 Gate fallback on exhausted retry attempts

When the first closed-lane response is HTTP 500 with a malformed or over-budget textual Retry-After, get_json returns the contextualized reqwest::Error immediately from the retry-delay check rather than exhausting HTTP_GET_ATTEMPTS; this status-only guard still downcasts that source error and launches the untagged query. That bypasses the existing bounded-retry/fail-closed behavior despite the change contract limiting fallback to exhausted retries, so distinguish terminal retry exhaustion from an unhonorable Retry-After and cover the latter as a counterexample.

AGENTS.md reference: AGENTS.md:L113-L116

Useful? React with 👍 / 👎.

Comment on lines +2384 to +2387
let fallback_params = params
.iter()
.filter(|(key, _)| key != "tag_id")
.cloned()

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 Retain crypto-only admission during the untagged fallback

When the closed tagged call exhausts with HTTP 500, this removes the only category-level filter before querying Gamma, while the remaining target_market check is not crypto-only: infer_symbol performs unrestricted substring matching (for example, RESOLVE contains the SOL alias) and accepts any binary market lasting exactly 5 or 15 minutes. Consequently, an unrelated untagged short-duration market can be recorded and polled as SOLUSDT whenever the fallback runs, contaminating the reference tape; retain an equivalent category or canonical market-pattern check before admitting the broader results.

AGENTS.md reference: AGENTS.md:L70-L74

Useful? React with 👍 / 👎.

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): retry bounded closed-lane Gamma discovery after 500

1 participant