Skip to content

feat(deploy): add fail-closed trading ECS host contract - #47

Merged
proerror77 merged 1 commit into
mainfrom
codex/trading-ecs-host-contract
Jul 16, 2026
Merged

feat(deploy): add fail-closed trading ECS host contract#47
proerror77 merged 1 commit into
mainfrom
codex/trading-ecs-host-contract

Conversation

@proerror77

@proerror77 proerror77 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Outcome

Adds the reviewed bare-ECS deployment contract for a future Tokyo Ubuntu 26.04 trading host. It publishes a digest-pinned ACR artifact and supports only Paper or Shadow activation.

Safety boundary

  • Does not create or start an ECS, ACK workload, ClickHouse, or cloud resource.
  • Rejects tags, non-Tokyo endpoints, LiveSmall, unknown intents, stale or orphan containers, and persistent secrets.
  • Uses a static systemd service with Restart=no and no boot enablement.
  • Cutover and rollback are locked, evidence-bound, and fail closed.

Verification

  • deployment/aliyun/test-trading-ecs-host-contract.sh
  • deployment_artifacts: 7 passed
  • deployment_envelope: 9 passed
  • tracked-secret contract: 7 passed
  • ShellCheck, bash syntax, workflow YAML, and git diff checks passed

Summary by CodeRabbit

  • New Features

    • Added a controlled deployment workflow for a dedicated Tokyo bare-ECS trading host, including staging, cutover, and rollback with evidence markers.
    • Introduced a static systemd runtime service and hardened host control/runtime flows with digest-pinned Paper/Shadow-only activation.
    • Updated build/publish to push ACR images with commit and run-based tags, plus deterministic contract bundle artifacts.
  • Documentation

    • Clarified collector vs trading host scope and added the Tokyo trading host contract documentation.
  • Tests

    • Expanded CI verification by adding trading host contract conformance coverage.

@coderabbitai

coderabbitai Bot commented Jul 15, 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: 34 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

Run ID: 80d3c10f-8d2f-4268-a97a-780cd30fa729

📥 Commits

Reviewing files that changed from the base of the PR and between 5062296 and 0bf3a32.

📒 Files selected for processing (10)
  • .github/workflows/acr-publish.yml
  • .github/workflows/ci.yml
  • deployment/aliyun/README.md
  • deployment/aliyun/TRADING_ECS_HOST.md
  • deployment/aliyun/hft-trading-ecs.service
  • deployment/aliyun/test-trading-ecs-host-contract.sh
  • deployment/aliyun/trading-ecs-hostctl.sh
  • deployment/aliyun/trading-ecs-paper-shadow-policy.jq
  • deployment/aliyun/trading-ecs-runtime.sh
  • rust_hft/deployment/PRODUCTION_DEPLOYMENT.md
📝 Walkthrough

Walkthrough

Adds a digest-pinned Tokyo bare-ECS trading host contract, deterministic ACR release packaging, hardened runtime and lifecycle scripts, a static systemd unit, Paper/Shadow policy validation, operational documentation, and comprehensive CI contract tests.

Changes

Tokyo trading ECS host

Layer / File(s) Summary
Release packaging and host contract
.github/workflows/acr-publish.yml, deployment/aliyun/README.md, deployment/aliyun/TRADING_ECS_HOST.md, rust_hft/deployment/PRODUCTION_DEPLOYMENT.md
Publishes commit and run-attempt image tags, creates a deterministic trading host bundle and release manifest, and documents digest-only staging, activation, credentials, cutover, rollback, and non-goals.
Policy and hardened runtime validation
deployment/aliyun/trading-ecs-paper-shadow-policy.jq, deployment/aliyun/trading-ecs-runtime.sh
Validates Paper/Shadow activation authority, secure manifests and secrets, release identities, local image digests, and hardened Docker lifecycle operations.
Static service, staging, cutover, and rollback
deployment/aliyun/hft-trading-ecs.service, deployment/aliyun/trading-ecs-hostctl.sh
Adds a static non-boot-starting systemd unit and locked host-control commands for artifact staging, health-gated cutover, evidence recording, pointer restoration, and rollback.
Contract test integration
deployment/aliyun/test-trading-ecs-host-contract.sh, .github/workflows/ci.yml
Tests invalid image references, Docker states, credentials, activation and authority tampering, secret validation, artifact integrity, runtime replacement, pointer writes, and forbidden workflow or service settings in CI.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ReleaseWorkflow
  participant ACR
  participant HostControl
  participant Runtime
  participant Systemd
  ReleaseWorkflow->>ACR: build and publish digest-pinned image
  ReleaseWorkflow->>HostControl: upload release manifest and control bundle
  HostControl->>ACR: login and pull exact digest
  HostControl->>Runtime: run preflight validation
  HostControl->>Systemd: install and explicitly start service
  Systemd->>Runtime: run hardened trading container
  Runtime-->>HostControl: return health, readiness, and identity
  HostControl->>Systemd: stop and restore pointer on failure or rollback
Loading

Possibly related PRs

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a fail-closed trading ECS host contract.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/trading-ecs-host-contract

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.

Comment thread .github/workflows/acr-publish.yml Fixed

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

ℹ️ 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/trading-ecs-runtime.sh
Comment thread deployment/aliyun/trading-ecs-hostctl.sh Outdated
Comment thread deployment/aliyun/trading-ecs-paper-shadow-policy.jq Outdated
Comment thread deployment/aliyun/trading-ecs-hostctl.sh Outdated
Comment thread deployment/aliyun/trading-ecs-runtime.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: 11

🤖 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 @.github/workflows/acr-publish.yml:
- Around line 86-98: Update the registry validation case around
published_registry to require the complete Tokyo Personal Edition hostname
contract, including a crpi-<id> prefix, for both standard and -vpc endpoints.
Reject arbitrary prefixes before generating vpc_registry or rewriting
published_registry, while preserving the existing normalization and error
behavior for valid hostnames.
- Around line 130-138: Update the actions/upload-artifact step for “Upload
bare-metal trading host contract” to reference a full immutable commit SHA
instead of the mutable `@v4` tag, while preserving its existing artifact settings
and conditional execution.

In `@deployment/aliyun/trading-ecs-hostctl.sh`:
- Around line 546-558: Update deployment/aliyun/trading-ecs-hostctl.sh in the
rollback flow to preserve PASSED.sha256 and atomically create append-only
rollback-intent and rolled-back evidence markers instead of renaming or deleting
the success marker. Document this additive revocation state machine in
deployment/aliyun/TRADING_ECS_HOST.md lines 131-134, and update
deployment/aliyun/test-trading-ecs-host-contract.sh lines 325-328 to verify
PASSED.sha256 remains unchanged and both rollback markers are present and
validated.
- Around line 430-434: Update the deployment evidence flow around
candidate_file, previous_file, and PASSED.sha256 to record each snapshot’s
content hash or an explicit absent marker. Make candidate-current.env and
previous-current.env immutable or append-only, then have rollback validate those
recorded values and require the current pointer to match the committed candidate
before invalidating rollback authorization.
- Around line 247-281: Move the enabled-state rejection in
deployment/aliyun/trading-ecs-hostctl.sh:247-281 before Docker pull and all
installation mutations, while retaining the post-staging postcondition. Update
deployment/aliyun/TRADING_ECS_HOST.md:21-23 to state that boot safety also
requires rejecting pre-existing service enablement, and revise
deployment/aliyun/hft-trading-ecs.service:30-31 so it does not claim the missing
[Install] section alone prevents boot startup. Extend
deployment/aliyun/test-trading-ecs-host-contract.sh:338-345 to verify an enabled
service is rejected before any persistent mutation.
- Around line 82-84: Canonicalize the artifact and password paths before
trusted-root containment checks, rejecting unresolved or escaping paths rather
than relying on raw prefixes containing “..”. Update the artifact validation
around artifact_root and artifact_dir to require a canonical direct-child path,
and verify the password path’s actual filesystem with findmnt before accepting
it. Preserve the existing secure_directory checks after canonical validation.

In `@deployment/aliyun/trading-ecs-paper-shadow-policy.jq`:
- Around line 25-35: Update the activation-intent validation in the policy
expression so the selected StartPaper or StartShadow intent is present in both
$signed.envelope.allowed_intent_types and $policy[0].allowed_intent_types.
Preserve the existing approval_class matching and StartLiveSmall exclusions
while ensuring LoadFactor-only policy entries cannot authorize a start intent.
- Around line 1-2: Update the one_json_value jq helper to accept exactly one
input JSON value and raise an error when additional values are emitted, rather
than acting as an identity filter. Preserve the existing single-value output so
jq -e cannot ignore a failing value followed by a passing one.

In `@deployment/aliyun/trading-ecs-runtime.sh`:
- Around line 83-100: Update the actual_names check in the manifest validation
flow to exclude only the root activation.sha256 marker, not nested files with
that name, and reject special filesystem objects by limiting the find results to
regular files. Preserve the exact manifest-to-activation directory comparison
and the existing manifest validation rules.
- Around line 123-130: Harden validate_runtime_secrets by rejecting secret_root
when its permissions allow group or world writes, before validating or consuming
the secret files. Check the directory mode using the existing filesystem
validation flow and return failure unless the directory is owned and writable
only by the expected trusted user, preserving the current tmpfs and non-symlink
checks.
- Around line 239-244: Remove the --env-file "$secret_root/runtime.env" option
from the container launch command in the runtime script. Preserve the existing
read-only secret-file mounts, and update the runtime initialization to load
HFT_GRPC_AUTH_TOKEN and HFT_SECRET_* values from those mounted files instead of
container environment metadata.
🪄 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

Run ID: e7fb1687-ed80-4a40-9bdc-97d8ad41caf2

📥 Commits

Reviewing files that changed from the base of the PR and between 2b82d59 and ec5db8c.

📒 Files selected for processing (10)
  • .github/workflows/acr-publish.yml
  • .github/workflows/ci.yml
  • deployment/aliyun/README.md
  • deployment/aliyun/TRADING_ECS_HOST.md
  • deployment/aliyun/hft-trading-ecs.service
  • deployment/aliyun/test-trading-ecs-host-contract.sh
  • deployment/aliyun/trading-ecs-hostctl.sh
  • deployment/aliyun/trading-ecs-paper-shadow-policy.jq
  • deployment/aliyun/trading-ecs-runtime.sh
  • rust_hft/deployment/PRODUCTION_DEPLOYMENT.md

Comment thread .github/workflows/acr-publish.yml
Comment thread .github/workflows/acr-publish.yml
Comment thread deployment/aliyun/trading-ecs-hostctl.sh Outdated
Comment thread deployment/aliyun/trading-ecs-hostctl.sh Outdated
Comment thread deployment/aliyun/trading-ecs-hostctl.sh
Comment thread deployment/aliyun/trading-ecs-paper-shadow-policy.jq Outdated
Comment thread deployment/aliyun/trading-ecs-paper-shadow-policy.jq Outdated
Comment thread deployment/aliyun/trading-ecs-runtime.sh
Comment thread deployment/aliyun/trading-ecs-runtime.sh
Comment thread deployment/aliyun/trading-ecs-runtime.sh
@proerror77
proerror77 force-pushed the codex/trading-ecs-host-contract branch 3 times, most recently from 5062296 to 72367f9 Compare July 16, 2026 00:27

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

🤖 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/trading-ecs-hostctl.sh`:
- Around line 239-247: Update the archive validation before the tar extraction
in the control-artifact flow to verify that each expected
member—hft-trading-ecs.service, trading-ecs-hostctl.sh,
trading-ecs-paper-shadow-policy.jq, and trading-ecs-runtime.sh—is a regular
file, rejecting FIFOs, devices, symlinks, and other non-regular entries before
tar runs. Preserve the existing exact-name comparison and subsequent checksum
validation.
- Around line 111-120: Update assert_service_boot_disabled_before_stage so the
not-found|'' branch immediately returns failure when systemctl is-enabled
produces empty output with a nonzero status; only perform the unit-path absence
check for a genuine not-found result with the expected status.
- Around line 346-349: Update the orphan-container guard around docker container
inspection to fail closed on Docker daemon/API errors. Reuse the exact-name
`docker container ls --all` fallback and health-check behavior from
`container_state()`, continuing only when Docker is healthy and no
`monday-hft-trading` container exists; otherwise invoke `die`.
🪄 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

Run ID: 9157f5c2-6f20-43bb-bd37-c59e3e46282c

📥 Commits

Reviewing files that changed from the base of the PR and between ec5db8c and 5062296.

📒 Files selected for processing (10)
  • .github/workflows/acr-publish.yml
  • .github/workflows/ci.yml
  • deployment/aliyun/README.md
  • deployment/aliyun/TRADING_ECS_HOST.md
  • deployment/aliyun/hft-trading-ecs.service
  • deployment/aliyun/test-trading-ecs-host-contract.sh
  • deployment/aliyun/trading-ecs-hostctl.sh
  • deployment/aliyun/trading-ecs-paper-shadow-policy.jq
  • deployment/aliyun/trading-ecs-runtime.sh
  • rust_hft/deployment/PRODUCTION_DEPLOYMENT.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • .github/workflows/ci.yml
  • rust_hft/deployment/PRODUCTION_DEPLOYMENT.md
  • deployment/aliyun/README.md
  • deployment/aliyun/hft-trading-ecs.service
  • deployment/aliyun/trading-ecs-paper-shadow-policy.jq
  • deployment/aliyun/TRADING_ECS_HOST.md

Comment thread deployment/aliyun/trading-ecs-hostctl.sh
Comment thread deployment/aliyun/trading-ecs-hostctl.sh
Comment thread deployment/aliyun/trading-ecs-hostctl.sh Outdated
@proerror77
proerror77 force-pushed the codex/trading-ecs-host-contract branch from 72367f9 to 0bf3a32 Compare July 16, 2026 00:41
@proerror77
proerror77 merged commit f6ded79 into main Jul 16, 2026
28 of 33 checks passed
@proerror77
proerror77 deleted the codex/trading-ecs-host-contract branch July 16, 2026 08:19
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.

2 participants