Skip to content

Fix Firstrade buying-power sizing and dry-run isolation - #235

Merged
Pigbibi merged 1 commit into
mainfrom
codex/fix-dryrun-state-monitors-20260728
Jul 29, 2026
Merged

Fix Firstrade buying-power sizing and dry-run isolation#235
Pigbibi merged 1 commit into
mainfrom
codex/fix-dryrun-state-monitors-20260728

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Why

  • Firstrade rejected an order estimate because the requested amount consumed the reported buying power with no operational reserve for unsettled funds and price movement.
  • Dry-run execution could still mutate durable strategy state.
  • Runtime reconciliation and monitor handling needed to distinguish safe validation from live execution.

What changed

  • Apply the configured reserved-cash ratio when sizing executable orders and expose it through the deployment sync contract.
  • Prevent dry-run routes from persisting live strategy state.
  • Harden runtime target reconciliation, monitor preservation, and broker adapter error handling.
  • Add regression coverage for buying-power reservation, dry-run isolation, Cloud Run routes, and workflow reconciliation.

Verification

  • pytest: 202 passed.
  • ruff check: passed for all changed Python files.
  • actionlint: passed for the changed workflow.
  • git diff --check: passed.
  • Codex review (not AIAudit): no actionable findings.

Production safety

  • A 1% cash reserve is already configured on the live service as a mitigation.
  • No Firstrade dry-run or live order endpoint was invoked after applying the mitigation.

Co-Authored-By: Codex <noreply@openai.com>
@Pigbibi
Pigbibi marked this pull request as ready for review July 29, 2026 02:42
@Pigbibi
Pigbibi merged commit acd3bd0 into main Jul 29, 2026
1 of 2 checks passed
@Pigbibi
Pigbibi deleted the codex/fix-dryrun-state-monitors-20260728 branch July 29, 2026 02:43

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

ℹ️ 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 on lines +309 to +311
has_single_sync_target = not str(env.get("SYNC_PLAN_JSON", "") or "").strip() or (
isinstance(targets, list) and len(targets) == 1
)

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 Avoid retaining the dispatcher beside direct monitor jobs

When SYNC_PLAN_JSON contains multiple targets and DIRECT_MONITOR_MIGRATION_COMPLETE=true, the scheduler step still creates and resumes the selected service's direct probe and precheck jobs, but this single-target condition forces direct_jobs_exist to remain false and preserves the global dispatcher. Because the preceding environment sync configures MONITOR_DISPATCH_TARGETS_JSON with that same selected service, the dispatcher continues invoking its due monitors alongside the direct jobs, causing duplicate dry-run previews, session checks, and failure notifications. Either remove migrated targets from the dispatcher configuration or retire the dispatcher after all represented targets have direct jobs.

Useful? React with 👍 / 👎.

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