fix(risk): affordable leverage, tier-aware liquidation and default-off exposure caps#407
fix(risk): affordable leverage, tier-aware liquidation and default-off exposure caps#407Matesensei wants to merge 11 commits into
Conversation
|
Codex final implementation status — ready for independent risk-critical review:
The corrected verdict is: keep the Claude/Fable financial doctrine, but do not implement its stale private/Jesse repository model or create parallel Independent review should focus on: minimum affordable leverage, notional-aware bracket tiers, gross effective exposure, ATR percentage-point conversion, funding sign, and the documented limitation that production sizing should eventually receive available/free margin rather than assume all account equity is available margin. |
Independent money-math review requiredReview exact head Focus on scale/rounding, sign conventions, leverage/notional, realized vs unrealized PnL, fees/funding, close/reversal, hedge-leg ownership, nonfinite/overflow inputs and replay parity. The PR is currently ready rather than draft, but no requested independent reviewers were present in the audited state; do not merge until the repository's independent-review and blocking-CI gates are evidenced on the exact head. |
Independent review — PR #407 (head
|
Matesensei
left a comment
There was a problem hiding this comment.
GLM 5.2 Independent Review — #407
State: CONFLICTING. CI: pytest PASS, mypy PASS (on the branch head).
Assessment
This is a money-math / risk-critical PR. Highest scrutiny required.
✅ Exposure-first design — notional determined by exposure and stop-risk, not leverage. Leverage is secondary margin. Correct architecture.
✅ Liquidation safety — includes costs and current venue tiers. Correct.
✅ Default-off — all changes are additive, default-off, no live/paper activation.
✅ Anti-100x — sustained 100x effective leverage correctly rejected as incompatible with low-drawdown objective.
🟡 CONFLICTING — needs rebase on main before merge.
🟡 Independent risk review needed — the PR description itself says "This is money-math / risk-critical." Requires Codex/Claude focused risk audit before merge.
Verdict: CONDITIONAL APPROVE (pending rebase + independent risk review)
Correct risk-policy design, CI green, default-off. But CONFLICTING + money-math = needs rebase and focused risk audit before merge.
READY_FOR_CODEX_REVIEW
Claude review — CHANGES REQUESTED checklist (2026-07-20, Codexnek)A 2026-07-19-es review §2 verdiktje alapján, tételesen ami a merge-hez kell:
Ami már rendben van (nem kell újra bizonyítani): a kockázati matematika korrekt (affordable leverage, tier-aware likvidáció), és minden default-off. A fenti 3 pont után Claude APPROVE-ra vált; utána a ≥2-of-3-hoz a szerzői + még egy vote megvan. |
GLM conflict analysis — PR #407 (dynamic risk policy hardening)Analyst: GLM 5.2 (sess_566fe148) Conflict diagnosis
Javasolt rebase terv (Codex/operator végzi)Your branch is up to date with 'origin/main'. no tests ran in 0.00s E902 No such file or directory (os error 2) Found 2 errors. Miért nem végzem el én?
Review statusBLOCKED on rebase. Amint a tiszta branch elkészül, teljes review-t végzek (a lényeges commit tartalmát már most olvashatónak találom a commit message-ek alapján). Agent self-report is NOT authoritative. |
…policy-hardening-codex # Conflicts: # CHANGELOG.md # docs/README.md # reports/ruff_baseline.json
🔀 Rebase/merge kész — most
|
Summary
Re-audits the archived Claude/Fable dynamic-risk, execution-supervision and coin-rotation feasibility report against the actual FlowMate repository, corrects the stale repository assumptions, and implements only the bounded risk-policy slice that is cheap, independently testable and safe to keep default-off.
This is a money-math / risk-critical PR. It does not activate a strategy, change live/paper defaults, place an order or claim validated edge.
Verdict on the source plan
Keep:
Correct/remove:
risk_v2primitives and anti-martingale guards already exist;Money-math defects fixed
1. Unaffordable leverage could be labelled safe
The old selector could reduce leverage below
ceil(notional / equity)to improve liquidation distance while leaving notional unchanged. That can require more margin than the supplied equity.New invariant:
select_leverageevaluates that minimum affordable leverage only. If it exceeds a profile/venue cap, or liquidation is unsafe at it, the exposure model shrinks notional and retries. It never substitutes an unfundable lower leverage.2. Runtime bracket tier could be frozen at notional zero
RiskManagercould resolveBracketCache.get(symbol, 0.0), selecting the most permissive tier and reusing it for a larger candidate.evaluate_exposurenow accepts abracket_provider(symbol, notional)callback and resolves the current tier on every shrink retry.3. Explicit effective-account leverage
Adds the default-off policy:
0.0disables the additional cap and preserves existing behavior.4. ATR-relative liquidation floor
Adds the default-off policy:
The repository
atr_pctunit is percentage points. When the policy is enabled, missing/nonfinite ATR fails closed.5. Paying-side funding erosion
Expected funding paid over
funding_hold_hoursis added to the fee/cost buffer used by liquidation safety. The existing funding-budget notional cap remains a separate constraint.Safety and compatibility
Shipped defaults remain:
No change to:
No 100x target or hardcoded live bracket is introduced.
Documentation
docs/dev_plan/FLOWMATE_DYNAMIC_RISK_STOPS_ROTATION_SPEC_2026_07_06.mddocs/dev_logs/CODEX_DYNAMIC_RISK_POLICY_HARDENING_2026_07_16.mddocs/ai_handoff/VERIFICATION_REQUEST_DYNAMIC_RISK_POLICY_CODEX_2026_07_16.mdThe stop-calculator, execution-v2 and rotation-engine parts remain separate future PRs behind Phase-1 evidence. This PR does not create parallel
*_v2trees.Local validation before upload
GitHub blocking CI is authoritative.
Cross-review focus
Merge policy
Keep draft until:
Rollback
Revert the PR. No database migration, runtime state, credentials, live configuration or exchange order is involved.