LOW severity: [LOGLAB-18] $.pendingDecreaseCollateral variable will be updated incorrectly if the agent executes an insufficient response, leading to an imbalance in the strategy after unpausing. **Severity:** Medium

**Path:** src/strategy/BasisStrategy.sol#L946-L966, src/strategy/BasisStrategy.sol#L578-L590, src/strategy/BasisStrategy.sol#L590-L609

**Description:** When the agent executes the deutilize request with an insufficient response, the `_afterDecreasePosition()` function will...

Vulnerable code:
function _afterDecreasePosition(IHedgeManager.AdjustPositionPayload calldata responseParams)   
    [...]
    (bool exceedsThreshold, int256 sizeDeviation) = _checkDeviation(
        responseParams.sizeDeltaInTokens, requestParams.sizeDeltaInTokens, _responseDeviationThreshold
    );
    if (exceedsThreshold) {
        shouldPause = true;
        if (sizeDeviation < 0) {
            uint256 sizeDeviationAbs = uint256(-sizeDeviation);
            uint256 assetsToBeReverted;
            if (sizeDeviationAbs == requestParams.sizeDeltaInTokens) {
                assetsToBeReverted = _pendingDeutilizedAssets;
            } else {
                assetsToBeReverted =
                    _pendingDeutilizedAssets.mulDiv(sizeDeviationAbs, requestParams.sizeDeltaInTokens);
            }
            if (assetsToBeReverted > 0) {
                ISpotManager _spotManager = $.spotManager;
                _asset.safeTransfer(address(_spotManager), assetsToBeReverted);
                _spotManager.buy(assetsToBeReverted, ISpotManager.SwapType.MANUAL, "");
            }
        }
    }
    [...]
    if (requestParams.collateralDeltaAmount > 0) {
        (bool exceedsThreshold,) = _checkDeviation(
            responseParams.collateralDeltaAmount, requestParams.collateralDeltaAmount, _responseDeviationThreshold
        );
        shouldPause = exceedsThreshold;
    }

if ($.vault.totalSupply() == 0 || ISpotManager(_msgSender()).exposure() == 0) {
    // in case of redeeming all by users,
    // or selling out all product
    // close hedge position
    sizeDeltaInTokens = type(uint256).max;
    collateralDeltaAmount = type(uint256).max;
    $.pendingDecreaseCollateral = 0;
} else if (status == StrategyStatus.FULL_DEUTILIZING) {
    (uint256 min,) = $.hedgeManager.decreaseCollateralMinMax();
    uint256 pendingWithdraw = assetsToDeutilize();
    collateralDeltaAmount = min > pendingWithdraw ? min : pendingWithdraw;
    $.pendingDecreaseCollateral = 0;
}

else {
    // when partial deutilizing
    IHedgeManager _hedgeManager = $.hedgeManager;
    uint256 positionNetBalance = _hedgeManager.positionNetBalance();
    uint256 _pendingDecreaseCollateral = $.pendingDecreaseCollateral;
    if (_pendingDecreaseCollateral > 0) {
        (, positionNetBalance) = positionNetBalance.trySub(_pendingDecreaseCollateral);
    }
    uint256 positionSizeInTokens = _hedgeManager.positionSizeInTokens();
    uint256 collateralDeltaToDecrease =
        positionNetBalance.mulDiv(productDelta, positionSizeInTokens);
    collateralDeltaToDecrease += _pendingDecreaseCollateral;
    uint256 limitDecreaseCollateral = _hedgeManager.limitDecreaseCollateral();
    if (collateralDeltaToDecrease < limitDecreaseCollateral) {
        $.pendingDecreaseCollateral = collateralDeltaToDecrease;
    } else {
        collateralDeltaAmount = collateralDeltaToDecrease;
    }
}