Skip to content

feat: bind CEX fee evidence to runtime account - #789

Merged
proerror77 merged 10 commits into
mainfrom
codex/fee-account-binding
Aug 9, 2026
Merged

proerror77 merged 10 commits into
mainfrom
codex/fee-account-binding

Conversation

@proerror77

@proerror77 proerror77 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Change contract

Bind authenticated Binance fee evidence and realized latency evidence to the same validated logical runtime account ID, so a caller cannot join a fee credential fingerprint to an unrelated signed account stream.

Issue relationship

Refs #779

Out of scope

Credential provisioning, order placement, runtime activation, materialization, and production cutover.

Dependencies and merge order

None. The materializer PR consumes this contract after merge.

Focused validation

  • cargo test -p hft-research-manifest --locked (22 passed)
  • Targeted rustfmt and git diff --check pass
  • Collector test compile is blocked only by the existing macOS libc::RUSAGE_THREAD incompatibility; Linux CI is authoritative
  • Counterexample: a latency artifact with a different runtime account ID is rejected

Rollout and rollback

No runtime mutation. Fee schema advances to v2 before any production fee artifacts exist; rollback is this PR revert.

Scope exception

None.

Summary by CodeRabbit

  • New Features

    • Added runtime account identification to fee schedules, latency evidence, and Binance fee snapshots.
    • Upgraded Binance fee snapshot support to schema version 2.
    • Added validation to ensure account IDs are present, valid, and consistent across related data.
  • Bug Fixes

    • Prevented publication and verification of fee data with missing, invalid, or mismatched runtime account IDs.

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 6e24719: verify fee artifact/runtime logical-account binding and v2 schema validation.

@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: 57 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: e37c24f9-aea0-40b0-ade5-46d8e3620b5b

📥 Commits

Reviewing files that changed from the base of the PR and between 80c27b2 and 157358e.

📒 Files selected for processing (8)
  • agent-worktree.yml
  • deployment/aliyun/TRADING_ECS_HOST.md
  • deployment/aliyun/test-trading-ecs-host-contract.sh
  • deployment/aliyun/trading-ecs-runtime.sh
  • rust_hft/alpha-harness/app/src/mission_runner.rs
  • rust_hft/deployment/docker/Dockerfile.trading
  • rust_hft/research-core/manifest/src/lib.rs
  • rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs
📝 Walkthrough

Walkthrough

The change binds CEX fee schedules, latency evidence, Binance fee snapshots, and published manifests to a validated runtime account ID. Binance artifacts use schema v2, and artifact verification checks account identity consistency.

Changes

CEX fee runtime account binding

Layer / File(s) Summary
Manifest runtime account validation
rust_hft/research-core/manifest/src/lib.rs
CEX fee schedules and latency-cost evidence now include runtime account IDs. Validation rejects empty IDs and mismatched latency evidence. Tests cover the new fields and mismatch case.
Binance artifact schema and verification
rust_hft/tools/collector/src/binance_fee_artifact.rs
Binance snapshots and manifests now use schema v2 and carry validated runtime account IDs. Artifact verification requires the manifest and snapshot IDs to match.
Collector runtime account integration
rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs, agent-worktree.yml
The collector reads and validates HFT_SECRET_BINANCE_RUNTIME_ACCOUNT_ID before publishing it in the snapshot. Worktree metadata targets the runtime account-binding changes.

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

Sequence Diagram(s)

sequenceDiagram
  participant BinanceFeeSnapshotCollector
  participant BinanceFeeSnapshot
  participant FeeManifest
  participant ArtifactVerification
  BinanceFeeSnapshotCollector->>BinanceFeeSnapshot: Validate and record runtime account ID
  BinanceFeeSnapshotCollector->>FeeManifest: Publish schema v2 with runtime account ID
  FeeManifest->>ArtifactVerification: Verify schema and matching account ID
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description covers all required sections and clearly states the change, scope, validation, dependency context, and rollback plan.
Title check ✅ Passed The title clearly and concisely describes binding CEX fee evidence to a runtime account.
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/fee-account-binding

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: 6e24719e39

ℹ️ 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 rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs Outdated
Comment thread rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs Outdated
Comment thread rust_hft/tools/collector/src/binance_fee_artifact.rs Outdated
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 80c27b2: account identity now comes from the protected Binance secret scope, not a CLI label; validation matches runtime nonblank IDs including desk/main.

@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 `@rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs`:
- Around line 61-64: Update the binance-fee-snapshot credential-loading flow
around runtime_account_id and the Binance API key/secret reads to verify that
all credentials belong to the same Binance runtime-account scope before
publishing the fee snapshot. Reject mismatched or independently supplied
credentials, while preserving valid matching configurations and the existing
invalid-account error behavior.
🪄 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: 4c6ea785-2e0c-4612-bc27-e53a2404053f

📥 Commits

Reviewing files that changed from the base of the PR and between 02968ad and 80c27b2.

📒 Files selected for processing (4)
  • agent-worktree.yml
  • rust_hft/research-core/manifest/src/lib.rs
  • rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs
  • rust_hft/tools/collector/src/binance_fee_artifact.rs

Comment thread rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs Outdated

@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: 80c27b29c8

ℹ️ 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 rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs Outdated
Comment thread rust_hft/tools/collector/src/binance_fee_artifact.rs
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 507085b: verify atomic HFT_SECRET_BINANCE_ACCOUNT_JSON binds runtime_account_id, api_key, and secret as one protected scope.

@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: 507085bb46

ℹ️ 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 rust_hft/tools/collector/src/bin/binance-fee-snapshot.rs
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 790ecfa: verify protected runtime.env admits the atomic Binance account JSON, validates exact fields, and requires its API key/secret to equal the runtime credential pair.

The suggested V1 decoder is intentionally not added: production readback found no fee artifacts and the fee binary has never been deployed, so there is no immutable V1 evidence to preserve; publication moves directly to V2.

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 14cb946: verify atomic Binance account JSON is the sole stored Binance credential source, validator remains generic for other venues, and the container derives legacy process vars with runtime jq.

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 6027bde: final atomic-account scope plus tracked-secret-safe host fixture; both host contract and repository secret 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: 6027bde981

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

Copy link
Copy Markdown
Owner Author

@codex review exact head 3a7b640 after evaluator V2 merge: verify atomic authenticated account binding, runtime account consistency, and protected host contract.

@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 31cee2f: verify authenticated Binance bundle account now must equal immutable activation policy account, plus prior atomic-secret and V2 manifest bindings.

@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: 31cee2fda8

ℹ️ 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 Outdated
Comment thread rust_hft/research-core/manifest/src/lib.rs
Comment thread deployment/aliyun/trading-ecs-runtime.sh Outdated
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 37ff487: verify final account-bound manifest/runtime/fixture contract after Linux Rust Workspace compile fix.

@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: 37ff4872a3

ℹ️ 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 rust_hft/research-core/manifest/src/lib.rs
@proerror77

Copy link
Copy Markdown
Owner Author

@codex review exact head 157358e: verify Binance-only policy scoping, mandatory atomic bundle for Binance, and launch-time account recheck. The nested fee/latency artifact readback is implemented in dependent materializer PR #786 before V2 admission.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 157358e75b

ℹ️ 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
proerror77 enabled auto-merge (squash) August 9, 2026 22:39
@proerror77
proerror77 merged commit 4e8358f into main Aug 9, 2026
50 checks passed
@proerror77
proerror77 deleted the codex/fee-account-binding branch August 9, 2026 22:43
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.

1 participant