Files
XianBWandCopilot 7c95268c0c fix(security)!: harden artifact serialization and loading (#2339)
* security: harden artifact serialization and loading

* ci: restore dependency and title lint compatibility

* fix: address artifact test and lint failures

* ci: handle current MLflow and Windows OSQP changes

* ci: use lxml release with cross-platform wheels

* fix: defer optional CVXPY solver imports

* docs: mark notebook model artifacts as trusted

* docs: mark position artifacts as trusted

* style: document intentional lazy import

* ci: skip broken released OSQP on Windows Python 3.8

* fix: mark online model artifacts as trusted

* test: make MLflow client timing check robust

* ci: retry nondeterministic benchmark smoke test

* fix: cap filelock before fork safety regression

* fix: use filelock release compatible with multiprocessing

* fix: preserve artifact loading compatibility after hardening

* fix(security): validate derived artifact paths and extend regressions

* fix(security): preserve extended data artifact round trips

* fix(security): retain legacy NumPy and pandas artifact classes

Allow the exact MaskedArray and SparseDtype module paths emitted by the older dependency versions in CI. Preserve restricted loading and cover both old and new paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(data): avoid unused trading calendar lookup in PIT normalization

PIT normalization uses report dates and calendar-day offsets, so do not request an unused Baostock calendar. Cover annual and quarterly normalization without online calendar access.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(security): require explicit trust in artifact workflows

Expose default-off artifact trust at online, delayed-training and meta-workflow entry points. Keep data loading restricted, preserve legacy default recorder calls and restored workflow defaults, and document migration and trust boundaries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test(workflow): cover complete DDG-DA and HIST artifact flows

Exercise real training, cache and recorder restoration, saved-task replay, signals and portfolio backtests. Fix the cache trust, grouping, relative-path, LightGBM early-stopping and HIST CPU blockers exposed by full execution.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(security)!: unify artifact trust and publish upgrade guidance

Use trusted consistently across public APIs and CLI options. Migrate pre-release saved consent only at serialization boundaries, reject invalid or conflicting settings, and preserve restricted data reads. Add a canonical upgrade guide with README, installation, changelog and runtime-error entry points.

BREAKING CHANGE: executable artifact restoration requires explicit trusted=True. HIST mappings use JSON and high-frequency cache paths must remain within artifact_root. See docs/start/artifact_migration.rst for upgrading existing workflows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(security): remove trial-only trust compatibility

Target upgrades from pre-PR Qlib rather than artifacts generated by intermediate PR revisions. Retain restricted defaults for saved objects without consent, unify current APIs, and remove state/keyword migration branches and documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* ci: avoid failed dataset probes and space download retries

Download the same existing v2 archives used by successful jobs without probing nonexistent package-version assets. Allow five download attempts 60 seconds apart; preserve the full matrix, datasets, noninteractive setup and failure propagation. Cover the exact archives and retry policy in offline CI tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs: add practical artifact migration examples

Show explicit consent for restored online components while preserving the original manager, schema-aware Arrow conversions, timezone-preserving ZoneInfo migration, and restricted round trips into a separate recorder. Explain shared-component scope, staging artifacts and trusted-source prerequisites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(workflow): preserve fresh artifact workflows with scoped trust

Keep immutable cache references intact at open rolling tails. Add explicit per-load record-template consent and per-artifact collector loading options without widening other reads. Restore the original template class after parent-load failures, and support audited business-frequency and NumPy record representations through exact pickle globals.

Document the scoped APIs and cover fresh trained-model reads, cache generation, numerical round trips and refusal paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-08 17:49:08 +08:00
..
2023-05-24 15:49:58 +08:00
2022-01-10 16:52:37 +08:00

Introduction

This is the implementation of DDG-DA based on Meta Controller component provided by Qlib.

Please refer to the paper for more details: DDG-DA: Data Distribution Generation for Predictable Concept Drift Adaptation [arXiv]

Background

In many real-world scenarios, we often deal with streaming data that is sequentially collected over time. Due to the non-stationary nature of the environment, the streaming data distribution may change in unpredictable ways, which is known as concept drift. To handle concept drift, previous methods first detect when/where the concept drift happens and then adapt models to fit the distribution of the latest data. However, there are still many cases that some underlying factors of environment evolution are predictable, making it possible to model the future concept drift trend of the streaming data, while such cases are not fully explored in previous work.

Therefore, we propose a novel method DDG-DA, that can effectively forecast the evolution of data distribution and improve the performance of models. Specifically, we first train a predictor to estimate the future data distribution, then leverage it to generate training samples, and finally train models on the generated data.

Dataset

The data in the paper are private. So we conduct experiments on Qlib's public dataset. Though the dataset is different, the conclusion remains the same. By applying DDG-DA, users can see rising trends at the test phase both in the proxy models' ICs and the performances of the forecasting models.

Run the Code

After verifying that the recorder artifacts and local working files are your own and cannot be replaced by untrusted writers (see below), run from this directory:

    python workflow.py --trusted=True run

The default forecasting models are Linear. Users can choose other forecasting models by changing the forecast_model parameter when DDG-DA initializes. For example, users can try LightGBM forecasting models by running the following command:

    python workflow.py --trusted=True --conf_path=../baseline/workflow_config_lightgbm_Alpha158.yaml run

Recorder artifacts and local working files

workflow.py exposes the DDGDA workflow through the DDGDABench Fire entry point. Its trusted option defaults to False. Set it explicitly only for artifacts and caches from a verified writer in access-controlled MLflow and local storage: unrestricted pickle loading can execute code. Creating a run yourself is not enough if someone else can overwrite its files.

The option covers recorder-backed executable meta-model/task loading, including InternalData.setup, and DDG-DA's local handler/internal-data pickle cache reads; prediction, label and numerical-report artifact loads remain restricted. Lower-level callers can also pass trusted=True to MetaDatasetDS or InternalData.setup for recorder task reads, not as a global local-cache grant. A refused load is not a reason to retry automatically with trust enabled. See the artifact loading migration guide for data compatibility and migration details.

This example also saves and reuses local pickle files in working_dir, which the benchmark sets to this directory. Handler/internal-data caches default to restricted loading, which refuses executable objects such as Alpha158 or InternalData. The explicit opt-in allows these caches to be restored with ordinary pickle and emits a warning; it does not authenticate their contents. Protect working_dir, the configuration directory (also used for handler caching), and any supplied h_path from untrusted writes. Do not copy unknown cached handlers, meta-information or models into them. There is no automatic unsafe retry and no change to the global restricted loader. Other pickle APIs and workflow YAML retain their own trust requirements; only use trusted configurations and files.

Generated tasks keep lightweight handler-cache configuration references, including the path and chosen trusted setting, rather than embedding the full market data. Do not assume task["dataset"]["kwargs"]["handler"] is a file:// string. Treat saved task configurations as executable inputs; reusing an opted-in task also reuses that local-cache consent independently of a new workflow's default. An old exported task may need regeneration with its matching meta-model and configuration to obtain the current cache reference and selected policy. Loading a saved task containing a reweighter through a recorder still requires explicit recorder consent; that flag alone does not globally authorize local cache reads.

The Makefile's clean target deletes local pickle files and mlruns; preserve any results you need before using it. Deleting experiments or running a full retrain is not necessary to migrate ordinary trusted artifacts.

Full workflow regression

From the repository root, with the test and model dependencies installed:

python -m pytest tests/rolling_tests/test_ddgda.py -m slow -q

The offline regression uses deterministic local daily market data and an isolated MLflow store. Both linear and LightGBM similarity models run through feature selection, seven similarity-training windows, daily rank IC, cache restoration, 30-epoch meta-training, inferred time weights, two rolling training windows, prediction/label collection and a 40-day portfolio backtest. It checks default refusal, explicit authorization, restored predictions, delayed replay of both saved rolling tasks and non-empty numerical results without replacing workflow stages with mocks. These small integration cases verify functionality, not paper-scale performance or investment returns.

Results

The results of related methods in Qlib's public dataset can be found here

Requirements

Here are the minimal hardware requirements to run the workflow.py of DDG-DA.

  • Memory: 45G
  • Disk: 4G

Pytorch with CPU & RAM will be enough for this example.