fix(liquidity): keep activation debounce across drain chunks#4337
Merged
Conversation
verifyRule cleared the rule's activation-debounce timer (ruleActivations) unconditionally right before executeRule. After each pipeline completed and the rule returned to Active, the next cron cycle re-armed the timer and had to wait the full lmActivationDelay again before the next chunk. For a redundancy rule whose orders are liquidity-capped (best-price chunk, e.g. an exchange sell), this serialized the drain to one chunk per delay, turning a large offload into a multi-hour trickle. Arm the timer once when the condition first appears and clear it only when the condition resolves (else branch); follow-up chunks then fire at the normal every-minute cadence. Also clear the timer when a rule is Paused so a rule paused by a failed pipeline re-debounces on reactivation — deliberately not for other non-active states, notably Processing (occurs between chunks).
Regression tests for verifyRule's ruleActivations behaviour: the timer persists across a drain chunk (Active + ongoing condition), is cleared on Paused so a failed-then-reactivated rule re-debounces, and is kept while Processing between chunks. Verified to fail if either fix is reverted.
…rifyRule The earlier verifyRule guard cleared the activation-debounce timer only when the every-minute cron observed the rule Paused. A manual reactivation (reactivateRule) can flip Paused -> Active in a different service before that tick, letting a just-failed rule skip the debounce with a stale timestamp. Move the reset to the actual pause transition: handlePipelineFail now calls a new resetActivation(ruleId) on the liquidity service right after rule.pause(). Revert the verifyRule non-active guard to its original form. Covers manual and cron reactivation alike. Tests updated; adds a handlePipelineFail spec.
Collaborator
Author
|
Three review passes to reach zero findings. Pass 1 flagged missing regression coverage for the debounce invariant (added). Pass 2 found that clearing the timer inside |
TaprootFreak
marked this pull request as ready for review
July 23, 2026 13:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
verifyRulecleared the rule's activation-debounce timer (ruleActivations) unconditionally right beforeexecuteRule. After each pipeline completes and the rule returns toActive, the next cron cycle re-arms the timer and must wait the fulllmActivationDelayagain — before the next chunk. For a redundancy rule whose orders are liquidity-capped (best-price chunk, e.g. an exchange sell), this serialized the drain to one chunk per delay (~15 min), turning a large offload into a multi-hour trickle.Fix
ruleActivations.deletebeforeexecuteRule. The timer is armed once when the condition first appears and cleared only when the condition resolves (theelsebranch). Follow-up chunks of an ongoing drain then fire at the normal every-minute cadence.handlePipelineFailcalls a newresetActivation(ruleId)on the liquidity service right afterrule.pause(), so a rule paused by a failed pipeline re-debounces on its next activation — regardless of whether reactivation happens via the cron or the manual admin endpoint. (.pause()has exactly one call site, so this covers every pause.)Behaviour is unchanged for rules that satisfy their need in a single pipeline and for deficit paths. Adds regression tests for the debounce invariant and the pause→reset wiring. Verified locally:
tsc, eslint, jest.