Skip to content

fix(polymarket): bind legacy health freshness to writes - #419

Merged
proerror77 merged 2 commits into
mainfrom
codex/polymarket-legacy-health-write-freshness-418
Jul 28, 2026
Merged

fix(polymarket): bind legacy health freshness to writes#419
proerror77 merged 2 commits into
mainfrom
codex/polymarket-legacy-health-write-freshness-418

Conversation

@proerror77

@proerror77 proerror77 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Change contract

Bind legacy Python Gate freshness to a stable atomic health-file write while preserving exact payload timestamps and strict immutable evidence.

Out of scope

Collector/snapshot/research logic, #235, parity semantics, observation duration, PID/restart identity, OSS readback behavior, and production cutover.

Dependency / merge order

Base exact-main b199e1c87cf9a547c3d0ca605810ee2b26c2437c (PR #417). Merge this before rebuilding the next exact-main release artifact.

Focused validation

  • bash deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
  • git diff --check
  • Full-policy positive counterexample: atomic completion write remains admissible when payload cycle-start age exceeds 240 seconds.
  • Fail-closed counterexamples: stale write, future payload timestamp, malformed/impossible UTC timestamps, missing/unbound write evidence, unchanged post-start success.
  • Two-axis Spec and Standards review: 0 findings.

Rollout / rollback impact

Rebuild a new digest-addressed exact-main artifact and run a fresh 3600+601 second Gate. Revert this PR to restore the prior payload-age freshness rule; production remains on Python until the Gate and cutover both pass.

Closes #418

Summary by CodeRabbit

  • New Features

    • Added more precise health snapshot timing evidence, including filesystem write times.
    • Added strict UTC timestamp validation and parity-window duration checks.
    • Added ordering safeguards for startup, completion, and health snapshot events.
  • Bug Fixes

    • Improved detection of stale or inconsistently updated health data.
    • Rejected malformed, impossible, or out-of-order timestamps during gate validation.
  • Tests

    • Expanded coverage for timestamp boundaries, write-time requirements, freshness checks, and event ordering.

@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: 13 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: 7e5e757a-f405-40d6-82cf-9e595bbf257c

📥 Commits

Reviewing files that changed from the base of the PR and between b8994eb and ae930e7.

📒 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
📝 Walkthrough

Walkthrough

The legacy shadow-gate path now captures health-file write times, validates strict timestamp and ordering constraints, records the evidence in gate.json, and expands control-plane tests for invalid timestamps, write-time boundaries, Rust-mode nulls, and observation ordering.

Changes

Legacy health freshness

Layer / File(s) Summary
Timestamp parsing and policy constraints
deployment/aliyun/polymarket-shadow-gate-policy.jq
Adds strict UTC timestamp parsing, parity-window validation, legacy write-time ordering checks, and Rust-mode null requirements.
Legacy health observation flow
deployment/aliyun/polymarket-raw-ops-shadow-gate.sh
Captures stable legacy health snapshots and filesystem write times, validates freshness and cutoff ordering, and emits the new evidence fields in gate.json.
Control-plane validation coverage
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh
Updates fixtures and adds negative tests for write-time boundaries, malformed dates, impossible calendar values, Rust-mode fields, and observer ordering.

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

Sequence Diagram(s)

sequenceDiagram
  participant ShadowGate as Shadow gate
  participant HealthFile as Legacy health file
  participant Policy as jq policy
  participant GateJSON as gate.json
  ShadowGate->>HealthFile: Capture snapshot and filesystem write time
  ShadowGate->>Policy: Validate freshness and timestamp ordering
  Policy-->>ShadowGate: Accept validated observation
  ShadowGate->>GateJSON: Record baseline write-time evidence
Loading

Possibly related issues

  • proerror77/monday#418 — Covers legacy Gate freshness binding through completed health writes and write-time ordering.
  • proerror77/monday#416 — Covers legacy snapshot freezing, freshness observation, completion cutoff, and evidence validation.

Possibly related PRs

  • proerror77/monday#34 — Modifies the same shadow-gate scripts and legacy health written_at_unix validation.
  • proerror77/monday#389 — Overlaps the legacy baseline-health decision and parity-cutoff control path.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and accurately describes the main change: binding legacy health freshness to writes.
Description check ✅ Passed The description covers the required contract, scope, dependencies, validation, and rollback details; it only omits the explicit Scope exception entry.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/polymarket-legacy-health-write-freshness-418

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.

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

ℹ️ 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

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

🧹 Nitpick comments (2)
deployment/aliyun/test-polymarket-raw-ops-control-plane.sh (1)

1939-1949: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Disambiguate line-number greps for robustness.

snapshot_line, completion_snapshot_line, gate_start_line, and shadow_start_line don't pin down a single match the way daemon_reload_line does with tail -1. If any of these literal markers were ever duplicated in $GATE in the future, cut -d: -f1 would yield a multi-line value and the subsequent ((...)) comparison would likely error out with an unclear message rather than a clean assertion failure.

♻️ Proposed hardening
-snapshot_line=$(grep -nF 'baseline_health_observation=$(fresh_legacy_health_observation' \
-  "$GATE" | cut -d: -f1)
+snapshot_line=$(grep -nF 'baseline_health_observation=$(fresh_legacy_health_observation' \
+  "$GATE" | head -1 | cut -d: -f1)

(similarly for completion_snapshot_line, gate_start_line, shadow_start_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 1939
- 1949, Update the line-number lookups for snapshot_line,
completion_snapshot_line, gate_start_line, and shadow_start_line to select a
single matching line, consistent with daemon_reload_line using tail -1. Keep the
existing ordering assertion unchanged so duplicate markers produce a
deterministic comparison and clean failure.
deployment/aliyun/polymarket-shadow-gate-policy.jq (1)

44-80: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Repeated utc_iso8601_unix computation for started_at/completed_at.

.started_at | utc_iso8601_unix is computed independently 4 times (lines 44, 65, 66-67, 78) and .completed_at | utc_iso8601_unix twice (48, 80). Binding these once (e.g. (.started_at | utc_iso8601_unix) as $started_at_unix) would avoid duplicated logic and reduce the risk of one occurrence silently drifting from the others in future edits to this security-relevant policy.

♻️ Proposed refactor sketch
+and ((.started_at | utc_iso8601_unix) as $started_at_unix | $started_at_unix | type == "number")
+and ((.completed_at | utc_iso8601_unix) as $completed_at_unix | $completed_at_unix | type == "number")
-and (.started_at | utc_iso8601_unix | type == "number")
 and (.parity_window_started_at_unix | positive_integer)
 and (.parity_window_ended_at_unix | positive_integer)
 and (.parity_window_ended_at_unix - .parity_window_started_at_unix >= 601)
-and (.completed_at | utc_iso8601_unix | type == "number")

(actual binding would need to be threaded through the surrounding and chain, e.g. via a top-level . as $root | ($root.started_at|utc_iso8601_unix) as $started_at_unix | ($root.completed_at|utc_iso8601_unix) as $completed_at_unix | ...)

🤖 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 44 - 80,
Refactor the policy around its top-level predicate to bind the converted
started_at and completed_at values once, using scoped variables such as
$started_at_unix and $completed_at_unix, while preserving the existing root
object context. Replace every repeated utc_iso8601_unix use for these fields
throughout the baseline validation branch and surrounding checks with the
corresponding bindings.
🤖 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/polymarket-raw-ops-shadow-gate.sh`:
- Around line 396-422: Document the freshness contract introduced around
fresh_legacy_health_observation: legacy health observations use the file rewrite
mtime, bounded by MAX_HEALTH_SILENCE_SECONDS, as the recency signal, while
updated_at and last_success_at only need to be non-empty and not future-dated.
Add this clarification where the gate freshness contract is defined, without
changing the existing validation logic.

In `@deployment/aliyun/polymarket-shadow-gate-policy.jq`:
- Around line 4-15: Update the deployment policy around utc_iso8601_unix to
explicitly require jq 1.7 or newer, documenting and enforcing that version
requirement wherever this policy is executed. Keep the existing UTC timestamp
validation and conversion behavior unchanged rather than relying on pre-1.7
timezone-dependent date builtins.

---

Nitpick comments:
In `@deployment/aliyun/polymarket-shadow-gate-policy.jq`:
- Around line 44-80: Refactor the policy around its top-level predicate to bind
the converted started_at and completed_at values once, using scoped variables
such as $started_at_unix and $completed_at_unix, while preserving the existing
root object context. Replace every repeated utc_iso8601_unix use for these
fields throughout the baseline validation branch and surrounding checks with the
corresponding bindings.

In `@deployment/aliyun/test-polymarket-raw-ops-control-plane.sh`:
- Around line 1939-1949: Update the line-number lookups for snapshot_line,
completion_snapshot_line, gate_start_line, and shadow_start_line to select a
single matching line, consistent with daemon_reload_line using tail -1. Keep the
existing ordering assertion unchanged so duplicate markers produce a
deterministic comparison and clean failure.
🪄 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: e1f30fff-309b-4c10-bfd1-f9698f035973

📥 Commits

Reviewing files that changed from the base of the PR and between b199e1c and b8994eb.

📒 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/polymarket-raw-ops-shadow-gate.sh
Comment thread deployment/aliyun/polymarket-shadow-gate-policy.jq
@proerror77
proerror77 merged commit 1c3535d into main Jul 28, 2026
50 checks passed
@proerror77
proerror77 deleted the codex/polymarket-legacy-health-write-freshness-418 branch July 28, 2026 02:36
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): bind legacy Gate freshness to completed health writes

1 participant