Skip to content

fix(liquidity): keep activation debounce across drain chunks#4337

Merged
TaprootFreak merged 4 commits into
developfrom
fix/lm-activation-delay-per-chunk
Jul 23, 2026
Merged

fix(liquidity): keep activation debounce across drain chunks#4337
TaprootFreak merged 4 commits into
developfrom
fix/lm-activation-delay-per-chunk

Conversation

@TaprootFreak

@TaprootFreak TaprootFreak commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

verifyRule cleared the rule's activation-debounce timer (ruleActivations) unconditionally right before executeRule. After each pipeline completes and the rule returns to Active, the next cron cycle re-arms the timer and must 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 (~15 min), turning a large offload into a multi-hour trickle.

Fix

  • Remove the unconditional ruleActivations.delete before executeRule. The timer is armed once when the condition first appears and cleared only when the condition resolves (the else branch). Follow-up chunks of an ongoing drain then fire at the normal every-minute cadence.
  • Clear the timer at the actual pause transition: handlePipelineFail calls a new resetActivation(ruleId) on the liquidity service right after rule.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.

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.
@TaprootFreak

Copy link
Copy Markdown
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 verifyRule had a race with the manual reactivation endpoint; the reset was moved to the actual pause transition (handlePipelineFail), which causally precedes any reactivation. Pass 3: zero findings on both conformance and logic, verified against the module's tests.

@TaprootFreak
TaprootFreak marked this pull request as ready for review July 23, 2026 13:25
@TaprootFreak
TaprootFreak merged commit 514a912 into develop Jul 23, 2026
8 checks passed
@TaprootFreak
TaprootFreak deleted the fix/lm-activation-delay-per-chunk branch July 23, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant