Date: 2026-02-26
Branch target: test
Simplify spread maintenance while preserving stability:
- Keep current double-side replacement behavior.
- Keep existing
n-extraslot creation when spread is too wide. - Remove reliance on split/merge-style partial handling for spread correction.
- Ensure correction is always fund-safe and converges smoothly over time using total funds + ideal grid sizing.
- If spread is too wide and
nslots are missing, create exactlynextra edge orders (existing behavior onteststays). - If the chosen edge candidate is
PARTIAL, update it toward ideal full size first (fund-capped). - New orders must use available funds first.
- If available funds are insufficient (including zero), run redistribution from existing same-side orders using updated ideal sizing (grid-reset style projection).
- Keep doubled-side update/replacement behavior unchanged.
- Do not dynamically modify target spread based on doubled flags.
- Temporary grid gaps are acceptable; repeated cycles should smooth naturally.
Observed behavior in profiles/server-profiles/logs/XRP-BTS.log after commit d1a6d9b63c7378c646031500fc1b0c299d0cb5b2:
- System is generally stable (
SAFE-REBALANCE+VALIDATION PASSEDrepeatedly). - Spread correction can fail to execute when it picks a partial update with no blockchain delta:
Spread too wide ... correcting with 1 extra slot(s)Identified partial order ... for updateSkipping size update ... no blockchain deltaSpread correction batch was prepared but not executed
This suggests correction should be deterministic, fund-aware, and less coupled to fragile split/merge side effects.
- Spread correction planning and funding logic.
- Partial-to-ideal top-up behavior at the edge.
- Funding fallback through redistribution/reprojection.
- Tests for correction and funding edge cases.
- Rewriting sync engine fill semantics.
- Changing doubled-side trigger/reset behavior.
- Broad architecture refactors unrelated to spread correction.
- Keep existing missing-slot detection and
n-extradecision logic. - Ensure correction can produce both:
- edge partial size update (if candidate is partial), and
- exactly
nedge creates.
- Remove target-spread inflation tied to doubled flags in spread checks.
Primary file: modules/order/grid.js
Build a two-stage funding allocator for correction actions on the selected side.
- Compute available budget:
available = min(funds.available[side], accountTotals.sideFree)
- Apply available budget to:
- partial top-up (edge partial -> ideal),
nnew edge orders.
If remaining demand > 0, do a same-side reprojection:
- Recompute ideal sizes using total side budget and updated side layout (including missing slots to be created).
- Identify over-allocated existing active/partial orders (size above new ideal).
- Reduce those orders down toward ideal, respecting minimum size safety.
- Allocate recovered size to:
- edge partial top-up first,
- then new edge orders in edge-priority order.
- If still insufficient, place only affordable creates (
k <= n) and log shortfall.
Safety guards:
- Never resize below minimum absolute / dust-safe constraints.
- Never create below health threshold.
- Never spend beyond available + recovered budget.
Primary files: modules/order/grid.js, possibly modules/order/manager.js (if action merge flow needs small extensions)
No behavior change in:
modules/order/sync_engine.js- doubled full fill -> reset flag + double replacement trigger
- doubled partial fill -> reset flag + single replacement trigger
This is intentionally preserved for runtime stability.
Add/adjust tests to cover:
- Spread too wide +
nmissing -> plansncreates. - Edge partial exists -> partial is topped up toward ideal before/alongside creates.
- Sufficient available funds -> no redistribution needed.
- Zero available funds + recoverable excess -> redistribution funds correction.
- Zero available funds + no recoverable excess -> safe no-op or partial correction only.
- No target spread mutation from doubled flags.
- Double-side fill triggers still behave exactly as before.
Likely test files:
tests/test_fill_coupled_partial_planner.js(adjust or split responsibilities)- new spread-correction funding tests (recommended dedicated file)
When spread is too wide:
- Compute
nmissing edge slots. - Select preferred side via existing side-selection logic.
- Build correction candidates:
- optional edge partial update candidate,
nnearest free spread slots.
- Run funding allocator (available-first, redistribution fallback).
- Emit one COW batch with final
ordersToUpdate+ordersToPlace. - If any planned action has zero blockchain delta, skip that action only (do not fail entire correction unless batch would be empty).
- Spread correction does not rely on split/merge maintenance behavior.
n-extrabehavior remains active and deterministic.- Partial edge orders can be topped up to ideal target when affordable.
- New orders never exceed available/recovered budget.
- With no free funds, redistribution can still fund corrections when over-allocated orders exist.
- Duplicated/no-delta update edge cases do not cause unstable correction loops.
- Doubled-side replacement behavior remains unchanged.
- Implement behind existing flow (no new config required initially).
- Run targeted tests for spread correction + fill handling.
- Replay/observe live log markers:
Spread too wideSPREAD-CORRECTIONSkipping size update ... no blockchain deltaSpread correction batch was prepared but not executed
- Confirm reduced occurrence of aborted correction batches and smoother convergence over several rebalance cycles.
- This plan intentionally prioritizes deterministic correction and financial safety over strict contiguous-grid aesthetics.
- Grid smoothness is expected to emerge over repeated cycles from ideal-size reprojection, not from forced split/merge mechanics.