Skip to content

feat(collector): add USD-M reference host gate - #263

Merged
proerror77 merged 1 commit into
mainfrom
codex/cex-usdm-reference-host-gate-222
Jul 23, 2026
Merged

proerror77 merged 1 commit into
mainfrom
codex/cex-usdm-reference-host-gate-222

Conversation

@proerror77

@proerror77 proerror77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Part of #222.

Change contract

Compile immutable, production-eligible USD-M reference shadow-gate evidence by read-only observation of one already-running, release-pinned collector and canonical Rust artifact verifier.

Out of scope

Dependency / merge order

Depends on merged PR #262, which packages the strict read-only Rust artifact verifier. Merge after #262; no stacked unmerged dependency remains.

Focused validation

  • bash -n deployment/aliyun/binance-usdm-reference-shadow-gate.sh deployment/aliyun/test-binance-usdm-reference-host-gate.sh
  • shellcheck deployment/aliyun/binance-usdm-reference-shadow-gate.sh deployment/aliyun/test-binance-usdm-reference-host-gate.sh
  • bash deployment/aliyun/test-binance-usdm-reference-host-gate.sh
  • bash deployment/aliyun/test-binance-usdm-reference-shadow-gate.sh
  • bash deployment/aliyun/test-binance-usdm-reference-release-contract.sh
  • cargo test --quiet --manifest-path rust_hft/Cargo.toml -p hft-collector --bin binance-usdm-reference-artifact-verifier
  • git diff --check
  • Independent Spec and Standards reviews: no blocker.

Counterexamples reject tampered data, symlinked manifests, InvocationID replacement, historical API errors, artifact gaps over 90 seconds, and verifier SHA drift. Test-only gates cannot set passed/production_eligible or publish PASSED.sha256.

Rollout / rollback impact

Rollout packages the read-only runner in the dedicated USD-M reference control bundle. It does not mutate a host. A separately authorized single controller must later install/start the isolated shadow service and run the >=3600 second gate. Rollback removes the runner from the dedicated bundle; existing collector and research behavior are unchanged.

Summary by CodeRabbit

  • New Features

    • Added a shadow gate for Binance USD-M reference releases.
    • Validates release integrity, service identity, artifact continuity, health status, and minimum artifact availability.
    • Produces structured gate evidence and pass markers for eligible releases.
    • Includes the gate script in packaged control assets and checksum manifests.
  • Tests

    • Added comprehensive acceptance and rejection coverage for tampered artifacts, invalid manifests, service changes, health errors, timing gaps, and verifier hash drift.
    • Added contract checks confirming the gate is included in CI packaging.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a USD-M reference shadow gate, deterministic end-to-end tests, and ACR workflow packaging and contract checks for the new gate asset.

Changes

USD-M reference shadow gate

Layer / File(s) Summary
Gate bundle integrity and execution constraints
deployment/aliyun/binance-usdm-reference-shadow-gate.sh
Validates release structure, control asset hashes, release metadata, service templates, locking, and gate duration rules.
Runtime observation and evidence publication
deployment/aliyun/binance-usdm-reference-shadow-gate.sh
Checks running collector identity, artifact integrity and continuity, health freshness, immutable readback, and gate evidence publication.
Workflow packaging and contract wiring
.github/workflows/acr-publish.yml, deployment/aliyun/test-binance-usdm-reference-release-contract.sh, deployment/aliyun/test-binance-usdm-reference-shadow-gate.sh
Packages and hashes the gate script and asserts its presence in workflow and control-asset references.
Fixture harness and acceptance scenarios
deployment/aliyun/test-binance-usdm-reference-host-gate.sh
Builds deterministic fixtures, validates successful evidence output, and tests tampered data, symlinks, service identity changes, health errors, discontinuities, and verifier digest drift.

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

Sequence Diagram(s)

sequenceDiagram
  participant ShadowGate
  participant Systemd
  participant Spool
  participant ArtifactVerifier
  participant GateEvidence
  ShadowGate->>Systemd: inspect active unit and collector identity
  ShadowGate->>Spool: scan artifact manifests and health.json
  ShadowGate->>ArtifactVerifier: verify artifact data and manifest bindings
  ShadowGate->>GateEvidence: write gate.json and production pass marker
Loading

Possibly related PRs

  • proerror77/monday#259: Adds overlapping USD-M shadow gate implementation, tests, and workflow packaging changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title matches the main change: adding a USD-M reference gate, though it is a bit broader than the new shadow-gate runner.
Description check ✅ Passed The description covers the contract, out of scope, dependencies, validation, and rollout, but omits an explicit scope-exception section.
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/cex-usdm-reference-host-gate-222

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
.github/workflows/acr-publish.yml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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 dc38369 into main Jul 23, 2026
32 of 33 checks passed

@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: 89a76f6a7c

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

@@ -0,0 +1,245 @@
#!/usr/bin/env bash

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 Run the new host-gate suite in CI

This regression suite is not invoked by any workflow or other test script. I checked the repository-wide references and the control-plane step in .github/workflows/ci.yml; it runs four older deployment suites but never test-binance-usdm-reference-host-gate.sh. Consequently, changes can break the production gate while CI still passes, despite this being the only suite exercising its host-level behavior.

Useful? React with 👍 / 👎.

Comment on lines +235 to +236
jq ".observed_at_ns=$((start_ns + 92000000000))" "$third_manifest" \
>"$third_manifest.tmp" && mv "$third_manifest.tmp" "$third_manifest"

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 Make the discontinuity test reach the gap check

When this counterexample mutates the latest manifest timestamp, its SHA changes but health.json.manifest_sha256 is left bound to the original manifest. The runner therefore rejects the fixture at the health-binding check before testing artifact continuity, so removing or breaking the 90-second gap validation would still leave this test green. Update the fixture's canonical paths and health binding so the excessive gap is the sole rejection reason.

Useful? React with 👍 / 👎.

@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/binance-usdm-reference-shadow-gate.sh`:
- Around line 53-56: Update the preflight validation near the
command-availability loop to require jq decimal-number support before processing
nanosecond epoch values. Invoke jq with have_decnum and fail through die unless
it reports true, preserving the existing missing-command checks and ensuring
downstream artifact filtering and timestamp calculations only run with a
precision-safe jq build.
🪄 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: b5d39a17-7ca6-4756-a52a-8d9191b8c211

📥 Commits

Reviewing files that changed from the base of the PR and between 1adbeee and 89a76f6.

📒 Files selected for processing (5)
  • .github/workflows/acr-publish.yml
  • deployment/aliyun/binance-usdm-reference-shadow-gate.sh
  • deployment/aliyun/test-binance-usdm-reference-host-gate.sh
  • deployment/aliyun/test-binance-usdm-reference-release-contract.sh
  • deployment/aliyun/test-binance-usdm-reference-shadow-gate.sh

Comment on lines +53 to +56
for command in awk cmp date dirname find jq mkdir mktemp readlink rm sha256sum \
sleep sort stat systemctl tr; do
command -v "$command" >/dev/null 2>&1 || die "missing required command: $command"
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

jq have_decnum builtin which version introduced default enabled

💡 Result:

The builtin function have_decnum was introduced in jq 1.7 [1]. It is enabled by default in the standard build [2][3], as it serves to identify whether the jq binary was compiled with decNumber support (which maintains decimal precision for literals) [3][1]. Users can explicitly disable this support at compile time using the --disable-decnum configuration option [2][3]. Because decnum is enabled by default in official distributions, have_decnum typically returns true [3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repository files matching shadow gate:"
git ls-files | grep -F deployment/aliyun/binance-usdm-reference-shadow-gate.sh || true

echo
echo "Relevant source lines:"
sed -n '45,70p' deployment/aliyun/binance-usdm-reference-shadow-gate.sh
sed -n '288,305p' deployment/aliyun/binance-usdm-reference-shadow-gate.sh
sed -n '325,345p' deployment/aliyun/binance-usdm-reference-shadow-gate.sh

echo
echo "Policy files and jq usage references:"
git ls-files | grep 'binance-usdm.*policy\|binance-usdm.*gate' | sed -n '1,80p'
rg -n "observed_at_ns|last_success_at_ns|have_decnum|decnum|gate-policy|timing|gate.json" deployment/aliyun || true

Repository: proerror77/monday

Length of output: 25680


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "jq availability and version details:"
if command -v jq >/dev/null 2>&1; then
  jq --version || true
  jq -n 'have_decnum' || true
  jq -n '"observed_at_ns_value": 1700000000000000000' || true
  jq -n '.observed_at_ns == floor and .observed_at_ns > 0' <<'EOF'
{"observed_at_ns": 1700000000000000000}
EOF
else
  echo "jq not available"
fi

echo
echo "Package version constraints:"
for f in Dockerfile* *.Dockerfile docker-compose*.yaml docker-compose*.yml requirements.txt pyproject.toml poetry.lock uv.lock Cargo.lock package-lock.json pnpm-lock.yaml yarn.lock Makefile; do
  if [ -e "$f" ]; then
    echo "--- $f ---"
    rg -n "jq|jq-|jqlang|version|image|apt|apk|install" "$f" | sed -n '1,120p' || true
  fi
done

Repository: proerror77/monday

Length of output: 454


Add a jq decnum guard before relying on nanosecond epochs.

observed_at_ns and last_success_at_ns are around 1.7e18, which exceeds safe integer precision on older/decnum-disabled jq builds. If jq reads/corrupts those literals, artifact filtering, evidence timestamp binding, and discontinuity math can fail or write incorrect evidence. Gate preflight on jq -n 'have_decnum' == true, or pin a jq ≥ 1.7+ build that preserves decimal integer literals.

🤖 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/binance-usdm-reference-shadow-gate.sh` around lines 53 -
56, Update the preflight validation near the command-availability loop to
require jq decimal-number support before processing nanosecond epoch values.
Invoke jq with have_decnum and fail through die unless it reports true,
preserving the existing missing-command checks and ensuring downstream artifact
filtering and timestamp calculations only run with a precision-safe jq build.

@proerror77
proerror77 deleted the codex/cex-usdm-reference-host-gate-222 branch July 24, 2026 08:44
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