Skip to content

Persist Firstrade strategy run state#16

Merged
Pigbibi merged 1 commit into
mainfrom
codex/firstrade-mega-persistence
May 24, 2026
Merged

Persist Firstrade strategy run state#16
Pigbibi merged 1 commit into
mainfrom
codex/firstrade-mega-persistence

Conversation

@Pigbibi

@Pigbibi Pigbibi commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • persist Firstrade strategy run plans and completed order results to GCS when enabled
  • block duplicate live submissions for the same account, strategy, and monthly period
  • add FIRSTRADE_PERSIST_STRATEGY_RUNS env wiring and tests

Tests

  • .venv/bin/python -m pytest -q

@Pigbibi Pigbibi merged commit 1fb9d9e into main May 24, 2026
1 check passed
@Pigbibi Pigbibi deleted the codex/firstrade-mega-persistence branch May 24, 2026 08:21

@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: 2a88d121f0

ℹ️ 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 +331 to +333
except Exception as exc:
result["strategy_run_persisted"] = False
result["strategy_run_persistence_error"] = f"{type(exc).__name__}: {exc}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fail run when terminal strategy state cannot be persisted

The duplicate-run guard depends entirely on reading a terminal persisted stage (is_duplicate_live_run), but this except swallows persistence failures after execution. In a live cycle where orders were submitted, a transient GCS write failure here leaves the latest state as ORDERS_PLANNED (or missing), so the next invocation for the same month will not trip idempotency and can submit the same orders again. For live trading, returning success after failing to persist the terminal state breaks the duplicate-submission protection this change is adding.

Useful? React with 👍 / 👎.

result["strategy_run_persistence_error"] = strategy_run_persistence_error
if persist_strategy_runs:
completed_state = build_strategy_run_state(
stage="DRY_RUN_COMPLETED" if settings.dry_run_only else "SUBMITTED",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Don't mark no-op live cycles as SUBMITTED

This sets stage to SUBMITTED for every non-dry-run cycle, even when execution_result.action_done is false and no orders were actually submitted. Because duplicate detection treats SUBMITTED as terminal, a no-op live run (for example, all deltas below threshold) will block later runs in the same month that might legitimately need to submit orders after portfolio/market changes. The persisted stage should reflect whether a submission actually occurred.

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