Skip to content

fix(runtime): confirm distributed startup and retire stale generations - #401

Merged
brokermr810 merged 83 commits into
mainfrom
test
Nov 22, 2026
Merged

brokermr810 merged 83 commits into
mainfrom
test

Conversation

@brokermr810

Copy link
Copy Markdown
Collaborator

Root cause

Distributed start commands reported success after registering bar subscriptions, before an evaluator prepared the requested runtime. Daily strategies could wait for the next candle while stale run/health records remained visible.

Changes

  • Prepare runtimes independently of candle closure using a versioned event on the existing evaluation topic/shard.
  • Complete starts only after persisted run/epoch/live-lease readiness acknowledgement. Bound readiness polling without consuming failed execution attempts.
  • Reconcile obsolete generations, make restarts idempotent, serialize same-strategy commands, and ignore delayed commands from earlier generations.
  • Fence lease-loss cleanup and state writes so old runtimes cannot overwrite or stop replacements; keep ownership until the old runtime stops.
  • Preparation does not invoke trading signal callbacks. Preserve closed-bar execution and ongoing position protection/risk monitoring.
  • Add PostgreSQL integration coverage to CI and update both deployment guides.

Verification

  • 255 Linux regression tests passed, including real sandbox, runtime lifecycle, scheduler, evaluator, commands, recovery and process roles.
  • 8 isolated PostgreSQL integration tests passed, including desired epoch 6 vs actual epoch 1 and 20 rounds of concurrent command claims.
  • Ruff, structural quality, documentation, whitespace and DCO checks passed. No quality-baseline relaxation.
  • Latest main was synchronized without changes to the tested code tree.

Deployment / migration

Update trading-worker, strategy-dispatcher-worker and strategy-evaluator-worker together. Updating only the API or one worker is insufficient. No new database table, migration or Kafka topic is required. Dispatcher reconciliation recovers subscribed running strategies with stale/missing readiness; do not manually edit epochs.

Remaining risk / scope

Verify matching desired/actual epochs, active leases and readiness acknowledgements after deployment. Testing used isolated local Linux/PostgreSQL resources; production services, strategies and orders were not changed. This PR is not merged or deployed.

tianhe added 30 commits November 1, 2026 17:17
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/routes/community.py
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/tests/test_safe_exec.py
#	backend_api_python/tests/test_strategy_runtime_process_isolation.py
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/professional_report/features/equity.py
#	backend_api_python/app/research/workflows.py
#	backend_api_python/tests/test_professional_report_builder.py
…emails

Persist definitive order failure streaks and portfolio batch outcomes, send deduplicated alerts across opted-in channels, and render transactional emails using localized monochrome templates and configured branding.

Signed-off-by: TIANHE <[email protected]>
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/services/strategy_v2/live_execution.py
#	backend_api_python/app/services/trading_executor.py
#	backend_api_python/tests/test_strategy_v2_order_gateway.py
#	docs/trading/LIVE_TRADING_SAFETY.md
#	docs/trading/LIVE_TRADING_SAFETY_CN.md
Use the canonical strategy_name column for automatic-stop and rebalance notifications, honor explicit stop-and-close requests, and exercise the production schema and notification delivery paths in regression tests.

Signed-off-by: TIANHE <[email protected]>
Keep order sizing aligned with the deployment ledger across restarts. Revalue positions atomically with fills and derive live floating PnL from current quantities so stale residual rows cannot inflate equity. Preserve real small holdings and add cross-path regression coverage.

Signed-off-by: TIANHE <[email protected]>
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	docs/trading/LIVE_TRADING_SAFETY.md
#	docs/trading/LIVE_TRADING_SAFETY_CN.md
@sonarqubecloud

Copy link
Copy Markdown

@brokermr810
brokermr810 merged commit 8b5b871 into main Nov 22, 2026
15 checks passed
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.

3 participants