Skip to content

deploy: recover Polymarket from an unregistered degraded Rust baseline - #629

Merged
proerror77 merged 3 commits into
mainfrom
codex/polymarket-bootstrap-recovery
Aug 3, 2026
Merged

deploy: recover Polymarket from an unregistered degraded Rust baseline#629
proerror77 merged 3 commits into
mainfrom
codex/polymarket-bootstrap-recovery

Conversation

@proerror77

@proerror77 proerror77 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Change contract

Permit exactly one bounded recovery path: a verified Rust candidate may replace an unhealthy, unregistered direct Rust binary. Normal Rust-to-Rust releases still require the existing immutable, healthy baseline.

Acceptance evidence

  • The Gate admits only rust_bootstrap with degraded baseline evidence, stable runtime identity, candidate health, full Gate evidence, and independent OSS data/manifest/_SUCCESS readback.
  • Failed candidate recovery restores the exact direct binary plus saved service/control state.
  • Bootstrap snapshots work without a global control directory, bind the copied binary to the recorded digest, and reject direct-binary mode drift before rollback evidence mutation.
  • Metadata-only degraded-baseline evidence remains bounded to bootstrap Rust-self parity.

Out of scope

Normal Rust health-policy redesign, generic Gate bypasses, manual active-binary replacement, collector/uploader restart, OSS cleanup, and research/snapshot work.

Dependency / merge order

Base: main. Depends on already-merged #620 and #626.

Issue relationship

Refs #627

Focused validation

  • bash deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • bash -n and shellcheck on the changed shell scripts
  • Rust Fast Gates Python-reference allowlist reproduction
  • cargo test -p hft-collector --lib systemd_reference_resource_envelope_is_pinned --locked
  • git diff --check origin/main...HEAD

Rollout / rollback impact

No runtime change in this PR. After merge, a separate runtime operation must publish a candidate and run stage → Gate → cutover; failed cutover restores the recorded binary and service state. No collector or uploader restart occurs from this PR itself.

Summary by CodeRabbit

  • New Features

    • Added support for directly installed Rust bootstrap binaries alongside existing baseline modes.
    • Added checksum, executable-state, runtime identity, and rollback verification for bootstrap binaries.
    • Added degraded-baseline handling and evidence reporting for bootstrap deployments.
  • Bug Fixes

    • Improved cutover, rollback, snapshot, and policy validation to detect binary drift and invalid metadata.
  • Tests

    • Expanded control-plane coverage for bootstrap identity, health admission, rollback integrity, and policy validation.
    • Updated CI validation for supported legacy command references.

@coderabbitai

coderabbitai Bot commented Aug 2, 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: 38 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: ecc374dc-8f1c-48ba-92c6-dc3470dddc76

📥 Commits

Reviewing files that changed from the base of the PR and between 6392007 and 5e3ccb2.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • deployment/aliyun/polymarket-raw-ops-cutover.sh
  • deployment/aliyun/polymarket-raw-ops-shadow-gate.sh
  • deployment/aliyun/polymarket-shadow-gate-policy.jq
  • deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
📝 Walkthrough

Walkthrough

The control plane adds rust_bootstrap support for direct Rust binaries. It validates executable identity and checksums, records degraded gate evidence, handles cutover and uploader branches, and restores bootstrap binaries during rollback with dedicated tests.

Changes

Rust bootstrap baseline support

Layer / File(s) Summary
Baseline admission and gate evidence
deployment/aliyun/polymarket-raw-ops-shadow-gate.sh, deployment/aliyun/polymarket-shadow-gate-policy.jq
The shadow gate classifies direct Rust binaries, validates their path, executable state, digest, and runtime identity, and records baseline_degraded evidence. The policy validates degraded bootstrap evidence and comparison modes.
Cutover, runtime verification, and rollback
deployment/aliyun/polymarket-raw-ops-cutover.sh
Cutover verifies bootstrap runtime identity and skips release uploader draining for degraded baselines. Rollback snapshots, restores, and verifies direct binaries using saved paths, checksums, and executable modes.
Control-plane contract coverage
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh, .github/workflows/ci.yml
Tests cover bootstrap identity, degraded admission, policy rejection cases, rollback lineage, source-contract assertions, and the CI runtime-reference allowlist.

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

Possibly related issues

Possibly related PRs

  • proerror77/monday#29 — Introduces the Rust cutover and shadow-gate control-plane paths extended here.
  • proerror77/monday#497 — Establishes Rust-only parity behavior extended here for bootstrap baselines.
  • proerror77/monday#520 — Modifies restore_legacy and related rollback verification paths extended here.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% 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
Title check ✅ Passed The title clearly states the bounded recovery of Polymarket from an unregistered degraded Rust baseline.
Description check ✅ Passed The description covers the change, issue, scope, dependencies, validation, and rollback; the omitted scope-exception section is not required for this five-file change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 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-bootstrap-recovery

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 (6)
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh (3)

4941-4944: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Pin the occurrence count alongside tail -1.

The bootstrap branch at Lines 1162-1166 of deployment/aliyun/polymarket-raw-ops-cutover.sh added a second active_target release-root guard and a second rm -f "$ACTIVE_BINARY". tail -1 now selects the legacy_python block at Lines 1189-1194, which is the intended site. If a future branch is appended after that block, tail -1 moves to the new site and the ordering assertion still passes against the wrong code. Assert the expected count as well, as Line 4579 does for the invocation-ID check.

♻️ Sketch
+[[ $(grep -c 'active_target == "\$RELEASE_ROOT"/\*/polymarket-raw-ops' "$CUTOVER") -eq 2 ]]
 active_target_guard_line=$(grep -n \
   'active_target == "\$RELEASE_ROOT"/\*/polymarket-raw-ops' "$CUTOVER" | tail -1 | cut -d: -f1)
+[[ $(grep -c '^    rm -f "\$ACTIVE_BINARY"$' "$CUTOVER") -eq 2 ]]
 active_rm_line=$(grep -n '^    rm -f "\$ACTIVE_BINARY"$' "$CUTOVER" | tail -1 | cut -d: -f1)
🤖 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 4941
- 4944, Update the occurrence lookups for active_target_guard_line and
active_rm_line to assert the expected match count before selecting the final
occurrence, following the existing invocation-ID check pattern at Line 4579.
Preserve selecting the intended legacy_python block while making the ordering
assertion fail if additional matching branches are introduced later.

1387-1400: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add drift cases for the bootstrap-specific guards.

The drift loop covers active, proc, digest, and runtime. The bootstrap branch in deployment/aliyun/polymarket-raw-ops-shadow-gate.sh Lines 452-457 adds three guards that no case exercises:

  • baseline_release_path != RUST_ACTIVE_BINARY
  • RUST_ACTIVE_BINARY is a symlink
  • baseline_release_path is not executable

These guards are what separate a bootstrap baseline from a release baseline. Add cases for them.

💚 Proposed additional cases
-  for drift in active proc digest runtime; do
+  for drift in active proc digest runtime path symlink nonexec; do
     mock_active=$RUST_ACTIVE_BINARY mock_proc=$RUST_ACTIVE_BINARY
     mock_digest=true mock_runtime=true
+    baseline_release_path=$RUST_ACTIVE_BINARY
+    rm -f "$tmp_dir/bootstrap-link"; chmod +x "$RUST_ACTIVE_BINARY"
     case "$drift" in
       active) mock_active=/tmp/wrong ;;
       proc) mock_proc=/tmp/wrong ;;
       digest) mock_digest=false ;;
       runtime) mock_runtime=false ;;
+      path) baseline_release_path=/tmp/wrong ;;
+      symlink)
+        ln -s "$RUST_ACTIVE_BINARY" "$tmp_dir/bootstrap-link"
+        RUST_ACTIVE_BINARY=$tmp_dir/bootstrap-link
+        baseline_release_path=$RUST_ACTIVE_BINARY ;;
+      nonexec) chmod -x "$RUST_ACTIVE_BINARY" ;;
     esac
🤖 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 1387
- 1400, Extend the drift loop in the test around verify_baseline_identity with
cases that independently violate the bootstrap-specific guards: set
baseline_release_path different from RUST_ACTIVE_BINARY, make RUST_ACTIVE_BINARY
a symlink, and make baseline_release_path non-executable. Ensure each case
causes verify_baseline_identity to reject the baseline while preserving the
existing active, proc, digest, and runtime cases.

2331-2339: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

The non-executable case tests the recorded mode, not the file permission.

make_bootstrap_lineage_evidence always runs chmod +x on the snapshot binary at Line 2270. Passing 0644 therefore only changes .active_direct.mode in state.json. The rejection comes from the mode check at Line 1432 of deployment/aliyun/polymarket-raw-ops-cutover.sh, not from the -x check at Line 1437. The failure message at Line 2338 states "non-executable bootstrap rollback image", which describes the untested guard.

Add a separate case that clears the executable bit on $evidence/rollback/bin/polymarket-raw-ops while keeping mode at 0755. Then rename the current case to reflect that it covers mode metadata.

🤖 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 2331
- 2339, The non-executable bootstrap test currently validates only recorded mode
metadata because make_bootstrap_lineage_evidence restores executable
permissions. Rename the existing bootstrap-nonexec case and its failure message
to identify the mode-metadata rejection, then add a separate case that keeps
mode 0755 while removing the executable bit from
evidence/rollback/bin/polymarket-raw-ops and verifies manual rollback rejects
it.

Source: Linters/SAST tools

deployment/aliyun/polymarket-raw-ops-cutover.sh (2)

1240-1286: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting the repeated rollback runtime check.

The same three-way mode dispatch appears at Lines 1240-1251, Lines 1265-1274, and Lines 1277-1286. Only the failure message differs. A single helper that takes the message reduces the risk that a future mode is added to one copy and missed in the others.

♻️ Sketch
verify_rollback_runtime() {
  local failure=$1
  if [[ $rollback_mode == legacy_python ]]; then
    verify_legacy_runtime "$rollback_pid" 0 "$rollback_invocation_id" || die "$failure"
  elif [[ $rollback_mode == rust_release ]]; then
    verify_rust_runtime "$active_target" "$started_epoch" "$rollback_pid" \
      "$rollback_invocation_id" 0 "$rollback_health_policy" || die "$failure"
  else
    verify_bootstrap_rust_runtime "$bootstrap_path" "$bootstrap_sha" \
      "$rollback_pid" "$rollback_invocation_id" 0 || die "$failure"
  fi
}

Note that the contract test at Line 4704 of deployment/aliyun/test-polymarket-raw-ops-control-plane.sh greps for these literal lines, so the test would need the same update.

🤖 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-cutover.sh` around lines 1240 - 1286,
Extract the repeated three-way rollback runtime dispatch into a single
verify_rollback_runtime helper that accepts the failure message and performs the
existing legacy_python, rust_release, and bootstrap checks before calling die.
Replace all three inline dispatch blocks with helper calls using their current
messages, and update the contract test expectations that grep for the removed
literal lines.

1223-1239: 🩺 Stability & Availability | 🔵 Trivial

Bootstrap rollback clears health but never requires it to return.

Line 1099 clears the health file for every mode except rust_release, so a rust_bootstrap rollback also clears it. The bootstrap branch at Lines 1229-1232 breaks on runtime identity alone, and Line 1237 exempts bootstrap from the health-advance assertion. A bootstrap rollback can therefore report success while the restored collector writes no health file. The degraded baseline contract makes this intentional. Add a post-rollback alert on health-file staleness for the bootstrap path so the operator detects a silent collector.

🤖 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-cutover.sh` around lines 1223 - 1239,
Add a post-rollback staleness alert for the rust_bootstrap path after the
rollback verification loop, checking whether the health file is missing or its
SHA remains unchanged from previous_health_sha. Keep bootstrap success based on
verify_bootstrap_rust_runtime and preserve the degraded-baseline behavior;
report the stale health condition as an operator-visible alert rather than
failing the rollback.
deployment/aliyun/polymarket-shadow-gate-policy.jq (1)

219-241: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Consider pinning baseline_degraded in the non-bootstrap branches.

The rust_bootstrap branch requires .baseline_degraded == true. The legacy_python branch at Lines 141-195 and the rust_release branch at Lines 198-218 do not constrain .baseline_degraded. Evidence that sets baseline_degraded to true under rust_release still passes the policy. Adding an explicit false assertion to both branches makes the field authoritative for every baseline mode.

♻️ Proposed tightening for the `rust_release` branch
     .baseline_mode == "rust_release"
+    and .baseline_degraded == false
     and .baseline_health_start_required == false
🤖 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 219 - 241,
Pin the baseline_degraded field in both non-bootstrap policy branches: add an
explicit .baseline_degraded == false condition to the legacy_python branch and
the rust_release branch. Leave the rust_bootstrap branch’s existing true
assertion unchanged, ensuring every baseline mode authoritatively constrains
this field.
🤖 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-cutover.sh`:
- Around line 1240-1286: Extract the repeated three-way rollback runtime
dispatch into a single verify_rollback_runtime helper that accepts the failure
message and performs the existing legacy_python, rust_release, and bootstrap
checks before calling die. Replace all three inline dispatch blocks with helper
calls using their current messages, and update the contract test expectations
that grep for the removed literal lines.
- Around line 1223-1239: Add a post-rollback staleness alert for the
rust_bootstrap path after the rollback verification loop, checking whether the
health file is missing or its SHA remains unchanged from previous_health_sha.
Keep bootstrap success based on verify_bootstrap_rust_runtime and preserve the
degraded-baseline behavior; report the stale health condition as an
operator-visible alert rather than failing the rollback.

In `@deployment/aliyun/polymarket-shadow-gate-policy.jq`:
- Around line 219-241: Pin the baseline_degraded field in both non-bootstrap
policy branches: add an explicit .baseline_degraded == false condition to the
legacy_python branch and the rust_release branch. Leave the rust_bootstrap
branch’s existing true assertion unchanged, ensuring every baseline mode
authoritatively constrains this field.

In `@deployment/aliyun/test-polymarket-raw-ops-control-plane.sh`:
- Around line 4941-4944: Update the occurrence lookups for
active_target_guard_line and active_rm_line to assert the expected match count
before selecting the final occurrence, following the existing invocation-ID
check pattern at Line 4579. Preserve selecting the intended legacy_python block
while making the ordering assertion fail if additional matching branches are
introduced later.
- Around line 1387-1400: Extend the drift loop in the test around
verify_baseline_identity with cases that independently violate the
bootstrap-specific guards: set baseline_release_path different from
RUST_ACTIVE_BINARY, make RUST_ACTIVE_BINARY a symlink, and make
baseline_release_path non-executable. Ensure each case causes
verify_baseline_identity to reject the baseline while preserving the existing
active, proc, digest, and runtime cases.
- Around line 2331-2339: The non-executable bootstrap test currently validates
only recorded mode metadata because make_bootstrap_lineage_evidence restores
executable permissions. Rename the existing bootstrap-nonexec case and its
failure message to identify the mode-metadata rejection, then add a separate
case that keeps mode 0755 while removing the executable bit from
evidence/rollback/bin/polymarket-raw-ops and verifies manual rollback rejects
it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b20ffbac-33a4-4f9c-b6cb-d594c25d0f87

📥 Commits

Reviewing files that changed from the base of the PR and between 25b6e6d and 37fcc51.

📒 Files selected for processing (4)
  • deployment/aliyun/polymarket-raw-ops-cutover.sh
  • 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: 37fcc5186a

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

@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

🤖 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 5172-5183: Update the control-plane identity assertion near the
legacy_test_reference_allowlist check to match the workflow’s actual
exec_start|cmdline allowlist regex rather than the hardcoded line-17 LEGACY_EXEC
string. Use the real LEGACY_EXEC definition at line 1411 and preserve validation
against legacy_test_reference_allowlist.
🪄 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: 75972bdb-e80d-45bb-b6fa-68bcb5c75da2

📥 Commits

Reviewing files that changed from the base of the PR and between 37fcc51 and 6392007.

📒 Files selected for processing (4)
  • .github/workflows/ci.yml
  • deployment/aliyun/polymarket-raw-ops-cutover.sh
  • deployment/aliyun/polymarket-shadow-gate-policy.jq
  • deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • deployment/aliyun/polymarket-shadow-gate-policy.jq
  • deployment/aliyun/polymarket-raw-ops-cutover.sh

Comment thread deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
@proerror77
proerror77 enabled auto-merge (squash) August 3, 2026 00:01
@proerror77
proerror77 force-pushed the codex/polymarket-bootstrap-recovery branch from 6392007 to 5e3ccb2 Compare August 3, 2026 00:14
@proerror77
proerror77 merged commit 2dd3b8b into main Aug 3, 2026
49 checks passed
@proerror77
proerror77 deleted the codex/polymarket-bootstrap-recovery branch August 3, 2026 00:20
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.

1 participant