Repository navigation
fix(lean-prover): repair 3 critical regressions reported by po-2026 (#833) - #847
Conversation
… (Issue #834) Side-track ai-01 RTX 4090. Differentiates from existing train_gnn.py / train_mtgnn.py by targeting log-RV (where HAR/GARCH actually win measurably) instead of next-step direction of average panier return. Architecture: 3 GAT branches (daily / weekly / monthly à la Corsi 2009) on dynamic correlation graph, fusion MLP. Reuses M2 #837 RV pipeline (realized_variance.py, intraday_loader.py). Files - docs/M5_MULTISCALE_GNN.md — architecture + caveats + reproduction - scripts/multiscale_gnn_features.py — CrossAssetPanel (T,N=3,F=4) + rolling-correlation top-K adjacency + targets_h_step - scripts/multiscale_gnn_model.py — MultiScaleGNN PyG (3 GAT + fusion) - scripts/tests/test_multiscale_gnn_features.py — 14 tests (alignment, no-leakage HAR, adjacency normalization, target h-step, PyG batches) - scripts/tests/test_multiscale_gnn_model.py — 6 tests (forward shapes, param count bounds, gradient flow, scale distinctness, eval determinism) Tests: 20/20 PASS in coursia-ml-training env (torch 2.11+cu126 + PyG 2.7). ~6s, no GPU needed for unit tests. Driver `train_multiscale_gnn.py` + walk-forward training results to come in follow-up commit. This is scaffold + plan, not yet a recommendation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… (Issue #834) Driver for MultiScaleGNN: walk-forward 5-fold × multi-seed × {h=1,5,10} on cross-asset log-RV target. Compares mean MSE log-RV to HAR baseline (M2 #837) per coin and reports honest verdict via 2σ cross-seed gate. Verdict policy (cf G.2 pr-review-discipline): edge = HAR_mean - M5_mean - 2 * M5_std_cross_seed verdict = "BEATS HAR (≥2σ)" if edge > 0 | "NO BEATS HAR (<2σ)" if edge ≤ 0 | "INSUFFICIENT" if seeds < 4 or synthetic Dry-run validation (synthetic 3 'coins', n_days=400, 2 horizons × 2 seeds): device=cuda, T=378, panel build OK, training loop OK, JSON output OK h=1 M5 MSE log-RV = 0.212 ± 0.042 h=5 M5 MSE log-RV = 0.110 ± 0.012 verdict INSUFFICIENT (correct: synth + 2 seeds) elapsed 1203s (per-sample optim loop unbatched — to optimize for real run) Real run pending RTX 4090: 3 horizons × 4 seeds × 5 folds × 80 epochs on BTC + ETH + SOL hourly RV, vs HAR baseline. Verdict committed honest. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…#834) Inner training loop refactored from per-sample opt.step() to single forward+backward per epoch on full-fold PyG Batch. CUDA launch overhead no longer dominates compute on small graphs (N=3). Hyperparams retuned for full-batch convergence: - epochs: 80 → 400 (full-batch needs more outer iterations to match the effective updates of mini-batch training) - lr: 5e-3 → 1e-2 (gradient is more stable per step ⇒ larger lr OK) Dry-run (synth 3 coins, T=378, 2 horizons, 2 seeds, 5 folds): v1 unbatched: 1203.3s, h=1 MSE=0.212±0.042, h=5 MSE=0.110±0.012 v3 batched : 13.6s, h=1 MSE=0.147±0.002, h=5 MSE=0.083±0.000 → ~88x speedup + better convergence (lower std cross-seed) Real run feasible now: 3h × 4 seeds × 5 folds × 400 epochs estimated ~10 min on RTX 4090 (was ~13h before optim). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Permet de restreindre le panel cross-asset a un sous-ensemble de coins quand l'intersection des dates est vide ou trop courte. Le default reste (BTC, ETH, SOL) mais en pratique BTC-USD+ETH-USD donne ~1500 jours d'overlap exploitables (Bitstamp 2018-2024 + Binance 2019-2023) alors que SOL (yfinance 2024+) reduit a 0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…26 (#833) Background: po-2026 dashboard post 2026-05-08T21:22:58Z documented 5 issues on the multi-agent prover after the Cycle 12 baseline run on median_voter_theorem (Voting.lean L251). This PR addresses #1 / #2 / #3 — the three blockers that made the prover unsafe and unusable on external LLM providers. CRITICAL #1 — `lean_server` import was path-dependent (verifier.py) Before: `from lean_server import LeanVerifier` only resolved when the caller's cwd was `agent_tests/`. From any other context (tests, notebooks, sub-process) it raised `ModuleNotFoundError` and either crashed the prover or — worse — was caught silently and made compile() return success=True regardless of build state. Fix: spec-based import via `importlib.util.spec_from_file_location` using `Path(__file__).parent.parent / "lean_server.py"`. Idempotent via a module-level cache. The verifier now works regardless of cwd. HIGH #3 — sorry guard was bypassable (tools.py) Before: the guard only counted occurrences of the literal token "sorry". An LLM could "improve" sorry_count by inserting `exact _`, `exact ?_`, `admit`, bare `_`, etc. — all non-compiling placeholders that look like progress. Fix: - new `_check_stub_guard()` rejects 6 known placeholder patterns before writing - new `_build_check_or_revert()` runs `lake build` after each write and reverts the file on failure - both `file_replace_sorry` and `file_replace_lines` gain a `build_check=True` default; callers can opt out for speed but the prover loop now never operates on a broken file HIGH #2 — multi-agent workflow could hang forever (workflow.py + provers.py) Before: `AgentExecutor.handle()` did `await self._agent.run(...)` with no timeout. A stalled provider (zai/openrouter occasionally do) blocked the entire graph. There was also no iteration cap on the cyclic critic→tactic→verify subgraph. Fix: - per-agent timeout (default 90s) via `asyncio.wait_for` - `ProofMessage.iteration` increments on every traversal; when it exceeds `max_iterations` the executor yields output instead of looping - `MultiAgentSorryProver.prove_sorry()` wraps `workflow.run()` in a wall-clock `asyncio.wait_for` (default `max_iterations * 120s`) Tests New `agent_tests/tests/test_prover_guards.py` (20 tests, all passing): - lean_server class loads via spec import (CRITICAL #1) - get_verifier instantiates with explicit project_dir - 6 stub patterns rejected by `_check_stub_guard` - 7 real tactics accepted by `_check_stub_guard` - comments containing `exact _` ignored - `file_replace_sorry` blocks `exact _` without writing - `file_replace_sorry` writes a real tactic - `ProofMessage` carries iteration cap + bounded default timeout - `MultiAgentSorryProver.prove_sorry` exposes workflow_timeout_s Install New `agent_tests/requirements.txt` documents the prover deps: `agent-framework-openai>=1.3.0`, `openai>=2.0.0`, `python-dotenv`, `pytest`, `pytest-asyncio`. Verified by installing into `coursia-ml-training` env and running the 20 tests. Out of scope (po-2026 issues #4 / #5) #4 (goal extraction cascading errors on Voting.lean) and #5 (LLM selection) are separate concerns — #4 needs Voting.lean fixes upstream, #5 is a config call left to the operator. Both are tracked under #833. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jsboige
left a comment
There was a problem hiding this comment.
Review — CHANGES_REQUESTED (G.4 composite)
G.4 violation: This PR mixes 2 distinct domains in a single PR:
- Prover guards (4 files):
prover/*.py,requirements.txt,tests/test_prover_guards.py - M5 multiscale GNN (7 files):
multiscale_gnn_*.py,train_multiscale_gnn.py,tests/test_multiscale_gnn_*.py,docs/M5_MULTISCALE_GNN.md
Request: Split into 2 PRs:
- PR A (prover guards):
prover/verifier.py,prover/tools.py,prover/workflow.py,prover/provers.py,requirements.txt,tests/test_prover_guards.py,tests/__init__.py— HIGH priority (#833 blocking po-2026) - PR B (M5 multiscale GNN): all
multiscale_gnn*files + doc — LOW stretch
The prover guard fixes (verifier.py import, stub guard 6 patterns, workflow timeout) are HIGH and should merge fast. The GNN code can wait.
Content review (prover parts):
verifier.py: import path-aware viaimportlib.util.spec_from_file_location— correct approachtools.py:_check_stub_guard()rejecting 6 patterns (exact _,admit, etc.) — comprehensiveworkflow.py:asyncio.wait_fortimeout per agent — correct- 20 tests cover all 3 fixes — verified by ai-01
Content review (GNN parts): Not reviewed in detail (wrong domain in this PR).
Please split so the critical prover fixes can merge immediately.
clusterManager-Myia
left a comment
There was a problem hiding this comment.
Review ClusterManager — PR #847 (M5 Multiscale GNN + Lean Prover Guards)
Scope
13 files, 1779 additions. Two distinct domains:
- M5 multiscale GNN (7 files): architecture doc, features, model, training, tests
- Lean prover guards (6 files): verifier import fix, stub guard, workflow timeout, requirements, tests
M5 Multiscale GNN
M5_MULTISCALE_GNN.md (130L)
Clear architecture doc. 3-scale temporal GAT on N=3 coins. Honest caveats (N=3 tiny, hourly RV noisier, no exogenous features). "Stretch = no merge expectation" — appropriate. Well-cited (Corsi 2009, Veličković 2018, Wu 2020, Diebold-Yılmaz 2012).
multiscale_gnn_features.py (244L)
CrossAssetPanel: clean shape contracts(T, N, F=4),(T, N, N)._build_har_features_panel: HAR features [log_rv, rv_d, rv_w, rv_m] withshift(1)— no look-ahead. Dropna removes first 22 rows. Correct._rolling_correlation_adjacency: rolling 60d correlation, top-K=2, symmetrized, self-loops, row-normalized. Row-sum-to-1 invariant verified by tests.targets_h_step(h):rolling(h).mean().shift(-h)— correct h-step target.to_pyg_batches: lazy per-timestep dict, avoids torch import at module level.
multiscale_gnn_model.py (123L)
_ScaleGAT: 2-layer GAT,add_self_loops=False(adjacency already includes them). Correct.MultiScaleGNN: 3 independent branches → concat → MLP. All 3 scales receive the samexinput — the "multi-scale" is in the HAR features baked into x's channels, not in different temporal windows per scale. Minor doc/code mismatch: doc says "daily/weekly/monthly windows" but implementation passes identical input to all branches.
train_multiscale_gnn.py (335L)
- Walk-forward expanding window, PyG Batch for parallel eval. Single forward/backward per epoch — efficient.
- Verdict: BEATS HAR requires
edge_2sigma > 0. Very conservative — appropriate for stretch. _har_baseline_per_coin: log-RV → exp() before walk_forward_har. Correct round-trip.
GNN Tests (280L)
Shape contracts, no look-ahead (rv_d lag-1 verified), adjacency invariants, PyG batch structure, target alignment, model output shape/dtype, gradient flow through all 3 branches, eval determinism. Good coverage.
Lean Prover Guards
verifier.py (+35L)
importlib.util.spec_from_file_location to load lean_server.py from parent directory. Fixes the path-dependent import failure. Cached after first load.
tools.py (+130L net)
_STUB_PATTERNS: 6 regex patterns (exact _,exact ?_,refine ?_,admit, bare_). Comprehensive._check_stub_guard: line-by-line scan, skips comments. Good._build_check_or_revert: writes → build → revert on failure with error parsing. Solid defensive pattern.file_replace_linesre-enabled with full guard chain (file size → stub guard → sorry guard → build check). Significant capability expansion.file_replace_sorry: added stub guard + build_check parameter.
workflow.py (+30L)
- Per-agent timeout (90s default). Iteration cap on ProofMessage.
asyncio.wait_foron agent.run(). Clean.
provers.py (+15L)
workflow_timeout_sparameter,asyncio.wait_foron workflow.run(). TimeoutError caught.
test_prover_guards.py (180L)
- 20 tests: spec-based import, stub guard (6 patterns rejected, 7 tactics accepted, comments ignored), file_replace_sorry blocks stubs, workflow iteration cap, prove_sorry timeout parameter.
Summary
GNN: Solid scaffold. Minor doc/code mismatch on "different temporal windows per scale". Verdict threshold appropriately conservative.
Prover: Well-executed hardening. Three real regression fixes with comprehensive tests. file_replace_lines re-enabled with full guard chain is a significant improvement.
On G.4: Agree with Hermes — splitting would let HIGH-priority prover fixes merge independently.
COMMENT — no blocking code issues in either domain.
…er-counts AIF attacks (3-axes confrontation) (#8398) Affinage #3 of ai-01 greenlight (DM kl2huf, Ontology_AIF track). The §7 note already distributed the 93 aifAttackedNode by attack type (61 undercut / 29 undermine / 3 rebut, grounded on the real OWL, PR #8319) and explained the total gap (93 vs ~145) by generator evolution. It did NOT confront the per-type decomposition with the Argumentum structural audit, nor explain WHY a naive grep under-counts. This enriches the §7 methodological note with that confrontation. Added (md[22] §7 interpretation, source-only, +1844 bytes): - ~82 undercut / ~50 undermine / ~5 rebut from the Argumentum 3-axes audit (PR ArgumentumGames/Argumentum#847: fail-loud union DirectRef+ExceptionRef) vs the 61/29/3 grep on the CoursIA OWL. - WHY the grep under-counts: it counts only explicit aifAttackedNode; the audit union reconstitutes attacks referenced indirectly via Walton schemes (§4) and the conflict layer (§8). 61 vs ~82 = the AIF structure overflows the single aifAttackedNode predicate. - Rule C.4 honesty: ~82/~50/~5 attributed as external Argumentum MEASURE (#847 OPEN, #857 closed non-merged "MEASURE not verdict"), verdict CAUSE_DOCUMENTED_ONLY — NOT reproducible from the CoursIA OWL alone (the #763 generator serializes only explicit aifAttackedNode; the method doc docs/taxonomy/aif-structural-audit-method.md lives in Argumentum, not CoursIA). The 61/29/3 decomposition remains the only verifiable measure here. Markdown-only change (C.2 exception: no re-exec needed). Exactly 1 cell touched (md[22] aif-dist-interp), source-only; all 12 code cells byte-stable (outputs + execution_count unchanged). Validation (re-run post-commit): - detect_markdown_rendering --check : OK exit 0 (no new violations) - validate_pr_notebooks : 1/1 PASS (12 cells, 0 H.3-violator) - detect_solution_leaks --scan : 0 HIGH / 0 MEDIUM / 0 errors - COURSE_CATALOG.generated.{json,md} byte-identical to main - byte-stability: git diff = 1 insertion / 1 deletion, only md[22] source See #5730 (Argument_Analysis ontology uplift, partial — the epic stays OPEN). See #4960 (Argument_Analysis v3 track). Routed by ai-01 DM kl2huf (affinage #3). Co-authored-by: jsboige <jsboige@gmail.com> Co-authored-by: Claude-Code <noreply@anthropic.com>
Summary
Repairs the 3 blockers po-2026 documented on the dashboard 2026-05-08T21:22:58Z after the Cycle 12 baseline run on
median_voter_theorem(Voting.lean L251).Fixes
from lean_server import LeanVerifieronly resolved when cwd wasagent_tests/. Otherwise compile() returned True regardless of build stateprover/verifier.py(importlib.util.spec_from_file_location)sorry-> LLM could "improve" sorry_count by writingexact _,admit, bare_, etc._check_stub_guard()rejects 6 placeholder patterns; new_build_check_or_revert()runslake buildpost-write and reverts on failure;file_replace_sorryandfile_replace_linesgainbuild_check=TruedefaultAgentExecutor.handle()had no timeout -> stalled provider froze the workflow foreverasyncio.wait_for);ProofMessage.iterationcap;workflow.run()wrapped in wall-clock timeout (defaultmax_iterations * 120s)Out of scope (tracked separately under #833): #4 goal extraction cascading errors on Voting.lean; #5 LLM model selection.
Conflict resolution (commit 64505e0)
po-2026 pushed safety guards directly to main (
04eb0ac3+f7f3a2c6) while this PR was prepared. Conflict inprover/tools.pyresolved by po-2026: kept the PR #847 stub guard + build check architecture, integrated po-2026's safety guards (LINE_TOLERANCE, OpenRouter provider, finally blocks) on top.Test plan
agent_tests/tests/test_prover_guards.py(all passing — 0.85s)exact _,exact ?_,exact ?h,refine ?_,admit, bare_)exact h,rfl,simp,omega,intro, ...)exact _ignoredfile_replace_sorryblocksexact _without writingfile_replace_sorrywrites a real tacticProofMessagecarries iteration cap + bounded default timeoutMultiAgentSorryProver.prove_sorryexposesworkflow_timeout_sagent_tests/and from CoursIA root cwdrequirements.txtdeps install cleanly intocoursia-ml-trainingenvBLOCKED: 3 sorry > original 2, auto-restore firedAUTO-RESTORE: 2 sorry > best 1, build check activeValidation by reviewer
Files
prover/verifier.py— robust spec-based import oflean_server.pyprover/tools.py— stub guard + post-write build check +build_checkparameterprover/workflow.py— per-agent timeout + iteration cap onProofMessageprover/provers.py—MultiAgentSorryProver.prove_sorry()wraps workflow.run() with wall-clock timeoutrequirements.txt— explicit prover deps (agent-framework-openai, openai, python-dotenv, pytest)tests/__init__.py+tests/test_prover_guards.py— 20 testsCloses the blocking part of #833. Per #833 plan, P3 (
set_attack_planintegration) and P4 (Voting.lean sorry 6->0) remain.Co-Authored-By: po-2026 noreply@anthropic.com
🤖 Generated with Claude Code