fix(backtest,multi-vm): handle MT5 relaunch, per-VM healthchecks, orphan sweep - #12
Open
Marinski wants to merge 1 commit into
Open
fix(backtest,multi-vm): handle MT5 relaunch, per-VM healthchecks, orphan sweep#12Marinski wants to merge 1 commit into
Marinski wants to merge 1 commit into
Conversation
…han sweep Five production bug fixes found while investigating why backtests reported as failed on terminals that had in fact run them, and why the container healthcheck was permanently red and hiding real outages. Backtest reliability - MT5 relaunches itself to apply a LiveUpdate: the launcher process exits 0 before the replacement terminal writes its report, so the job was failed as "Report not generated" while a valid report landed minutes later. Wait for the replacement process and its run, bounded by the existing job timeout; a run long enough to be a real backtest is not an update restart and still fails immediately. - INI values are treated as literals (RawConfigParser) on both read and write. ConfigParser interpolation rejected bare '%' characters in symbols, report names and percentage inputs, surfacing as a spurious 400. Multi-VM healthchecks - check_health.py probed every port in config.yaml, so on a multi-VM install each VM reported the other VM's terminals DOWN and the container sat permanently unhealthy, making a genuine failure indistinguishable from standing noise. Apply the same per-VM group filter the launcher uses, with a fallback to no-filter if the import fails. - healthcheck.sh had the same bug: it grepped every port in config.yaml. Filter by the per-VM group file already bind-mounted by docker-compose, using awk (no python in the alpine container). No group file means no filter, preserving single-VM behaviour. Startup performance - sweep_orphans() parsed every *.json in the shared backtest-jobs dir at startup (19k+ files, ~2.5 min per process, many processes at boot) just to mark in-flight jobs failed. Inspect only state files touched within BACKTEST_SWEEP_LOOKBACK using scandir; add prune_old_jobs() to retire completed/failed jobs older than BACKTEST_JOB_RETENTION, gated by a shared marker so only one process scans per interval, in a background daemon thread so boot never blocks. Atomic tmp+rename writes prevent concurrent sweepers from seeing truncated files. Tests updated to cover relaunch handling, INI literals, per-VM healthcheck filtering and job sweep/prune; unit suite passes.
Marinski
force-pushed
the
fix/upstream-backtest-health-fixes
branch
from
August 5, 2026 08:21
2290ead to
5754311
Compare
Marinski
marked this pull request as ready for review
August 5, 2026 10:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five bug fixes that surfaced while running backtests on a multi-terminal deployment: backtests on terminals that had in fact run them were being reported as failed, and the container healthcheck was permanently red, masking a genuine outage.
What and why
Backtest reliability
%characters in symbols, report names and percentage inputs, causing a spurious 400 on submission.RawConfigParseris now used on both the read and write sides, matching how MT5 treats these values.Multi-VM healthchecks
check_health.pyprobed every port inconfig.yaml. On a multi-VM install each VM reported the other VM's terminals DOWN and the container sat permanently unhealthy, making a genuine failure indistinguishable from standing noise (observed: a 25,000+ failing streak while all local terminals were serving). It now applies the same per-VM group filter the launcher uses, with a fallback to no-filter if the import fails.healthcheck.shhad the same bug — it grepped everyport:inconfig.yaml. It now filters by the per-VM group file docker-compose already bind-mounts, using awk since the container image has no python. No group file means no filter, preserving single-VM behaviour.Startup performance
sweep_orphans()parsed every job file at boot. On a large shared backtest-jobs dir this took ~2.5 minutes per process, multiplied by the number of processes starting at boot — all to mark in-flight jobs failed. It now inspects only state files touched withinBACKTEST_SWEEP_LOOKBACK, and a newprune_old_jobs()retires completed/failed jobs older thanBACKTEST_JOB_RETENTION, gated by a shared marker so only one process scans per interval. Both run in a background daemon thread so boot never blocks, and writes are atomic (tmp+rename) so concurrent sweepers never see truncated files.Testing