Vesper Review — FLAG-037 CANCELLED_BY_ENGINE Layer¶
To: Orion, Katja
From: Vesper
Date: 2026-04-21
Branch: fix/reconciler-disappeared-order-conservative-ext
Verdict: APPROVED¶
3 commits, 5 tests, 121 passed on touched surface. Spec compliance confirmed across all critical points. One apply-sequence clarification required before Katja runs the commands — read the apply section before touching the terminal.
Spec Compliance¶
Canonical evaluation order: CANCELLED_BY_ENGINE (1) → cancel_tx_hash (2) → age-threshold (3). Implemented exactly. Atlas constraint met.
DB write before gateway submit: Confirmed in C6. Failure posture (DB fail → skip gateway, DB success + gateway fail → log and continue) matches ruling. Correct.
Dedicated mark_cancelled_by_engine method: Confirmed. Single transaction, writes status + cancelled_at + cancel_reason + updated_at. Intent legible at call site. Correct.
British spelling CANCELLED_BY_ENGINE: Confirmed, distinct from existing CANCELED. Correct.
No anomaly row for CANCELLED_BY_ENGINE skip: Correct. Skip is expected behavior, not an anomaly. Structured INFO log with order_id, offer_sequence, cancelled_at, cancel_reason is sufficient for auditability.
Defense-in-depth (my ruling): _get_orders_for_reconciliation extended to include CANCELLED_BY_ENGINE and _reconcile_order dispatches directly to _handle_disappeared_active_order. The guard fires on the post-cancel tick AND after restart — not relying solely on status-filter exclusion from get_active_orders. Restart continuity test (#3) confirms. Correct.
5 Atlas-required tests: All present and correctly scoped.
| # | Test | Key assertion |
|---|---|---|
| 1 | DEGRADED cancel + reconcile | No phantom fill, RECONCILER_SKIP_ENGINE_CANCEL logged |
| 2 | Ambiguous disappearance → age gate | Age-gate unchanged; no skip log |
| 3 | Restart continuity | Fresh StateManager still skips on persistent DB state |
| 4 | Mixed cancelled + ambiguous | Only ambiguous processed; skip fires once |
| 5 | Truth gate preservation | Zero inventory delta on all-CANCELLED_BY_ENGINE batch |
Windows teardown: StateManager.close() before TemporaryDirectory.cleanup(). Correct.
Standing rule compliance: No pre-created branch ✅, no *.patch glob ✅, defensive branch delete ✅.
Observation (Non-Blocking)¶
_get_orders_for_reconciliation now fetches CANCELLED_BY_ENGINE orders on every tick for the remainder of the session. In most sessions this will be a small set (one DEGRADED event = one batch of cancelled orders). If sessions eventually run long with multiple DEGRADED events, this set grows. Current impact is negligible. Log here for FLAG-043 or a future cleanup pass — do not address in this branch.
Apply Sequence — READ BEFORE RUNNING¶
Important: The C5–C7 patches were developed on top of the C1–C4 age-threshold layer. Katja's main does not yet have C1–C4. Both bundles must be applied. Two branches, two merges, in order.
Step 1 — Apply C1–C4 (age-threshold, original approval Apr 19)¶
cd C:\Users\Katja\Documents\NEO GitHub\neo-2026
git checkout main
git pull
git branch -D fix/reconciler-disappeared-order-conservative 2>$null
git checkout -b fix/reconciler-disappeared-order-conservative
Get-ChildItem "C:\Users\Katja\Documents\Claude Homebase Neo\02 Projects\NEO Trading Engine\08 Patches\fix-reconciler-disappeared-order-conservative" -Filter "*.patch" | Sort-Object Name | ForEach-Object { git am $_.FullName }
python -m pytest tests/test_reconciler_conservative.py tests/test_ledger_reconciler.py tests/test_config.py -q
# Expected: 87 passed, 10 pre-existing errors (test_reconciler_anomaly_log.py only)
Then merge:
git checkout main
git merge fix/reconciler-disappeared-order-conservative --no-ff -m "merge: FLAG-037 age-threshold conservative phantom-fill gate"
Step 2 — Apply C5–C7 (CANCELLED_BY_ENGINE layer, this delivery)¶
git branch -D fix/reconciler-disappeared-order-conservative-ext 2>$null
git checkout -b fix/reconciler-disappeared-order-conservative-ext
Get-ChildItem "C:\Users\Katja\Documents\Claude Homebase Neo\02 Projects\NEO Trading Engine\08 Patches\fix-reconciler-disappeared-order-conservative-ext" -Filter "*.patch" | Sort-Object Name | ForEach-Object { git am $_.FullName }
python -m pytest tests/test_reconciler_conservative.py tests/test_reconciler_cancelled_by_engine.py tests/test_ledger_reconciler.py tests/test_config.py tests/test_state_manager.py -q
# Expected: 121 passed
Then merge:
git checkout main
git merge fix/reconciler-disappeared-order-conservative-ext --no-ff -m "merge: FLAG-037 CANCELLED_BY_ENGINE layer — reconciler skip + cancel_all intent write"
If any git am fails mid-apply: git am --abort, screenshot the error, flag to Vesper.
Post-Merge¶
Once both merges are on main:
- Realign before S47:
python tools/realign_inventory_to_onchain.py --config config/config_live_stage1.yaml --db neo_live_stage1.db --dry-run→ then--confirm - S47 can run. Use
--duration-seconds 7200. - If S47 reaches
duration_elapsed→ FLAG-037 closed. Orion drafts closure note. - FLAG-040 (WAC correction) is next in Orion's queue — Vesper will issue tasking after S47 confirms the fix.
— Vesper, COO, BlueFly AI Enterprises