Skip to content

fix(rsi): harden factor sandbox, governance split, RSI engine, council/crossover, and arena OOS (Rounds 7-11) - #29

Open
ZhuLinsen wants to merge 1 commit into
mainfrom
fix/sandbox-governance-rsi-council-and-arena-integrity
Open

ZhuLinsen wants to merge 1 commit into
mainfrom
fix/sandbox-governance-rsi-council-and-arena-integrity

Conversation

@ZhuLinsen

Copy link
Copy Markdown
Owner

What Changed (Batch 3: Rounds 7–11)

  • Round 7 — FactorSandbox Security & Process Isolation (src/alphaevo/alpha_factory/sandbox.py, factory.py):
    • Replaced host exec() in _build_indicator_fn with AST/bytecode preflight_code() + 8-entry LRU cache (_df_cache_key sensitive to column/index dtypes, CategoricalDtype category order/dtypes, and object-dtype Python element types).
    • Hardened AST whitelist + _SafeModuleProxy (np/pd/math) + persistent spawn worker with BLAS single-thread env caps, RLIMIT_AS, deep PIT row slicing (df.iloc[: idx + 1].copy(deep=True)), and PEP 578 sys.addaudithook gated by _IN_FACTOR_EXEC.
    • Routed FactorSandbox.probe_pit through the hardened spawn worker (instead of unhardened fork).
  • Round 8 — Governance Purged/Warmup Split & Direction Alignment (src/alphaevo/alpha_factory/governance.py, rsi/co_steer.py):
    • Removed _fwd_ret column leak from factor execution panels; implemented calendar-aligned purged train/OOS split with causal warmup (_SplitPanelData) + valid non-NaN forward-return horizon guards so disjoint/short calendars never auto-retire PIT-safe factors.
    • Routed FactorGovernanceEngine PIT checks through self._sandbox.probe_pit; fixed signed IR (train_ic / train_ic_std, oos_ic / oos_ic_std).
    • Added expected_direction preservation, built-in/dynamic name collision guards, active-metric preservation, and retired-factor protection across LLM and offline Co-STEER synthesis.
  • Round 9 — RSI Engine, Atomic FactorStore & SQLite Concurrency (src/alphaevo/rsi/engine.py, alpha_factory/factor_store.py, strategy/store.py, reflection/experience.py):
    • Enforced fail-closed locked_holdout_pct > 0, non-starving candidate selection, unconditional order-invariant round-end DSR recomputation via TrialLedger.compute_dsr_for_trials, post-refresh MAP-Elites archive insertion, atomic FactorStore.save_if_absent (ON CONFLICT DO NOTHING) before mark_trial_accepted, and exception-safe transient L2 dynamic factor lease refcounting.
    • Hardened SQLite stores with thread locks, timeout=30.0, WAL, busy_timeout=5000, and close() / context managers.
  • Round 10 — Heterogeneous Council, Crossover/Mutator & Mechanism A/B (src/alphaevo/rsi/council.py, crossover.py, reflection/mutator.py, rsi/mechanism.py):
    • Honored committee.overall_status == "fail" under overfit, fixed <= / < negative/zero relaxation math, and made configured CLI / LiteLLM prosecutors (including ALPHAEVO_API_KEY env var before ConfigManager.load()) fail closed.
    • Added exit.triggers, stop_loss.conditions (None vs [] exact), None resets, shared prune_dangling_exit_tunables, and shared promote_legacy_conditions_to_triggers across crossover and mutator so audit replays match grafted children identically.
    • Isolated unified calendar cutoffs in Mechanism A/B with synthetic monotonic dates for undated frames, per-cutoff EvaluationKernel/BacktestEngine execution, OOS-only slicing, and market-derived null pool verification.
  • Round 11 — Arena Strict OOS Evolution vs Unseen Shadow Replay (src/alphaevo/arena/runner.py):
    • Separated pre-cutoff evolution panel (>= 15 pre-cutoff bars) strictly before shadow_start_date, preventing ShadowLedger eff_end baseline fallback and reporting shadow_verified = False when skipped or failed.

Why

Eliminates lookahead leakage, sandbox escape vectors, premature factor retirement/reactivation races, proposal-order DSR skew, fail-open critic paths, and in-sample/OOS overlap across Levels 1–3 while keeping the L0 Truth Kernel (src/alphaevo/truth/, src/alphaevo/evaluator/metrics.py) strictly untouched.

Verification

  • .venv/bin/ruff format & .venv/bin/ruff check: All checks passed (0 issues).
  • .venv/bin/mypy src/: Success: no issues found in 135 source files.
  • .venv/bin/pytest -q: 1102 passed in 137.77s, 0 warnings (including dedicated Batch 3 hardening suites in tests/unit/test_round7_to_11_sandbox_governance_rsi_arena_integrity.py).
  • L0 freeze check: git diff --name-only main -- src/alphaevo/truth/ src/alphaevo/evaluator/metrics.py is empty.
  • Multi-pass cross-model adversarial review (OpenAI Codex CLI gpt-6.2-sol, final task-3387): LGTM.

Risks

  • Hardening FactorSandbox.probe_pit via persistent spawn workers increases cold-start latency slightly on the first PIT call per worker, amortized by process reuse and LRU caching; tested on Linux and will be verified on Windows (windows-smoke) via CI.

Disclaimer: AlphaEvo is research and educational software only. Simulated backtests, factor audits, and shadow ledgers do not constitute financial advice or guarantee future returns.

This branch has not been deployed

No deployments
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