[C] Orion Implementation — FLAG 034 + max inventory usd Retirement
To: Orion CC: Katja (Captain), Atlas From: Vesper Date: 2026-04-17
Atlas rulings are in. See [C] Atlas Alignment — Post-Injection Regression Rulings.md for full context.
Task 1 — FLAG-034: Implement (APPROVED)¶
File: summarize_paper_run.py
Implement your proposed fix to _get_inventory_balance. Atlas requires one addition — a comment explaining the display semantics:
def _get_inventory_balance(conn, asset, fallback_key) -> float:
row = conn.execute(
"SELECT new_balance FROM inventory_ledger WHERE asset = ? ORDER BY id DESC LIMIT 1",
(asset,),
).fetchone()
if row:
fills_only = float(row["new_balance"])
else:
fallback = _get_float_state(conn, fallback_key)
fills_only = fallback if fallback is not None else 0.0
# FLAG-034: add capital-events overlay so the displayed balance matches
# the live total held by InventoryManager (fills + capital deltas).
# NOTE: Display uses TOTAL inventory (fills + capital overlay),
# matching live engine state, not ledger-only state.
overlay = conn.execute(
"SELECT COALESCE(SUM(CASE WHEN event_type='deposit' THEN amount "
"WHEN event_type='withdrawal' THEN -amount ELSE 0 END), 0.0) AS o "
"FROM capital_events WHERE asset = ?",
(asset,),
).fetchone()["o"]
return fills_only + float(overlay)
Requires a unit test before merge. Add at minimum: - Test with no capital_events (overlay = 0 → returns fills_only unchanged) - Test with one deposit event (overlay = deposit amount → fills_only + overlay) - Test with a withdrawal event (overlay negative → fills_only reduced)
Task 2 — max_inventory_usd: Retire Completely (APPROVED)¶
Atlas ruling: "Kill it cleanly." Remove from logs, config, and mental model. Do not wire in as a real gate.
Scope:
1. strategy_engine.py:116 — remove the config echo (self.max_inventory_usd = ... or equivalent)
2. main_loop.py:1102 — remove the comparison and the buy_inventory_guard_blocked field from the _log_no_intents_reason diagnostic dict entirely
3. config_live_stage1.yaml and config.yaml (paper) — remove max_inventory_usd from the strategy: block
4. Any config schema/dataclass — remove the field definition
5. Any references in tests or fixtures — remove or update
Do not leave a dead field in config. Remove it from both live and paper configs.
Task 3 — RLUSD Exposure Check (Atlas additional finding)¶
Atlas flagged a potential secondary constraint:
base_size_rlusd = 15 → ~30 RLUSD per round
max_rlusd_exposure = 120
Current RLUSD balance = ~97.6
Headroom = ~22 RLUSD
Question: Is max_rlusd_exposure affecting quote eligibility or sizing anywhere in the hot path?
Trace: does the RLUSD exposure check block or reduce quoting when RLUSD balance approaches max_rlusd_exposure? If so, at what threshold does it engage relative to current balance? Report the exact check location, variable, and whether headroom of 22 RLUSD is enough at size=15.
This is diagnostic — no fix needed unless you find an active constraint that's gating fills.
Task 4 — FLAG Bundle (same pass)¶
- FLAG-033:
PRAGMA quick_checkat startup inrun_paper_session.py. Design is complete. ~10 LOC. - FLAG-028:
idx_fills_session_idindex instate_manager.py.
Bundle FLAG-033 and FLAG-028 with FLAG-034 on the same branch if clean, or separate branch if simpler.
What Stays Unchanged¶
Do NOT touch:
- anchor_max_divergence_bps: 10.0 — Atlas ruling: hold for one controlled diagnostic run first
- base_size_rlusd: 15.0 — no change
- Any other strategy parameters
Deliverable¶
Return:
1. Branch name(s) and commits for FLAG-034, max_inventory_usd retirement, FLAG-033, FLAG-028
2. RLUSD exposure trace result
3. Test coverage confirmation for FLAG-034
We run the next session after this lands and merges.
— Vesper