[C] Orion Implementation — FLAG 034 + Cleanup Results
To: Vesper CC: Katja (Captain), Atlas From: Orion Date: 2026-04-17
Branch¶
fix/post-injection-cleanup off feat/flag-031-basis-model in /tmp/neo_git_work.
Four commits, each self-contained with unit tests. Bundled on one branch per "bundle if clean" guidance — all four changes are read-path or diagnostic and do not overlap.
Commits¶
| SHA | Subject | Files |
|---|---|---|
32c5b0a |
flag-034: display balance uses TOTAL (fills + capital overlay) | summarize_paper_run.py, tests/test_flag_034_display_overlay.py |
9faba8a |
retire max_inventory_usd: dead config removed | 14 files (code + configs + tests) |
d4c88ca |
flag-033: startup DB integrity check (PRAGMA quick_check) | run_paper_session.py, tests/test_flag_033_startup_integrity.py |
4ff5241 |
flag-028: add idx_fills_session_id index | neo_engine/state_manager.py, tests/test_flag_028_fills_session_index.py |
RLUSD Exposure Trace (Task 3)¶
Enforcement location: neo_engine/risk_engine.py:96
Mirrored halt-reason diagnosis in main_loop.py:789.
Check variable: inventory.rlusd_balance — TOTAL post-overlay balance via InventoryManager.get_snapshot(). Same source as all other guards.
Mechanism: Hard HALT, strict > comparison. Not a quote-generation gate, not a sizing attenuator. Any tick where post-fill RLUSD > cap trips the risk engine and stops the main loop for the session.
Headroom analysis at current live state:
- Current RLUSD balance: ~97.6
- max_rlusd_exposure: 120.0
- Headroom: ~22.39 RLUSD
At base_size_rlusd = 15:
- One SELL fill at base size: 97.6 → ~112.6. OK, still ~7.4 RLUSD under the cap.
- Two SELL fills same session: 97.6 → ~127.6. Breaches cap → HALT.
- One SELL fill with size-skew multiplier (up to ~1.30× base from inventory drift = ~19.5 RLUSD): 97.6 → ~117.1. OK but within 3 RLUSD of cap.
Verdict: max_rlusd_exposure = 120 is NOT currently gating fills (no quotes blocked, no sizes reduced). But it IS a tripwire — two SELL fills in the same session will HALT the engine mid-run. Not the root cause of S33–S35 zero fills, but the headroom is tight enough that once BUY/SELL activity resumes at size=15 we will see a RLUSD-exposure HALT within the first couple of SELL fills on a high-drift trajectory.
Recommendation: Raise max_rlusd_exposure to 140 or 150 before the next session. Not bundled with this branch — requires Atlas ruling since it's a live risk parameter change.
Test Coverage — FLAG-034¶
Five unit tests, all passing:
| Test | Covers |
|---|---|
test_no_capital_events_returns_fills_only |
overlay = 0 → returns fills_only unchanged |
test_deposit_adds_to_fills_only |
overlay = +35.21 XRP → fills_only + overlay |
test_withdrawal_subtracts_from_fills_only |
overlay = -25.0 RLUSD → fills_only - overlay |
test_basis_commit_does_not_move_asset_balance |
basis_commit excluded by CASE WHEN → balance unchanged |
test_fallback_used_when_no_ledger_rows |
engine_state seeded balance + overlay |
Added basis_commit and fallback cases: live DB has both a synthetic basis_commit event and engine_state seeded balances — confirmed fix handles them correctly.
FLAG-033 Notes¶
_startup_integrity_checkruns BEFORE_create_pre_run_backup— corrupt files do not get quietly backed up.- Handles both failure modes:
PRAGMA quick_checkreturning non-ok, ANDDatabaseErrorraised when the file is too broken for the pragma to execute (311-page truncation case). - Read-only open via
sqlite:///file:…?mode=roURI so the check cannot itself damage the DB. - Five unit tests: no-op paths (
:memory:, missing path, empty file), healthy pass, and truncated file failure.
FLAG-028 Notes¶
Single index: idx_fills_session_id ON fills (session_id). In migration block alongside other post-schema column additions, gated by CREATE INDEX IF NOT EXISTS — idempotent across existing DBs. Two unit tests: index exists, index covers the session_id column.
max_inventory_usd Retirement Notes¶
14 files touched:
- neo_engine/strategy_engine.py — removed from init log dict (line 116)
- neo_engine/main_loop.py — removed buy_inventory_guard_blocked from _log_no_intents_reason diagnostic
- neo_engine/config.py — removed StrategyConfig.max_inventory_usd field and loader kwarg
- config/config.yaml, config/config_live_stage1.yaml, config/config_live_session1.yaml, config/config.example.yaml — removed from all four
- tests/test_task5.py — removed from _make_config helper default, one call site, and StrategyConfig(...) constructor
- tests/test_phase3d.py, tests/test_phase4a.py, tests/test_main_loop.py — removed all kwargs and mock assignments
- neo_simulator/simulation_runner.py — removed kwarg
- neo_engine/main_loop_Old.py, neo_engine/strategy_engine_old.py — archive-file references scrubbed for grep hygiene
Smoke tests pass: all four configs load cleanly, StrategyConfig no longer has the field.
Workspace Config — Katja Action Required¶
The git repo at /tmp/neo_git_work is the source of truth. The workspace copy at config/config_live_stage1.yaml is a separate working copy with unmerged edits (base_size_rlusd: 15.0 is staged but not yet committed there). Did NOT touch it to avoid stomping edits.
Katja: When merging fix/post-injection-cleanup into main locally, delete the max_inventory_usd line from config_live_stage1.yaml (line 78) before running the next session, OR resolve the merge by keeping the git version.
What Stays Unchanged¶
anchor_max_divergence_bps: 10.0— heldbase_size_rlusd: 15.0— held- No other strategy parameters touched
Merge Ordering¶
fix/flag-008→ merge to main (pre-existing, blocked on Katja)fix/flag-030→ rebase onto main, merge (pre-existing, blocked on Katja)feat/flag-031-basis-model→ rebase, merge (pre-existing, blocked on Katja)fix/post-injection-cleanup→ rebase, merge (this branch)
— Orion