Skip to content

[C] Orion Message — Cleanup Branch Ready

Branch

fix/cleanup-and-anchor-instrumentation — 5 commits, one per item, in the order Vesper specified. Subjects match the brief exactly.

# SHA Subject Files
1 58ad919 fix(flag-034): session summary displays total XRP balance (fills + capital overlay) summarize_paper_run.py, tests/test_flag_034_display_overlay.py
2 ac33de6 chore: retire max_inventory_usd dead config (14 files) 14 files — code + 4 YAMLs + 4 tests + 2 archive
3 db85c38 fix(flag-033): startup DB integrity check before backup and engine init run_paper_session.py, tests/test_flag_033_startup_integrity.py
4 3ca933e fix(flag-028): add idx_fills_session_id index on fills table neo_engine/state_manager.py, tests/test_flag_028_fills_session_index.py
5 469e5bb feat: anchor_error_bps reliability stat — pct ticks where \|error\| > 5 bps neo_engine/main_loop.py, summarize_paper_run.py, tests/test_anchor_error_stat.py

All five held to the no-touch list — anchor_max_divergence_bps: 10.0, base_size_rlusd: 15.0, risk_engine.py, fill paths, schema (except the Item 4 index). No .claude or editor config stowaways.

Tests

Full suite of new tests, all passing locally:

Item Test file Count
1 test_flag_034_display_overlay.py 5
3 test_flag_033_startup_integrity.py 5
4 test_flag_028_fills_session_index.py 2
5 test_anchor_error_stat.py 3

Total: 15 unit tests across the four new files. 15/15 green together. Item 2 (max_inventory_usd retirement) has no dedicated test file — coverage comes from the existing test suite loading cleanly without the field (all 4 YAMLs load, StrategyConfig has no field, no test touches the removed kwarg).

Item 5 — anchor_error_bps output

Example summary line after the change (from the test expectations, illustrative):

Anchor: mean=+2.70bps | median=+5.45bps | range=[-10.0, +10.0] | bias=positive | |err|>5bps: 47.3%

The |err|>5bps: X.X% suffix is only emitted when engine_state has a value, so sessions from before this branch lands render as before (no "None%" on legacy logs).

Implementation details: - _log_anchor_divergence_summary() in main_loop.py gained one counter (abs_above_5), one computed stat (pct_error_above_5), one log-extra field, and one engine_state key (anchor.pct_error_above_5bps). - Existing buckets and one-sided counts (>10, >12, >14) untouched. - summarize_paper_run.py reads anchor.pct_error_above_5bps and conditionally appends the err5_str to the anchor line.

Delivery format — patches, not a push

Per your git rule, I'm handing off as .patch files for Katja to apply on her machine. Patches written to:

02 Projects/NEO Trading Engine/orion-patches-2026-04-18/

Five files: 0001-...patch through 0005-...patch. Each carries full commit metadata and message.

Expected conflict (one, known)

Patch 2 will conflict on one hunk in config/config_live_stage1.yaml. My sandbox baseline has max_inventory_usd: 10.0; Katja's main has max_inventory_usd: 20.0 # raised from 10.0 post-injection.... Since patch 2 deletes the line regardless of value, the resolution is simply delete the line and continue.

No conflicts expected on config.yaml, config_live_session1.yaml, config.example.yaml (values match my baseline).

Git commands for Katja — copy-paste, PowerShell

Run each block in your VS Code terminal from the repo root. Paste the path to the patches folder where shown.

Block 1 — create the branch off current main

git checkout main
git pull origin main
git checkout -b fix/cleanup-and-anchor-instrumentation

Block 2 — apply patches 1, 3, 4, 5 cleanly (skipping 2 for now)

# adjust the path to where the patches folder actually is on your machine
$patches = "C:\path\to\Claude Homebase Neo\02 Projects\NEO Trading Engine\orion-patches-2026-04-18"
git am --3way "$patches\0001-fix-flag-034-session-summary-displays-total-XRP-bala.patch"

Block 3 — apply patch 2 with --3way, expect conflict on config_live_stage1.yaml

git am --3way "$patches\0002-chore-retire-max_inventory_usd-dead-config-14-files.patch"

When git stops on the conflict, the file will have a block like:

<<<<<<< HEAD
  max_inventory_usd: 20.0   # raised from 10.0 post-injection (~10% of $200 portfolio)
=======
>>>>>>> (patch contents)

Resolve: open config/config_live_stage1.yaml, delete the entire conflict block (including both markers and the max_inventory_usd line). Save. Then:

git add config/config_live_stage1.yaml
git am --continue

Block 4 — apply remaining patches

git am --3way "$patches\0003-fix-flag-033-startup-DB-integrity-check-before-backu.patch"
git am --3way "$patches\0004-fix-flag-028-add-idx_fills_session_id-index-on-fills.patch"
git am --3way "$patches\0005-feat-anchor_error_bps-reliability-stat-pct-ticks-whe.patch"

Block 5 — verify the branch

git log --oneline main..HEAD

Expected: exactly five commits, same subjects and order as the table above.

Block 6 — run the new tests to confirm green on your machine

python -m pytest tests/test_flag_034_display_overlay.py tests/test_flag_033_startup_integrity.py tests/test_flag_028_fills_session_index.py tests/test_anchor_error_stat.py -v

Expected: 15 passed.

Block 7 — push and open PR

git push origin fix/cleanup-and-anchor-instrumentation

Then, either open the PR via GitHub UI, or:

gh pr create --base main --head fix/cleanup-and-anchor-instrumentation `
  --title "cleanup + anchor_error_bps instrumentation" `
  --body "5 commits per Vesper's 2026-04-18 brief: FLAG-034, max_inventory_usd retirement, FLAG-033, FLAG-028, anchor_error_bps reliability stat."

If anything goes wrong

If git am fails with "patch does not apply" on a file I didn't flag above, abort and ping me:

git am --abort

I'll regenerate against a fresher baseline. Most likely cause would be that main moved between my sandbox snapshot and your git pull — which is possible given the lag.

What stays unchanged (per the brief)

  • anchor_max_divergence_bps: 10.0 — held
  • base_size_rlusd: 15.0 — held
  • risk_engine.py — untouched
  • Fill calculation paths — untouched
  • No schema changes beyond the Item 4 index

— Orion