Skip to content

fix(runtime): allow two-minute sandbox requests and preserve failures - #391

Merged
brokermr810 merged 62 commits into
mainfrom
test
Nov 19, 2026
Merged

brokermr810 merged 62 commits into
mainfrom
test

Conversation

@brokermr810

Copy link
Copy Markdown
Collaborator

Summary

Fix premature live-strategy sandbox timeouts and preserve the original failure when a callback process terminates.

Root cause

The former five-second callback setting covered a complete isolated request, including frame decoding, runtime preparation, and all callbacks. Large portfolios could exceed this budget. After terminating the child, the runtime retried the dead session and obscured the original timeout with strategy sandbox is not running. Shorter outer waits could also preempt a larger sandbox budget.

Changes

  • Default live sandbox requests to 120 seconds via STRATEGY_RUNTIME_SANDBOX_TIMEOUT_SECONDS, bounded to 2–300 seconds. Ignore the retired STRATEGY_SCRIPT_CALLBACK_TIMEOUT_SEC setting.
  • Allow distributed startup and evaluation waits at least the sandbox budget plus 30 seconds; retain longer caller deadlines.
  • Preserve terminal failure causes and stop without retrying a dead process or replaying partially completed callbacks.
  • Keep existing retry behavior for nonterminal errors and preserve kernel isolation and credential restrictions.
  • Update the English and Chinese strategy-development and security guides.

Verification

  • 74 focused tests passed in a network-disabled Linux Docker container.
  • Covered a 96-instrument, 500-bar portfolio with a callback exceeding five seconds, subsequent requests, enforced timeouts, failure retention, and distributed wait budgets.
  • Changed-file Ruff checks, documentation checks, backend quality checks, and git diff --check passed.
  • DCO trailers verified for the PR's non-merge commits.

Deployment and remaining limits

Rebuild/pull the backend image and restart affected runtime workers. No database migration, API schema change, or frontend update is required. Previously stopped strategies are not restarted automatically; restart deliberately after normal state and position reconciliation.

Market-data fetching remains in the trusted host before the sandbox request. The 120-second limit is finite; production workloads were not replayed, and unrelated broker-authentication or market-data issues are outside this change. The complete Compose stack and live exchange order submission were not exercised.

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

# Conflicts:
#	backend_api_python/app/routes/community.py
aliassar and others added 27 commits November 11, 2026 13:00
#362 normalized the Binance protection orders, but Bitget (UTA and
classic) and Bybit still sent percentage-derived prices with str(), e.g.
stopLoss=77951.14749999999 for a 2.5% stop on a 76049.9 short. Those are
off the contract tick, so the venue rejects the protection order.

Run the stop-loss, take-profit and trailing activation prices (and the
Bybit trailingStop distance) through each client's _normalize_price, the
same way #362 does for Binance, and raise when the result falls below the
minimum.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aliassar <[email protected]>
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
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.78378% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...end_api_python/app/services/strategy_v2/sandbox.py 84.37% 4 Missing and 1 partial ⚠️
...ackend_api_python/app/services/trading_executor.py 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@brokermr810
brokermr810 merged commit 3e1fbba into main Nov 19, 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