Skip to content

fix(deploy): thaw shadow before final stop - #57

Merged
proerror77 merged 1 commit into
mainfrom
codex/fix-shadow-gate-thaw
Jul 16, 2026
Merged

fix(deploy): thaw shadow before final stop#57
proerror77 merged 1 commit into
mainfrom
codex/fix-shadow-gate-thaw

Conversation

@proerror77

@proerror77 proerror77 commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Fixes the failed Polymarket Rust shadow gate finalization.

The gate froze the shadow unit for its final memory snapshot, queued SIGTERM, then attempted systemctl stop while the unit was still frozen. Systemd correctly rejected that operation.

The fixed fail-closed sequence is: freeze → verify frozen → snapshot → SIGTERM → thaw → verify running → stop. The existing control-plane contract now asserts the final thaw transition and ordering.

Validation: bash deployment/aliyun/test-polymarket-raw-ops-control-plane.sh, bash -n, ShellCheck, git diff --check.

Summary by CodeRabbit

  • Bug Fixes

    • Improved shutdown handling for the Rust shadow service by explicitly thawing it after termination.
    • Added verification that the service returns to a running freezer state before shutdown completes.
  • Tests

    • Strengthened safety checks to verify the shutdown steps occur in the correct order, including thawing and state confirmation.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The shadow gate now thaws the frozen Rust unit and verifies FreezerState=running before stopping it. Control-plane assertions enforce the ordering from freeze through snapshot, kill, thaw, state verification, and stop.

Changes

Shadow gate lifecycle

Layer / File(s) Summary
Thaw validation before final stop
deployment/aliyun/polymarket-raw-ops-shadow-gate.sh, deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
The gate verifies the unit is running after thaw, while the control-plane test enforces thaw and thawed-state checks before the final stop.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: thawing the shadow unit before the final stop.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-shadow-gate-thaw

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

1247-1263: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Enhance grep robustness and remove redundant condition.

Consider these minor adjustments for consistency and test robustness:

  1. Add || true to the final_stop_line assignment. If set -e and pipefail are active, a missing stop command will abruptly terminate the script, hiding your custom shadow final freeze/snapshot/kill/thaw/stop sequence is unsafe diagnostic.
  2. Add | tail -1 to the thawed_state_line assignment for consistency with other variables and to prevent multiple matches from breaking the integer validation.
  3. Remove the redundant && $kill_line -lt $final_stop_line condition, as it is mathematically guaranteed by the preceding less-than checks.
♻️ Proposed refactor
-thawed_state_line=$(grep -n '^shadow_thawed_state=.*FreezerState' "$GATE" \
-  | cut -d: -f1 || true)
-final_stop_line=$(grep -n '^systemctl stop "$shadow_unit"$' "$GATE" | tail -1 | cut -d: -f1)
+thawed_state_line=$(grep -n '^shadow_thawed_state=.*FreezerState' "$GATE" \
+  | tail -1 | cut -d: -f1 || true)
+final_stop_line=$(grep -n '^systemctl stop "$shadow_unit"$' "$GATE" | tail -1 | cut -d: -f1 || true)
 [[ $freeze_line =~ ^[1-9][0-9]*$ \
   && $freezer_state_line =~ ^[1-9][0-9]*$ \
   && $final_memory_line =~ ^[1-9][0-9]*$ \
   && $kill_line =~ ^[1-9][0-9]*$ \
   && $final_thaw_line =~ ^[1-9][0-9]*$ \
   && $thawed_state_line =~ ^[1-9][0-9]*$ \
   && $final_stop_line =~ ^[1-9][0-9]*$ \
   && $freeze_line -lt $freezer_state_line \
   && $freezer_state_line -lt $final_memory_line \
   && $final_memory_line -lt $kill_line \
   && $kill_line -lt $final_thaw_line \
   && $final_thaw_line -lt $thawed_state_line \
-  && $thawed_state_line -lt $final_stop_line \
-  && $kill_line -lt $final_stop_line ]] || {
+  && $thawed_state_line -lt $final_stop_line ]] || {
🤖 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 1247
- 1263, Harden the sequence-line extraction and simplify its validation: update
the final_stop_line pipeline to tolerate missing matches with || true, make
thawed_state_line select only the last matching line via tail -1, and remove the
redundant kill_line -lt final_stop_line check from the compound condition.
🤖 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/test-polymarket-raw-ops-control-plane.sh`:
- Around line 1247-1263: Harden the sequence-line extraction and simplify its
validation: update the final_stop_line pipeline to tolerate missing matches with
|| true, make thawed_state_line select only the last matching line via tail -1,
and remove the redundant kill_line -lt final_stop_line check from the compound
condition.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e477fff-4a79-4fc3-bdbc-a6881ddf2488

📥 Commits

Reviewing files that changed from the base of the PR and between f18af3d and 91bad6e.

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

@proerror77
proerror77 merged commit 42ade9a into main Jul 16, 2026
18 checks passed
@proerror77
proerror77 deleted the codex/fix-shadow-gate-thaw branch July 16, 2026 05:11
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