Skip to content

Ship credentialed Binance fee snapshot timers - #793

Merged
proerror77 merged 29 commits into
mainfrom
codex/binance-fee-systemd
Aug 10, 2026
Merged

proerror77 merged 29 commits into
mainfrom
codex/binance-fee-systemd

Conversation

@proerror77

@proerror77 proerror77 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Change contract

Publish fail-closed systemd oneshots/timers for Binance Spot and USD-M BTCUSDT fee snapshots plus the verified OSS uploader. The producer now accepts the account bundle only through an absolute credential file, allowing systemd LoadCredential= to keep API secrets out of ordinary environment files.

Issue relationship

Closes #792

Out of scope

Credential provisioning or disclosure, live unit installation/enablement, PM Reference, LOB collectors, evaluator/materializer behavior, and all order creation.

Dependencies and merge order

PR #791 merged into f9cd212e3d6c63c5978bbeb5a0a6eb6d7d6282ff and is integrated in this branch.

Focused validation

  • deployment/aliyun/test-binance-fee-release-contract.sh
  • shellcheck deployment/aliyun/test-binance-fee-release-contract.sh
  • Linux target compiled all binance-fee-snapshot tests with --no-run; native macOS execution remains blocked by the pre-existing libc::RUSAGE_THREAD issue in polymarket_upload.rs.
  • systemd-analyze verify passed for all six service/timer assets in Ubuntu 24.04.
  • Counterexample: a missing credential file fails before any HTTP request; no service embeds a secret-bearing environment entry.

Rollout and rollback

Merge publishes disabled assets only. A separate runtime issue will pin exact release and rollback identities and requires OSS data/manifest/_SUCCESS readback before success.

Scope exception

None.

Summary by CodeRabbit

  • New Features
    • Added automated Binance Spot and USD-M fee snapshots on a recurring schedule.
    • Added scheduled uploads of verified fee snapshots to cloud storage.
    • Added deployment configuration for fee data storage and secure credential handling.
  • Bug Fixes
    • Upload failures now retain cumulative failure counts and recover cleanly after successful runs.
  • Monitoring
    • Health checks now report snapshot and upload failures, invalid status data, and missing services.
  • Tests
    • Added release and health checks to validate the complete fee collection and upload workflow.

@proerror77
proerror77 enabled auto-merge (squash) August 9, 2026 23:07
@proerror77

Copy link
Copy Markdown
Owner Author

Exact-head review requested for 6b1441d. Please verify systemd credential isolation, 60-second freshness cadence, fail-closed missing-credential behavior, fixed OSS destination, and that merge alone cannot enable production units.

@coderabbitai

coderabbitai Bot commented Aug 9, 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: 3 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: 910dc2b2-3435-4c5e-8bc3-473e65d1fa45

📥 Commits

Reviewing files that changed from the base of the PR and between a591743 and 1e65e68.

📒 Files selected for processing (3)
  • deployment/aliyun/monday-collector-health.sh
  • deployment/aliyun/test-binance-fee-release-contract.sh
  • deployment/aliyun/test-monday-collector-health.sh
📝 Walkthrough

Walkthrough

The PR adds credentialed Binance Spot and USD-M fee snapshot services, periodic OSS uploads, persistent upload failure tracking, collector health checks, release-contract tests, and deterministic ACR release metadata.

Changes

Binance fee release

Layer / File(s) Summary
Credentialed snapshot producers
rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs, deployment/aliyun/binance-fee-snapshot-*, deployment/aliyun/binance-fee.conf
The snapshot binary reads credentials from an absolute file path. Spot and USD-M systemd services use credential loading and persistent timers.
OSS upload and failure state
deployment/aliyun/binance-fee-upload.*, rust_hft/tools/collector/src/binance_fee_upload.rs
The uploader archives the fee spool to OSS and persists discovery and batch failure counts.
Health monitoring and validation
deployment/aliyun/monday-collector-health.sh, deployment/aliyun/test-monday-collector-health.sh
Health checks validate fee units, upload status, failure counts, and recent snapshot journal failures. Contract tests cover missing, malformed, and failing states.
Release packaging and gates
.github/workflows/acr-publish.yml, .github/workflows/ci.yml, deployment/aliyun/test-binance-fee-release-contract.sh, agent-worktree.yml
The workflows package deterministic fee assets, generate checksums and release metadata, and run the release contract test in publish and CI paths.

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

Sequence Diagram(s)

sequenceDiagram
  participant SnapshotTimer as Snapshot timers
  participant Snapshot as binance-fee-snapshot
  participant Spool as Binance fee spool
  participant Upload as binance-fee-upload
  participant OSS as Alibaba Cloud OSS
  participant Health as monday-collector-health.sh
  SnapshotTimer->>Snapshot: Run Spot and USD-M snapshots
  Snapshot->>Spool: Write fee artifacts
  Upload->>Spool: Discover pending artifacts
  Upload->>OSS: Upload verified artifacts
  Health->>SnapshotTimer: Check timer and service state
  Health->>Upload: Check upload status
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% 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 identifies the main change: credentialed Binance fee snapshot timers.
Description check ✅ Passed The description includes every required template section with specific scope, validation, dependency, rollout, and rollback details.
Linked Issues check ✅ Passed The changes satisfy issue #792 through credentialed Spot and USD-M services, timers, uploader assets, release validation, and disabled production units.
Out of Scope Changes check ✅ Passed The workflow, health monitoring, release checks, and failure tracking changes support the linked deployment and release-safety objectives.
✨ 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/binance-fee-systemd

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

Copy link
Copy Markdown
Owner Author

Exact-head review requested for 811927b. In addition to the credentialed units, the ACR release now publishes a digest-bound fee release receipt covering both binaries, the control manifest, and the deterministic control archive. Please review this exact head.

Comment thread rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs Fixed
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 811927b. Focus on systemd credential isolation, fail-closed defaults, immutable release asset binding, and no enablement on merge.

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 4b07d29. The security finding is fixed with tempfile::tempdir; please review the complete credentialed release contract at this exact head.

@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: 4b07d29253

ℹ️ 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 agent-worktree.yml
Comment thread deployment/aliyun/binance-fee-upload.service Outdated
Comment thread deployment/aliyun/binance-fee-snapshot-spot.service
Comment thread deployment/aliyun/binance-fee-upload.timer
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 0e7f33d. Ownership now includes the release workflow; the uploader has no service-wide deadline; the bundle includes a tmpfiles spool rule; and collector health now verifies all fee timers/services plus mandatory upload-status readback (55 focused cases pass).

@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: 0e7f33d333

ℹ️ 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/monday-collector-health.sh
Comment thread deployment/aliyun/monday-collector-health.sh
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 5364eb6 after integrating current main. Confirm the credentialed fee services, fixed OSS destination, release identity, unbounded uploader drain, tmpfiles spool ownership, and health readbacks remain fail-closed.

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head a81505f. New fixes make malformed upload-status a health breach and persist cumulative fee upload failure_count across later successful runs; focused health suite is 57/57 and release contract passes.

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

ℹ️ 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/monday-collector-health.sh
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head after the initial failure-count fix. A fresh fee lane now breaches on nonzero failure_count even before its first monitor baseline; the focused health suite is 59/59.

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

ℹ️ 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/monday-collector-health.sh
Comment thread .github/workflows/ci.yml
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head a591743. The exact-source ACR collector lane now runs the fee release contract before publication, and collector health detects any snapshot systemd failure in the complete 10-minute interval. Focused contracts: release PASS; health 61/61; worktree preflight PASS.

@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/monday-collector-health.sh`:
- Around line 306-318: Update the upload-status validation jq filter in the
health-check flow to require a present, non-null failure_count before validating
that it is a non-negative integer; remove the // 0 fallback from validation and
extraction so missing values trigger record_breach. Add a fixture omitting
failure_count and assert that it produces a breach.

In `@deployment/aliyun/test-binance-fee-release-contract.sh`:
- Around line 16-27: Strengthen the credential-isolation assertions in the test
by rejecting producer implementations that accept relative account-secret paths,
rather than only checking for the PathBuf field. Update the service environment
scan to detect credential-bearing entries case-insensitively, including
uppercase names such as BINANCE_API_KEY, while preserving the existing service
credential and path checks.
- Around line 32-35: Update the timer assertions in the loop over spot_timer and
usdm_timer to also require the exact setting AccuracySec=1s, alongside the
existing OnUnitActiveSec and Persistent checks.
🪄 Autofix

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: db6cf07e-e48f-4dff-9675-d624f3825a8a

📥 Commits

Reviewing files that changed from the base of the PR and between bd402f4 and a591743.

📒 Files selected for processing (16)
  • .github/workflows/acr-publish.yml
  • .github/workflows/ci.yml
  • agent-worktree.yml
  • deployment/aliyun/binance-fee-snapshot-spot.service
  • deployment/aliyun/binance-fee-snapshot-spot.timer
  • deployment/aliyun/binance-fee-snapshot-usdm.service
  • deployment/aliyun/binance-fee-snapshot-usdm.timer
  • deployment/aliyun/binance-fee-upload.env
  • deployment/aliyun/binance-fee-upload.service
  • deployment/aliyun/binance-fee-upload.timer
  • deployment/aliyun/binance-fee.conf
  • deployment/aliyun/monday-collector-health.sh
  • deployment/aliyun/test-binance-fee-release-contract.sh
  • deployment/aliyun/test-monday-collector-health.sh
  • rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs
  • rust_hft/tools/collector/src/binance_fee_upload.rs

Comment thread deployment/aliyun/monday-collector-health.sh Outdated
Comment thread deployment/aliyun/test-binance-fee-release-contract.sh
Comment thread deployment/aliyun/test-binance-fee-release-contract.sh
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a591743e99

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

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 3970ba3. Missing failure_count now breaches, credential isolation locks absolute secret paths and case-insensitive environment names, and both snapshot timers are contract-bound to AccuracySec=1s. Focused health 63/63; release contract PASS.

@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: 3970ba38ce

ℹ️ 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/monday-collector-health.sh
@proerror77

Copy link
Copy Markdown
Owner Author

Fixed at exact head 1e65e68: mandatory failure_count is now scoped to binance-fee-upload; existing uploaders preserve the prior optional-counter contract. Added a focused USD-M Reference status-without-counter regression test. Local evidence: collector health 64 passed / 0 failed; fee release contract passed; bash syntax and diff checks passed. Please review exact head 1e65e68.

@proerror77
proerror77 merged commit d55dd82 into main Aug 10, 2026
45 checks passed
@proerror77
proerror77 deleted the codex/binance-fee-systemd branch August 10, 2026 02:40
proerror77 pushed a commit that referenced this pull request Aug 10, 2026
Materialize verified Binance Spot/USD-M market tapes into the V3 outer
materialization carrying CexReplaySnapshotV2: PIT instrument rules,
account-bound maker/taker fees, independent funding and OI timelines,
aggregate-trade flow, and signed runtime lifecycle latency evidence.

Rebased onto origin/main be9e746, which already contains the signed
arrival-cost evidence (#787), its verification (#788), fee-account
binding (#789), and fee snapshot timers (#793). Refs #794.
proerror77 added a commit that referenced this pull request Aug 10, 2026
* feat(research): publish verified CEX ResearchSnapshot V2

Materialize verified Binance Spot/USD-M market tapes into the V3 outer
materialization carrying CexReplaySnapshotV2: PIT instrument rules,
account-bound maker/taker fees, independent funding and OI timelines,
aggregate-trade flow, and signed runtime lifecycle latency evidence.

Rebased onto origin/main be9e746, which already contains the signed
arrival-cost evidence (#787), its verification (#788), fee-account
binding (#789), and fee snapshot timers (#793). Refs #794.

* fix(research): close lob-pit-materializer review threads

- Delegate runtime latency verification to the hardened
  alpha_domain::runtime_latency_evidence verifier instead of a drifted
  collector-local copy: event IDs are deduplicated before filtering
  (conflicting duplicates fail closed), every fill must carry an
  authenticated instrument_market_{market} identity, and USD-M fails
  closed until a derivatives execution path exists.
- Republish verified fee and reference evidence triplets into the
  materialization artifact directory under content-addressed names so
  the digests recorded in the snapshot resolve to immutable bytes.
- Restructure the test fixture per market: the happy path is Spot
  (signed LiveSmall latency evidence exists only for Spot), a new test
  proves USD-M materialization fails closed, and the aggregate-trade
  assertions now match the (previous, current] bucket semantics.

* fix(research): anchor latency cohort and holding-interval funding

- Publish the complete digest-anchored runtime feedback log and the
  trusted-key document into the artifact directory under their content
  digests, so independent readers can reverify every signed lifecycle
  event and no resolvable-evidence gap remains for the key document.
- Charge USD-M funding settlements over each row's actual
  (current, future] holding interval, matching how the evaluator
  applies funding_bps to the held position; a settlement that precedes
  the holding interval is no longer charged and multi-bucket horizons
  collect every settlement.

---------

Co-authored-by: Sonic Shih <sonic.shih@mandonothing.com>
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.

Ship systemd-credentialed Binance fee snapshot services

2 participants