Skip to content

Fail closed on real Polymarket segment incompatibility - #422

Merged
proerror77 merged 3 commits into
mainfrom
codex/polymarket-real-segment-preflight-420
Jul 28, 2026
Merged

Fail closed on real Polymarket segment incompatibility#422
proerror77 merged 3 commits into
mainfrom
codex/polymarket-real-segment-preflight-420

Conversation

@proerror77

@proerror77 proerror77 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Closes #420

Change contract

Before any 4201-second shadow observation, run the exact candidate Rust uploader against one exact real production closed Polymarket market segment, require at least one quote, verify source and isolated candidate OSS triplets, and bind the readback/content identities into immutable Gate policy evidence.

Out of scope

Dependency or merge order

None. #421 follows after this PR merges; it is a separate rollout unit.

Focused validation

  • bash deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • bash -n deployment/aliyun/polymarket-raw-ops-shadow-gate.sh deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • shellcheck deployment/aliyun/polymarket-raw-ops-shadow-gate.sh deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • jq -n -f deployment/aliyun/polymarket-shadow-gate-policy.jq
  • Live read-only reproduction: the current candidate rejects an exact real production triplet at line 204 with quote requires request_status=success.
  • Counterexamples cover no-quote input, unrelated candidate output, mismatched content-addressed path, superseded source, bad success marker, non-terminal upload summary, missing/late/synthetic evidence.
  • Two-axis code review: approved with no remaining P0-P3 findings.

Rollout / rollback impact

Fail-closed Gate-only change. It adds a short pre-observation real-segment preflight and isolated digest/run-addressed OSS output. Failure occurs before shadow startup and leaves production Python services unchanged. Rollback is reverting this PR; no production cutover is included.

PRD is unnecessary because this is a small, already-specified deployment-gate defect with one behavior contract and one rollback unit.

Summary by CodeRabbit

  • New Features

    • Added a real-market preflight check before shadow collection starts.
    • Validates downloaded market data, manifests, success markers, file names, sizes, and checksums.
    • Adds detailed preflight evidence and success status to deployment results.
  • Bug Fixes

    • Prevents deployments from proceeding with invalid, outdated, incompatible, empty, or tampered market segments.
    • Strengthens validation of uploaded data and processing summaries.
  • Tests

    • Added coverage for valid and invalid real-market segment scenarios, including checksum mismatches and incomplete uploads.

@coderabbitai

coderabbitai Bot commented Jul 28, 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: 40 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: 5389e104-9225-4d99-96ca-294e99b43106

📥 Commits

Reviewing files that changed from the base of the PR and between 6136b55 and aec3125.

📒 Files selected for processing (2)
  • deployment/aliyun/polymarket-raw-ops-shadow-gate.sh
  • deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
📝 Walkthrough

Walkthrough

The shadow gate now preflights a closed real-market OSS segment, validates the candidate upload and readback, records structured evidence, enforces it through jq policy checks, and tests incompatible, tampered, and correctly ordered scenarios before shadow startup.

Changes

Real-market preflight

Layer / File(s) Summary
Gate preflight execution
deployment/aliyun/polymarket-raw-ops-shadow-gate.sh
Adds source and uploaded OSS triplet verification, real-segment candidate execution, isolated preflight evidence, cleanup, metrics, and a real_market_segment_preflight check.
Evidence policy validation
deployment/aliyun/polymarket-shadow-gate-policy.jq
Validates triplet paths, hashes, manifests, dataset identity, timing, upload summaries, and required preflight evidence.
Preflight and parity coverage
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
Adds compressed-triplet fixtures, real-segment acceptance and rejection cases, policy tampering checks, and ordering assertions before shadow startup.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ShadowGate
  participant OSS
  participant CandidateUploader
  participant GatePolicy
  ShadowGate->>OSS: download and verify closed source triplet
  ShadowGate->>CandidateUploader: process real segment and upload preflight output
  CandidateUploader->>OSS: publish isolated output triplet
  ShadowGate->>OSS: read back and verify output triplet
  ShadowGate->>GatePolicy: validate preflight evidence and metrics
Loading

Possibly related PRs

  • proerror77/monday#34: Extends the same Polymarket shadow gate and control-plane files with real-market preflight validation and evidence.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: failing closed on real Polymarket segment incompatibility.
Description check ✅ Passed The description covers the required contract, out-of-scope work, dependencies, validation, and rollout details.
Linked Issues check ✅ Passed The changes implement the real closed-segment preflight, evidence capture, incompatibility checks, and ordering tests required by #420.
Out of Scope Changes check ✅ Passed The diff stays focused on the real-segment preflight and policy/test updates with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-real-segment-preflight-420

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.

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

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

871-872: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

env is invoked but not in the required-command bootstrap list.

Line 636 runs runuser -u hftcollector -- env HOME=.... env is effectively always present, so this is a hygiene nit only.

🤖 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 871 - 872,
Add env to the required-command bootstrap list alongside the other utilities in
the command loop, covering its use by the runuser invocation at line 636.

598-607: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Stability retry loop has no backoff.

The three iterations re-stat immediately, so a writer that is mid-flush is very likely to lose all three attempts within the same millisecond window. A short sleep between attempts would make the stability check meaningful.

♻️ Suggested change
-  for _ in 1 2 3; do
+  for attempt in 1 2 3; do
+    ((attempt == 1)) || sleep 1
     before=$(stat -c '%d:%i:%s:%Y:%Z' "$status_file") || return 1
🤖 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 598 - 607,
Add a short sleep between failed stability-check attempts in the loop around
before, status_json, and after, while preserving the immediate break when before
matches after and the existing failure after all three attempts.
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh (2)

1716-1773: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider also tampering status and candidate_sha256.

The suite covers timing, dataset, digest, success-marker and upload-summary tampering, but not .real_market_preflight.status = "failed" or a candidate_sha256 that diverges from the top-level one — both are load-bearing policy clauses (Lines 61-62 of the policy).

🤖 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 1716
- 1773, Extend the policy-tampering checks after the existing real-market
preflight cases to modify `.real_market_preflight.status` to `"failed"` and
assert the policy rejects it, then modify
`.real_market_preflight.candidate_sha256` to differ from the top-level candidate
digest and assert rejection. Use distinct temporary JSON files and failure
messages consistent with the surrounding checks.

2524-2530: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Line-number ordering check breaks if the preflight is ever called twice.

grep -n ... | cut -d: -f1 yields a multi-line value on a second call site, and (( )) then errors out with a confusing message rather than a clear assertion failure. Piping through head -n 1 (or asserting exactly one match) would keep the failure legible.

🤖 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 2524
- 2530, Update the line-number lookup for real_market_segment_preflight in the
ordering assertion so multiple call sites cannot produce a multiline value;
select exactly the first match or explicitly assert that there is one match
before arithmetic comparison. Keep the existing preflight_line ordering
validation and failure message intact.
deployment/aliyun/polymarket-shadow-gate-policy.jq (1)

6-20: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Policy does not tie .file to the tail of .uri.

oss_triplet validates the URI shape and the file-name shape independently, so evidence declaring file: "market-updates.A...zst" with a URI ending in market-updates.B...zst passes. The gate always emits them consistently today, but this policy is the immutable evidence check, so it's worth pinning.

♻️ Suggested hardening
   and (.file | type == "string"
     and test("^market-updates\\.[A-Za-z0-9._-]+\\.ndjson\\.zst$"))
+  and ($triplet.uri | endswith("/" + $triplet.file))
🤖 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 6 - 20,
Update the oss_triplet policy to require that the validated .file value matches
the filename at the end of .uri, while preserving the existing URI and file
format checks. Extract or otherwise compare the URI’s trailing filename with
.file so mismatched declarations are rejected.
🤖 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.

Nitpick comments:
In `@deployment/aliyun/polymarket-raw-ops-shadow-gate.sh`:
- Around line 871-872: Add env to the required-command bootstrap list alongside
the other utilities in the command loop, covering its use by the runuser
invocation at line 636.
- Around line 598-607: Add a short sleep between failed stability-check attempts
in the loop around before, status_json, and after, while preserving the
immediate break when before matches after and the existing failure after all
three attempts.

In `@deployment/aliyun/polymarket-shadow-gate-policy.jq`:
- Around line 6-20: Update the oss_triplet policy to require that the validated
.file value matches the filename at the end of .uri, while preserving the
existing URI and file format checks. Extract or otherwise compare the URI’s
trailing filename with .file so mismatched declarations are rejected.

In `@deployment/aliyun/test-polymarket-raw-ops-control-plane.sh`:
- Around line 1716-1773: Extend the policy-tampering checks after the existing
real-market preflight cases to modify `.real_market_preflight.status` to
`"failed"` and assert the policy rejects it, then modify
`.real_market_preflight.candidate_sha256` to differ from the top-level candidate
digest and assert rejection. Use distinct temporary JSON files and failure
messages consistent with the surrounding checks.
- Around line 2524-2530: Update the line-number lookup for
real_market_segment_preflight in the ordering assertion so multiple call sites
cannot produce a multiline value; select exactly the first match or explicitly
assert that there is one match before arithmetic comparison. Keep the existing
preflight_line ordering validation and failure message intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a94db83-3e40-404e-8022-283d1f5b87bf

📥 Commits

Reviewing files that changed from the base of the PR and between 1c3535d and 6136b55.

📒 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

@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: 6136b55780

ℹ️ 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-raw-ops-shadow-gate.sh Outdated
Comment thread deployment/aliyun/polymarket-raw-ops-shadow-gate.sh Outdated
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.

Preflight Rust uploader with a real closed Polymarket segment

1 participant