Skip to content

fix(backtest,multi-vm): handle MT5 relaunch, per-VM healthchecks, orphan sweep - #12

Open
Marinski wants to merge 1 commit into
psyb0t:masterfrom
Marinski:fix/upstream-backtest-health-fixes
Open

fix(backtest,multi-vm): handle MT5 relaunch, per-VM healthchecks, orphan sweep#12
Marinski wants to merge 1 commit into
psyb0t:masterfrom
Marinski:fix/upstream-backtest-health-fixes

Conversation

@Marinski

@Marinski Marinski commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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

  • MT5 self-relaunch on update. When a LiveUpdate is pending, the launched terminal process exits 0 within seconds and MT5 relaunches itself to run the real test. The job was failed as "Report not generated" even though a valid report was written minutes later. The runner now waits 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 treated as literals. ConfigParser interpolation rejected bare % characters in symbols, report names and percentage inputs, causing a spurious 400 on submission. RawConfigParser is now used on both the read and write sides, matching how MT5 treats these values.

Multi-VM healthchecks

  • check_health.py probed every port in config.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.sh had the same bug — it grepped every port: in config.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 within BACKTEST_SWEEP_LOOKBACK, and a new prune_old_jobs() retires completed/failed jobs older than BACKTEST_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

  • Unit suite updated to cover relaunch handling, INI literals, per-VM healthcheck filtering, and job sweep/prune. 241 tests pass.
  • Lint clean.

…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
Marinski force-pushed the fix/upstream-backtest-health-fixes branch from 2290ead to 5754311 Compare August 5, 2026 08:21
@Marinski Marinski changed the title fix(backtest/multi-vm): survive MT5 relaunch, healthcheck per-VM, orphan sweep fix(backtest,multi-vm): handle MT5 relaunch, per-VM healthchecks, orphan sweep Aug 5, 2026
@Marinski
Marinski marked this pull request as ready for review August 5, 2026 10:42
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