dexbot 1.5.3 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +4 -3
- package/analysis/README.md +1 -2
- package/analysis/ama_fitting/fetch_lp_candles.ts +1 -9
- package/analysis/ama_fitting/package.json +1 -1
- package/analysis/analyze_derivatives.ts +1 -1
- package/analysis/bot_usage/discover_bot_accounts.ts +12 -6
- package/analysis/resolve_source.ts +9 -2
- package/analysis/tradingview/README.md +29 -11
- package/analysis/tradingview/analyze_tradingview.ts +92 -3
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +1120 -182
- package/analysis/trend_detection/package.json +1 -1
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +1 -1
- package/claw/modules/dexbot_profiles.ts +22 -2
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/skills/launcher-ops/references/launcher-workflow.md +1 -1
- package/claw/tests/test_claw_mcp_transport.ts +2 -2
- package/claw/tests/test_dexbot_profiles.ts +65 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +1 -9
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -1
- package/dist/analysis/analyze_derivatives.js +1 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js +11 -6
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +2 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
- package/dist/analysis/resolve_source.d.ts +1 -0
- package/dist/analysis/resolve_source.d.ts.map +1 -1
- package/dist/analysis/resolve_source.js +6 -2
- package/dist/analysis/resolve_source.js.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +5 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +112 -3
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +5 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1118 -182
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/bot.js +1 -1
- package/dist/bot.js.map +1 -1
- package/dist/dexbot.js +3 -3
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +2 -2
- package/dist/market_adapter/candle_utils.d.ts +6 -0
- package/dist/market_adapter/candle_utils.d.ts.map +1 -1
- package/dist/market_adapter/candle_utils.js +6 -0
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.d.ts +17 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +101 -19
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.d.ts +2 -0
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +31 -4
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +0 -6
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +14 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_book_data.js +138 -0
- package/dist/market_adapter/inputs/fetch_book_data.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +16 -2
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +109 -281
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +87 -0
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +1 -0
- package/dist/market_adapter/inputs/kibana_feed_source.js +570 -0
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +10 -5
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +166 -0
- package/dist/market_adapter/inputs/window_cache.d.ts.map +1 -0
- package/dist/market_adapter/inputs/window_cache.js +500 -0
- package/dist/market_adapter/inputs/window_cache.js.map +1 -0
- package/dist/market_adapter/interval_utils.d.ts +8 -1
- package/dist/market_adapter/interval_utils.d.ts.map +1 -1
- package/dist/market_adapter/interval_utils.js +14 -1
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/modules/account_bots.d.ts +1 -0
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +21 -5
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +25 -4
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +67 -4
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.d.ts +2 -0
- package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +3 -1
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +13 -3
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts +2 -0
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +122 -28
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +59 -8
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +11 -0
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/constants.d.ts +13 -0
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +68 -4
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +8 -0
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +57 -2
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +26 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +157 -28
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +41 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +135 -5
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +79 -12
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +554 -46
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +13 -0
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts +15 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
- package/dist/modules/dexbot_state_recovery.js +36 -7
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/fund_registry.d.ts +1 -1
- package/dist/modules/fund_registry.js +1 -1
- package/dist/modules/node_connect_policy.d.ts +52 -0
- package/dist/modules/node_connect_policy.d.ts.map +1 -0
- package/dist/modules/node_connect_policy.js +35 -0
- package/dist/modules/node_connect_policy.js.map +1 -0
- package/dist/modules/node_manager.d.ts +32 -0
- package/dist/modules/node_manager.d.ts.map +1 -1
- package/dist/modules/node_manager.js +76 -9
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts +30 -0
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +176 -3
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/export.d.ts.map +1 -1
- package/dist/modules/order/export.js +1 -0
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +143 -15
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +5 -3
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +182 -6
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/manager.d.ts +64 -2
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +231 -14
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/strategy.d.ts +3 -0
- package/dist/modules/order/strategy.d.ts.map +1 -1
- package/dist/modules/order/strategy.js +79 -7
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +16 -1
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +11 -1
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +24 -1
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +258 -13
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +662 -12
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +36 -0
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +102 -6
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/validate.d.ts.map +1 -1
- package/dist/modules/order/utils/validate.js +6 -2
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/paths.d.ts +2 -0
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +1 -0
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts +13 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +20 -0
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/utils/errors.d.ts +16 -0
- package/dist/modules/utils/errors.d.ts.map +1 -1
- package/dist/modules/utils/errors.js +31 -0
- package/dist/modules/utils/errors.js.map +1 -1
- package/dist/pm2.js +7 -7
- package/dist/scripts/analyze-credit.d.ts.map +1 -1
- package/dist/scripts/analyze-credit.js +13 -3
- package/dist/scripts/analyze-credit.js.map +1 -1
- package/dist/scripts/analyze-orders.js +2 -2
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.js +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -1
- package/dist/scripts/test-credit-renewal.js +1 -1
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/tv.d.ts +24 -2
- package/dist/scripts/tv.d.ts.map +1 -1
- package/dist/scripts/tv.js +190 -65
- package/dist/scripts/tv.js.map +1 -1
- package/docs/BITSHARES_ONBOARDING.md +9 -2
- package/docs/COW_INVARIANTS.md +18 -1
- package/docs/DEXBOT_COMPARISON.md +3 -3
- package/docs/EVOLUTION.md +8 -7
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +21 -9
- package/docs/GRID_RECALCULATION.md +5 -6
- package/docs/GRID_RECONCILE.md +12 -2
- package/docs/MPA_CREDIT_USAGE.md +2 -2
- package/docs/README.md +5 -6
- package/docs/architecture.md +0 -58
- package/docs/developer_guide.md +2 -1
- package/docs/docker.md +1 -1
- package/market_adapter/README.md +4 -0
- package/modules/README.md +1 -1
- package/package.json +1 -1
- package/scripts/README.md +5 -3
- package/tests/README.md +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../modules/order/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../modules/order/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoJH,cAAM,kBAAkB;IACpB,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,GAAG,CAAC;gBAEA,IAAI,EAAE,GAAG;IAOf,OAAO,CAAC,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,KAAK,EACL,KAAU,EACV,UAAsB,EACtB,QAAe,EACf,WAAkB,EAClB,kBAAyB,EAC5B,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6LT;AAMD,cAAM,YAAY;IACd,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,GAAG,CAAC;IACjB,UAAU,EAAE,GAAG,CAAC;IAChB,UAAU,EAAE,GAAG,CAAC;IAChB,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,EAAE,GAAG,CAAC;IACV,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,6BAA6B,EAAE,OAAO,CAAC;IACvC,iBAAiB,EAAE,M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AM,GAAE,GAAiB;IAIhD;;;OAGG;IACH,qBAAqB,CAAC,MAAM,GAAE,GAAU;IASxC;;;;;;;OAOG;IACG,WAAW,CAAC,cAAc,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,GAAG,CAAA;KAAE;;;;;;;;;;;;IAyDvH,IAAI,iBAAiB,QAEpB;IAED,IAAI,iBAAiB,CAAC,KAAK,KAAA,EAO1B;IAED,IAAI,sBAAsB,QAEzB;IAED,IAAI,sBAAsB,CAAC,KAAK,KAAA,EAO/B;IAED,IAAI,cAAc;eAzwEY,MAAM;sBAAgB,MAAM;uBAAiB,MAAM;kBAAY,OAAO;uBAAiB,MAAM;oCAA8B,OAAO;MA2wE/J;IAED,IAAI,cAAc,CAAC,KAAK;eA7wEM,MAAM;sBAAgB,MAAM;uBAAiB,MAAM;kBAAY,OAAO;uBAAiB,MAAM;oCAA8B,OAAO;KA6wExI,EAavB;IAED,IAAI,eAAe;aA3xEU;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,eAAe,EAAE,MAAM,CAAA;SAAE;cAAQ;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,eAAe,EAAE,MAAM,CAAA;SAAE;MA6xE1H;IAED,IAAI,eAAe,CAAC,KAAK;aA/xEI;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,eAAe,EAAE,MAAM,CAAA;SAAE;cAAQ;YAAE,KAAK,EAAE,OAAO,CAAC;YAAC,eAAe,EAAE,MAAM,CAAA;SAAE;KA+xElG,EAQxB;CAEJ;AAED,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -27,9 +27,9 @@ import SyncEngine from './sync_engine.js';
|
|
|
27
27
|
import { calculateCurrentSpread, checkSpreadCondition, checkGridHealth } from './grid.js';
|
|
28
28
|
import * as Format from './format.js';
|
|
29
29
|
import { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, DEFAULT_CONFIG, TIMING, LOG_LEVEL, PIPELINE_TIMING, COW_PERFORMANCE, COW_ACTIONS, GRID_LIMITS } from '../constants.js';
|
|
30
|
-
import { getMinOrderSize, computeChainFundTotals, hasValidAccountTotals, resolveConfigValueWithRegistry, isExplicitZeroAllocation, floatToBlockchainInt, validateBoundaryCommit, resolveGapSlots } from './utils/math.js';
|
|
30
|
+
import { getMinOrderSize, computeChainFundTotals, hasValidAccountTotals, resolveConfigValueWithRegistry, isExplicitZeroAllocation, floatToBlockchainInt, validateBoundaryCommit, resolveGapSlots, resolveGapBand, isSlotInRail } from './utils/math.js';
|
|
31
31
|
import { validateOrder, validateGridForPersistence, validateWorkingGridFunds, checkFundDrift, reconcileGrid, optimizeRebalanceActions, projectTargetToWorkingGrid, buildStateUpdates, buildAbortedResult, buildSuccessResult, evaluateCommit } from './utils/validate.js';
|
|
32
|
-
import { resolveSpreadOrderSide, parseSlotIndex, parseChainOrder, geometryTypeForSlotIndex, isOrderOnChain } from './utils/order.js';
|
|
32
|
+
import { resolveSpreadOrderSide, parseSlotIndex, parseChainOrder, geometryTypeForSlotIndex, isOrderOnChain, resolveReserveCount, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds } from './utils/order.js';
|
|
33
33
|
import { getErrorMessage } from '../utils/errors.js';
|
|
34
34
|
const { toFiniteNumber } = Format;
|
|
35
35
|
// ===============================================================================
|
|
@@ -133,7 +133,7 @@ class COWRebalanceEngine {
|
|
|
133
133
|
this.assets = deps.assets;
|
|
134
134
|
this.config = deps.config;
|
|
135
135
|
}
|
|
136
|
-
async execute({ masterGrid, gridVersion, boundaryIdx, funds, fills = [], excludeIds = new Set(), gapSlots = null, evacStreaks = null }) {
|
|
136
|
+
async execute({ masterGrid, gridVersion, boundaryIdx, funds, fills = [], excludeIds = new Set(), gapSlots = null, evacStreaks = null, reserveEdgeAnchors = null }) {
|
|
137
137
|
const startTime = Date.now();
|
|
138
138
|
const workingGrid = new WorkingGrid(masterGrid, { baseVersion: gridVersion });
|
|
139
139
|
const strategyParams = {
|
|
@@ -146,6 +146,27 @@ class COWRebalanceEngine {
|
|
|
146
146
|
currentBoundaryIdx: boundaryIdx
|
|
147
147
|
};
|
|
148
148
|
const { targetGrid, boundaryIdx: targetBoundary } = this.strategy.calculateTargetGrid(strategyParams);
|
|
149
|
+
// P4 / unanchored plan: the strategy returns a null boundary paired
|
|
150
|
+
// with an EMPTY target grid only when no numeric center exists to
|
|
151
|
+
// recover from (e.g. GRID-LOAD rejected the persisted boundary AND
|
|
152
|
+
// startPrice is an unresolved mode string). Planning rotations here
|
|
153
|
+
// would fabricate rail-edge geometry — dust-cancel fills included,
|
|
154
|
+
// even though they deliberately carry isDelayedRotationTrigger when
|
|
155
|
+
// the boundary is known. Route to a structural resync instead of
|
|
156
|
+
// broadcasting. (A null boundary with a non-empty target is a
|
|
157
|
+
// hand-built/boundary-less plan — e.g. unit mocks — and proceeds.)
|
|
158
|
+
if ((targetBoundary === null || targetBoundary === undefined) && targetGrid.size === 0) {
|
|
159
|
+
// A genuinely empty grid (no master orders, no fills) has nothing
|
|
160
|
+
// to heal — plain abort. Anything else is stranded without an
|
|
161
|
+
// anchor and needs a rebuild.
|
|
162
|
+
const needsHeal = (masterGrid?.size ?? 0) > 0 || (fills?.length ?? 0) > 0;
|
|
163
|
+
this.logger?.log('[COW] Plan skipped: boundary unrecoverable (no numeric center)' + (needsHeal ? '; requesting structural resync' : ''), 'warn');
|
|
164
|
+
return {
|
|
165
|
+
...buildAbortedResult('boundary-unrecoverable'),
|
|
166
|
+
evacReady: [],
|
|
167
|
+
...(needsHeal ? { needsResync: true, resyncReason: 'boundary-unrecoverable' } : {}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
149
170
|
let dustThresholdPercent = this.config?.gridLimits?.PARTIAL_DUST_THRESHOLD_PERCENTAGE;
|
|
150
171
|
const reconcileResult = reconcileGrid(masterGrid, targetGrid, targetBoundary, {
|
|
151
172
|
logger: (msg, level) => this.logger?.log(msg, level),
|
|
@@ -194,14 +215,33 @@ class COWRebalanceEngine {
|
|
|
194
215
|
optimizedActions.length = 0;
|
|
195
216
|
optimizedActions.push(...guarded);
|
|
196
217
|
}
|
|
218
|
+
// Rail-edge truncation telemetry: when the planned window runs off
|
|
219
|
+
// the rail (sellStart past the last slot), one side can never place
|
|
220
|
+
// — the Sep-10 signature (boundary 209 on a 216-slot rail left 2
|
|
221
|
+
// sell slots, and the ordinal pairing then teleported the buy rail
|
|
222
|
+
// 113 slots). Warn only: the cross-guard, fund validation and
|
|
223
|
+
// boundary-hold still judge the plan; no geometry is refused here.
|
|
224
|
+
{
|
|
225
|
+
const railSize = targetGrid?.size ?? 0;
|
|
226
|
+
const gap = Number(gapSlots) || 0;
|
|
227
|
+
const sellStart = Number(targetBoundary) + gap + 1;
|
|
228
|
+
if (Number.isFinite(sellStart) && railSize > 0 && sellStart >= railSize) {
|
|
229
|
+
this.logger?.log(`[COW] Rail-edge plan: boundary=${targetBoundary} gap=${gap} rail=${railSize} (sellStart=${sellStart}); window truncated, guards still apply`, 'warn');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
197
232
|
// Refill-slot wire (boundary-hold): surviving hole-CREATEs justify this
|
|
198
233
|
// plan's boundary shift (folded CANCEL+CREATE pairs already became
|
|
199
234
|
// stamped UPDATEs above; stale-dropped placements are excluded — a
|
|
200
235
|
// deferred placement justifies nothing). The executor holds the
|
|
201
236
|
// committed boundary when a listed refill is guard-skipped.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
237
|
+
// Reserve-ladder CREATEs are excluded (collectRefillSlotIds): reserves
|
|
238
|
+
// are static edge insurance and their fills never crawl, so a skipped
|
|
239
|
+
// reserve must not pin geometry either.
|
|
240
|
+
const refillSlotIds = collectRefillSlotIds(optimizedActions, {
|
|
241
|
+
config: this.config,
|
|
242
|
+
slots: masterGrid,
|
|
243
|
+
edgeAnchors: reserveEdgeAnchors
|
|
244
|
+
});
|
|
205
245
|
projectTargetToWorkingGrid(workingGrid, targetGrid, { actions: optimizedActions });
|
|
206
246
|
const precisions = {
|
|
207
247
|
buyPrecision: this.assets?.assetB?.precision,
|
|
@@ -380,12 +420,18 @@ class OrderManager {
|
|
|
380
420
|
_gridDirtyAt;
|
|
381
421
|
_lastStaleTotalsWarnAt;
|
|
382
422
|
_orphanFillsCreditedAt;
|
|
423
|
+
_fundDriftLedger;
|
|
383
424
|
_pendingRecovery;
|
|
425
|
+
_pendingFillCrawls;
|
|
384
426
|
_recentFillKeysSnapshot;
|
|
385
427
|
_lastFilledBuyPrice;
|
|
386
428
|
_lastFilledSellPrice;
|
|
387
429
|
_lastFilledPrice;
|
|
388
430
|
_lastFilledType;
|
|
431
|
+
_lastFilledAt;
|
|
432
|
+
_deferredRebalanceAt;
|
|
433
|
+
_lastHeldPlanSignature;
|
|
434
|
+
_lastBoundaryHoldResyncAt;
|
|
389
435
|
_gapEvacStreaks;
|
|
390
436
|
_gapEvacCancelQueued;
|
|
391
437
|
// anchor fields removed
|
|
@@ -493,13 +539,19 @@ class OrderManager {
|
|
|
493
539
|
this._gapSlots = 0;
|
|
494
540
|
this._gridDirtyAt = null;
|
|
495
541
|
this._orphanFillsCreditedAt = null;
|
|
542
|
+
this._fundDriftLedger = null;
|
|
496
543
|
this._pendingRecovery = null;
|
|
544
|
+
this._pendingFillCrawls = [];
|
|
497
545
|
this._recentFillKeysSnapshot = null;
|
|
498
546
|
this._lastStaleTotalsWarnAt = {};
|
|
499
547
|
this._lastFilledBuyPrice = null;
|
|
500
548
|
this._lastFilledSellPrice = null;
|
|
501
549
|
this._lastFilledPrice = null;
|
|
502
550
|
this._lastFilledType = null;
|
|
551
|
+
this._lastFilledAt = 0;
|
|
552
|
+
this._deferredRebalanceAt = 0;
|
|
553
|
+
this._lastHeldPlanSignature = null;
|
|
554
|
+
this._lastBoundaryHoldResyncAt = 0;
|
|
503
555
|
this._gapEvacStreaks = new Map();
|
|
504
556
|
this._gapEvacCancelQueued = new Set();
|
|
505
557
|
this._metrics = {
|
|
@@ -645,6 +697,11 @@ class OrderManager {
|
|
|
645
697
|
// The caller is released from the refcount contract.
|
|
646
698
|
this._broadcastingFlag = 0;
|
|
647
699
|
this._broadcastingStartedAt = 0;
|
|
700
|
+
// A leaked flag never reaches stopBroadcasting, so wake the same
|
|
701
|
+
// region-end listeners it would have: without this, fills
|
|
702
|
+
// enqueued during the hung region are stranded until the next
|
|
703
|
+
// fill event even though the flag is now clear.
|
|
704
|
+
this._fireBroadcastRegionEnd();
|
|
648
705
|
}
|
|
649
706
|
}
|
|
650
707
|
}
|
|
@@ -717,8 +774,26 @@ class OrderManager {
|
|
|
717
774
|
// this flag is held and its defer branch returns without
|
|
718
775
|
// rescheduling, so fills enqueued during a long region would
|
|
719
776
|
// starve indefinitely. Fire once when the last region ends.
|
|
777
|
+
this._fireBroadcastRegionEnd();
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Notify runtime listeners that the last broadcast/placement region ended.
|
|
782
|
+
* Called from stopBroadcasting (refcount -> 0) and the stale-flag watchdog
|
|
783
|
+
* (a leaked flag hard-reset to 0). The fill consumer's defer branch returns
|
|
784
|
+
* without rescheduling, so this is the only wake-up for fills enqueued
|
|
785
|
+
* during a region; the watchdog path must fire it too or a hung broadcast's
|
|
786
|
+
* queued fills wait for the next fill event.
|
|
787
|
+
* Guarded so a listener error never escapes into a finally/watchdog frame.
|
|
788
|
+
* @returns {void}
|
|
789
|
+
*/
|
|
790
|
+
_fireBroadcastRegionEnd() {
|
|
791
|
+
try {
|
|
720
792
|
this._onBroadcastRegionEnd?.();
|
|
721
793
|
}
|
|
794
|
+
catch (err) {
|
|
795
|
+
this.logger?.log?.(`[BROADCAST] Region-end hook failed: ${err?.message || err}`, 'warn');
|
|
796
|
+
}
|
|
722
797
|
}
|
|
723
798
|
/**
|
|
724
799
|
* Reset funds structure to zeroed values. Acquires _fundLock so the
|
|
@@ -1147,7 +1222,14 @@ class OrderManager {
|
|
|
1147
1222
|
if (options === null || typeof options !== 'object' || Array.isArray(options)) {
|
|
1148
1223
|
throw new TypeError('Commit options must be an object');
|
|
1149
1224
|
}
|
|
1150
|
-
return {
|
|
1225
|
+
return {
|
|
1226
|
+
skipRecalc: options.skipRecalc === true,
|
|
1227
|
+
// Set by the COW refill hold: the boundary passed to this commit is
|
|
1228
|
+
// the COMMITTED value, not the plan's target, so nothing was
|
|
1229
|
+
// derived into it and owed fill crawls must survive (see the
|
|
1230
|
+
// pending-crawl bookkeeping in _commitWorkingGrid).
|
|
1231
|
+
boundaryHeld: options.boundaryHeld === true
|
|
1232
|
+
};
|
|
1151
1233
|
}
|
|
1152
1234
|
async _updateOrder(order, context = 'updateOrder', options = {}) {
|
|
1153
1235
|
const updateOptions = this._normalizeOrderUpdateOptions(options);
|
|
@@ -1354,14 +1436,23 @@ class OrderManager {
|
|
|
1354
1436
|
* @param {Object} [options]
|
|
1355
1437
|
* @returns {Promise<any>}
|
|
1356
1438
|
*/
|
|
1357
|
-
async processFilledOrders(orders, excl,
|
|
1439
|
+
async processFilledOrders(orders, excl, options = {}) {
|
|
1358
1440
|
// Step 1: Handle Fills (Accounting & State Updates)
|
|
1359
1441
|
await this.strategy.processFillsOnly(orders, excl);
|
|
1360
1442
|
// Step 2: Trigger Safe Rebalance only for actual fills.
|
|
1361
1443
|
const triggerFills = orders.filter((f) => !f.isPartial || f.isDelayedRotationTrigger);
|
|
1362
1444
|
const shouldRebalance = triggerFills.length > 0;
|
|
1363
1445
|
if (shouldRebalance) {
|
|
1364
|
-
|
|
1446
|
+
// deferIfBroadcasting: fill processing runs under
|
|
1447
|
+
// _fillProcessingLock, and _awaitBroadcastIdle can sleep 30s —
|
|
1448
|
+
// beyond the lock's 20s acquisition timeout. Defer the rebalance
|
|
1449
|
+
// instead of waiting in-lock; processFillsOnly already recorded
|
|
1450
|
+
// the boundary crawls, so a later derivation applies them. The
|
|
1451
|
+
// region-end hook schedules the deferred rebalance.
|
|
1452
|
+
const rebalanceResult = await this.performSafeRebalance(orders, excl, {
|
|
1453
|
+
...(options || {}),
|
|
1454
|
+
deferIfBroadcasting: true
|
|
1455
|
+
});
|
|
1365
1456
|
// Carry the fill set + exclusions on the result so the COW batch
|
|
1366
1457
|
// executor can re-plan once from fresh master if the plan goes
|
|
1367
1458
|
// stale between planning and broadcast.
|
|
@@ -1396,11 +1487,20 @@ class OrderManager {
|
|
|
1396
1487
|
const buyPrecision = this.assets?.assetB?.precision;
|
|
1397
1488
|
const minSellSizeInt = floatToBlockchainInt(minSellSize, sellPrecision);
|
|
1398
1489
|
const minBuySizeInt = floatToBlockchainInt(minBuySize, buyPrecision);
|
|
1490
|
+
// Rail membership by geometry (shared isSlotInRail), mirroring the
|
|
1491
|
+
// reconcile pickers (_pickVirtualSlotsToActivate / _pickEdgeReserveSlots).
|
|
1492
|
+
// A freshly generated grid's roles never need this, but the gate keeps
|
|
1493
|
+
// the startup placement path and the runtime activation path from
|
|
1494
|
+
// diverging: a slot whose stored type is stale relative to the current
|
|
1495
|
+
// boundary must not be placed on the wrong rail.
|
|
1496
|
+
const resolved = resolveGapBand(this);
|
|
1497
|
+
const inRailFor = (type, o) => isSlotInRail(resolved.boundaryIdx, resolved.gapSlots, type, o);
|
|
1399
1498
|
// Get closest virtual sells (lowest prices first = closest to market),
|
|
1400
1499
|
// selecting up to sellCount orders that pass the minimum-size filter.
|
|
1401
1500
|
// Scan the full sorted rail instead of slicing first so sub-min slots
|
|
1402
1501
|
// don't consume activation budget (mirrors _pickVirtualSlotsToActivate).
|
|
1403
1502
|
const sellsClosestFirst = this.getOrdersByTypeAndState(ORDER_TYPES.SELL, ORDER_STATES.VIRTUAL)
|
|
1503
|
+
.filter((o) => inRailFor(ORDER_TYPES.SELL, o))
|
|
1404
1504
|
.sort((a, b) => a.price - b.price);
|
|
1405
1505
|
const validSells = [];
|
|
1406
1506
|
for (const o of sellsClosestFirst) {
|
|
@@ -1415,6 +1515,7 @@ class OrderManager {
|
|
|
1415
1515
|
// Get closest virtual buys (highest prices first = closest to market),
|
|
1416
1516
|
// selecting up to buyCount orders that pass the minimum-size filter.
|
|
1417
1517
|
const buysClosestFirst = this.getOrdersByTypeAndState(ORDER_TYPES.BUY, ORDER_STATES.VIRTUAL)
|
|
1518
|
+
.filter((o) => inRailFor(ORDER_TYPES.BUY, o))
|
|
1418
1519
|
.sort((a, b) => b.price - a.price);
|
|
1419
1520
|
const validBuys = [];
|
|
1420
1521
|
for (const o of buysClosestFirst) {
|
|
@@ -1426,7 +1527,37 @@ class OrderManager {
|
|
|
1426
1527
|
}
|
|
1427
1528
|
// Reverse for placement order (lowest first)
|
|
1428
1529
|
validBuys.sort((a, b) => a.price - b.price);
|
|
1429
|
-
|
|
1530
|
+
// Reserve ladder: edge-pinned orders activate alongside the window
|
|
1531
|
+
// without consuming its budget. Buys pin at the floor (lowest first),
|
|
1532
|
+
// sells at the ceiling (highest first). Same min-size gate as the window.
|
|
1533
|
+
const pickEdgeReserves = (orderType, count, windowed, precision, minSizeInt, ascending) => {
|
|
1534
|
+
const picked = [];
|
|
1535
|
+
if (count <= 0)
|
|
1536
|
+
return picked;
|
|
1537
|
+
const windowedIds = new Set(windowed.map((o) => o.id));
|
|
1538
|
+
// Both edges anchor at the live grid's own edge (ladder/rail extreme).
|
|
1539
|
+
const edgeAnchor = resolveLiveReserveEdgeAnchorPrice(this, ascending ? 'buy' : 'sell');
|
|
1540
|
+
const edge = ascending ? 'floor' : 'ceiling';
|
|
1541
|
+
const edgeFirst = this.getOrdersByTypeAndState(orderType, ORDER_STATES.VIRTUAL)
|
|
1542
|
+
.filter((o) => inRailFor(orderType, o))
|
|
1543
|
+
.filter((o) => parseSlotIndex(o.id) !== null)
|
|
1544
|
+
.sort((a, b) => compareReserveEdge(a, b, edge, edgeAnchor));
|
|
1545
|
+
for (const o of edgeFirst) {
|
|
1546
|
+
if (picked.length >= count)
|
|
1547
|
+
break;
|
|
1548
|
+
if (windowedIds.has(o.id))
|
|
1549
|
+
continue;
|
|
1550
|
+
if (floatToBlockchainInt(o.size, precision) >= minSizeInt) {
|
|
1551
|
+
picked.push(o);
|
|
1552
|
+
windowedIds.add(o.id);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
picked.sort((a, b) => ascending ? a.price - b.price : b.price - a.price);
|
|
1556
|
+
return picked;
|
|
1557
|
+
};
|
|
1558
|
+
const reserveBuys = pickEdgeReserves(ORDER_TYPES.BUY, resolveReserveCount(this.config, 'buy'), validBuys, buyPrecision, minBuySizeInt, true);
|
|
1559
|
+
const reserveSells = pickEdgeReserves(ORDER_TYPES.SELL, resolveReserveCount(this.config, 'sell'), validSells, sellPrecision, minSellSizeInt, false);
|
|
1560
|
+
return [...validSells, ...reserveSells, ...validBuys, ...reserveBuys];
|
|
1430
1561
|
}
|
|
1431
1562
|
/**
|
|
1432
1563
|
* Get orders matching the specified type and state.
|
|
@@ -1479,6 +1610,34 @@ class OrderManager {
|
|
|
1479
1610
|
this.boundaryIdx = newIdx;
|
|
1480
1611
|
this._logBoundaryDebug('restore', newIdx);
|
|
1481
1612
|
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Drop owed fill-crawl records (boundary bookkeeping).
|
|
1615
|
+
*
|
|
1616
|
+
* Records are pushed per shift-eligible fill at intake and consumed when a
|
|
1617
|
+
* derivation commits them. They must be dropped only when the crawl they
|
|
1618
|
+
* encode has been applied — an accepted commit that used the PLAN's target
|
|
1619
|
+
* boundary (or an absolute fill anchor that subsumes every owed delta).
|
|
1620
|
+
* A held boundary (refill guard skip), a gate-rejected boundary, and a
|
|
1621
|
+
* null boundary all leave the records owed, so they are not dropped there.
|
|
1622
|
+
*
|
|
1623
|
+
* Also used when the boundary is (re)anchored outside the fill path (grid
|
|
1624
|
+
* reset / recenter / rejected-snapshot rebuild): those records belong to
|
|
1625
|
+
* the previous generation, and applying their relative deltas onto a fresh
|
|
1626
|
+
* anchor would double-count movement the anchor already contains.
|
|
1627
|
+
*
|
|
1628
|
+
* Marks the grid dirty so the cleared array reaches disk even on paths
|
|
1629
|
+
* that do not otherwise persist.
|
|
1630
|
+
*
|
|
1631
|
+
* @param {string} reason - Log/debug label for the drop
|
|
1632
|
+
*/
|
|
1633
|
+
_clearPendingFillCrawls(reason = 'unspecified') {
|
|
1634
|
+
if (!Array.isArray(this._pendingFillCrawls) || this._pendingFillCrawls.length === 0)
|
|
1635
|
+
return;
|
|
1636
|
+
const count = this._pendingFillCrawls.length;
|
|
1637
|
+
this._pendingFillCrawls = [];
|
|
1638
|
+
this._markGridDirty();
|
|
1639
|
+
this.logger?.log?.(`[BOUNDARY] Dropped ${count} owed fill crawl(s) (${reason})`, 'debug');
|
|
1640
|
+
}
|
|
1482
1641
|
/**
|
|
1483
1642
|
* Observability (fix #4, docs/CONSOLIDATED_ORPHAN_FIX_SUMMARY.md §2): emit the live
|
|
1484
1643
|
* boundary whenever roles are (re)assigned, so a silent boundary crawl that
|
|
@@ -1549,6 +1708,7 @@ class OrderManager {
|
|
|
1549
1708
|
this._lastFilledBuyPrice = price;
|
|
1550
1709
|
else if (f.type === ORDER_TYPES.SELL)
|
|
1551
1710
|
this._lastFilledSellPrice = price;
|
|
1711
|
+
this._lastFilledAt = Date.now();
|
|
1552
1712
|
recorded++;
|
|
1553
1713
|
lastKind = f?.isPartial === true ? 'partial' : (f?.isPartial === false ? 'full' : 'unknown');
|
|
1554
1714
|
lastPriceSrc = priceSrc;
|
|
@@ -1913,11 +2073,44 @@ class OrderManager {
|
|
|
1913
2073
|
async performSafeRebalance(fills = [], excludeIds = new Set(), options = {}) {
|
|
1914
2074
|
this.logger.log("[SAFE-REBALANCE] Starting with COW...", "info");
|
|
1915
2075
|
if (!options?.skipBroadcastWait) {
|
|
1916
|
-
|
|
1917
|
-
|
|
2076
|
+
// Shutdown guard applies to every path here (including the
|
|
2077
|
+
// deferIfBroadcasting defer path, which never reaches
|
|
2078
|
+
// _awaitBroadcastIdle): a rebalance must not plan/broadcast while
|
|
2079
|
+
// the bot is shutting down. _awaitBroadcastIdle returns
|
|
2080
|
+
// shutdown:true for this, so keep it explicit when skipping it.
|
|
2081
|
+
if (this._shuttingDown) {
|
|
1918
2082
|
this.logger.log('[SAFE-REBALANCE] Aborting rebalance: shutdown in progress', 'warn');
|
|
1919
2083
|
return buildAbortedResult('Shutdown in progress — safe rebalance aborted');
|
|
1920
2084
|
}
|
|
2085
|
+
// Never sleep on the broadcast flag while holding
|
|
2086
|
+
// _fillProcessingLock (the lock's acquisition timeout is 20s; the
|
|
2087
|
+
// wait is 30s). A fill-driven rebalance defers instead, leaving
|
|
2088
|
+
// the crawls recorded by processFillsOnly for a later derivation.
|
|
2089
|
+
if (options?.deferIfBroadcasting && this.isBroadcastingActive()) {
|
|
2090
|
+
this.logger.log('[SAFE-REBALANCE] Deferred: broadcast/placement activity active; rebalance retries after the region ends', 'info');
|
|
2091
|
+
this._deferredRebalanceAt = Date.now();
|
|
2092
|
+
return { ...buildAbortedResult('broadcast-active-deferred'), deferred: true };
|
|
2093
|
+
}
|
|
2094
|
+
// Identical-held-plan suppression: a fill-less replan whose
|
|
2095
|
+
// boundary, guard pivot and fill timestamp are unchanged since the
|
|
2096
|
+
// last hold can only reproduce the same vetoed plan (INV-COW-007).
|
|
2097
|
+
// Defer instead of spending another broadcast region re-deriving
|
|
2098
|
+
// it; a fresh fill changes _lastFilledAt and re-enables planning.
|
|
2099
|
+
const heldSig = this._lastHeldPlanSignature;
|
|
2100
|
+
if (fills.length === 0 && heldSig
|
|
2101
|
+
&& Number(this.boundaryIdx) === Number(heldSig.boundaryIdx)
|
|
2102
|
+
&& Number(this._lastFilledPrice) === Number(heldSig.pivot)
|
|
2103
|
+
&& Number(this._lastFilledAt) === Number(heldSig.fillsAt)) {
|
|
2104
|
+
this.logger.log('[SAFE-REBALANCE] Deferred: identical held plan (no new fills since last hold); a fill-driven plan will re-derive', 'debug');
|
|
2105
|
+
return { ...buildAbortedResult('held-plan-unchanged-deferred'), deferred: true };
|
|
2106
|
+
}
|
|
2107
|
+
if (!options?.deferIfBroadcasting) {
|
|
2108
|
+
const idle = await this._awaitBroadcastIdle();
|
|
2109
|
+
if (idle.shutdown || this._shuttingDown) {
|
|
2110
|
+
this.logger.log('[SAFE-REBALANCE] Aborting rebalance: shutdown in progress', 'warn');
|
|
2111
|
+
return buildAbortedResult('Shutdown in progress — safe rebalance aborted');
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
1921
2114
|
}
|
|
1922
2115
|
return await this._gridLock.acquire(async () => {
|
|
1923
2116
|
return await this._applySafeRebalanceCOW(fills, excludeIds);
|
|
@@ -1933,6 +2126,13 @@ class OrderManager {
|
|
|
1933
2126
|
this._gapEvacStreaks = new Map();
|
|
1934
2127
|
if (!(this._gapEvacCancelQueued instanceof Set))
|
|
1935
2128
|
this._gapEvacCancelQueued = new Set();
|
|
2129
|
+
// Live reserve edge anchors, resolved once and shared with the engine's
|
|
2130
|
+
// refill wire so a reserve-ladder CREATE can never be classified as a
|
|
2131
|
+
// hole refill (which would let a skipped reserve pin the boundary).
|
|
2132
|
+
const reserveEdgeAnchors = {
|
|
2133
|
+
buy: resolveLiveReserveEdgeAnchorPrice(this, 'buy'),
|
|
2134
|
+
sell: resolveLiveReserveEdgeAnchorPrice(this, 'sell')
|
|
2135
|
+
};
|
|
1936
2136
|
const result = await cowEngine.execute({
|
|
1937
2137
|
masterGrid: this.orders,
|
|
1938
2138
|
gridVersion: this._gridVersion,
|
|
@@ -1941,7 +2141,8 @@ class OrderManager {
|
|
|
1941
2141
|
fills,
|
|
1942
2142
|
excludeIds,
|
|
1943
2143
|
gapSlots: this._gapSlots,
|
|
1944
|
-
evacStreaks: this._gapEvacStreaks
|
|
2144
|
+
evacStreaks: this._gapEvacStreaks,
|
|
2145
|
+
reserveEdgeAnchors
|
|
1945
2146
|
});
|
|
1946
2147
|
// Phase 3 safety net: act on stuck in-band orders regardless of the
|
|
1947
2148
|
// plan outcome — a plan that aborted for unrelated reasons must not
|
|
@@ -2011,7 +2212,7 @@ class OrderManager {
|
|
|
2011
2212
|
}
|
|
2012
2213
|
};
|
|
2013
2214
|
try {
|
|
2014
|
-
const { skipRecalc: skipRecalcOpt } = this._normalizeCommitOptions(options);
|
|
2215
|
+
const { skipRecalc: skipRecalcOpt, boundaryHeld } = this._normalizeCommitOptions(options);
|
|
2015
2216
|
skipRecalc = skipRecalcOpt;
|
|
2016
2217
|
const stats = workingGrid.getMemoryStats();
|
|
2017
2218
|
try {
|
|
@@ -2074,6 +2275,22 @@ class OrderManager {
|
|
|
2074
2275
|
}
|
|
2075
2276
|
this.orders = Object.freeze(finalMap);
|
|
2076
2277
|
this._setBoundary(commitBoundary);
|
|
2278
|
+
// Pending-crawl bookkeeping: an accepted non-null commit
|
|
2279
|
+
// incorporates (incremental derivation) or subsumes (absolute
|
|
2280
|
+
// recovery anchor) every fill recorded so far, so all pending
|
|
2281
|
+
// crawl entries are consumed here. A gate-rejected commit keeps
|
|
2282
|
+
// the previous boundary — nothing was derived into it — so
|
|
2283
|
+
// pending entries survive for the next derivation. A null
|
|
2284
|
+
// commit likewise consumes nothing, and neither does a HELD
|
|
2285
|
+
// boundary (boundaryHeld): the refill hold deliberately keeps
|
|
2286
|
+
// the committed boundary over the plan's target, so the shift
|
|
2287
|
+
// those records encode was never applied and must stay owed —
|
|
2288
|
+
// clearing here lost the crawl permanently (no fill evidence
|
|
2289
|
+
// left for the next derivation, holes refilled same-side).
|
|
2290
|
+
if (boundaryCheck.ok && commitBoundary !== null && commitBoundary !== undefined
|
|
2291
|
+
&& boundaryHeld !== true) {
|
|
2292
|
+
this._clearPendingFillCrawls('boundary commit');
|
|
2293
|
+
}
|
|
2077
2294
|
this._gridVersion++;
|
|
2078
2295
|
committed = true;
|
|
2079
2296
|
// Track orderIds from successful COW commits for recovery sync protection.
|