Code review comment: This is created after decoding the org and name values. So I guess `pkg.packageID` and `currentPkgId` could be different

Code under review:
private void rewriteAsyncInvocations(BIRFunction func, BIRTypeDefinition attachedTypeDef, BIRPackage pkg) {
        PackageID packageID = pkg.packageID;
        Name org = new Name(IdentifierUtils.decodeIdentifier(packageID.orgName.getValue()));
        Name module = new Name(IdentifierUtils.decodeIdentifier(packageID.name.getValue()));
        PackageID currentPkgId = new PackageID(org, module, packageID.version);
        BSymbol functionOwner;
        List<BIRFunction> scopeFunctionsList;
        if (attachedTypeDef == null) {
            functionOwner = packageCache.getSymbol(currentPkgId);
            scopeFunctionsList = pkg.functions;
        } else {
            functionOwner = attachedTypeDef.type.tsymbol;
            scopeFunctionsList = attachedTypeDef.attachedFuncs;
        }
        for (BIRBasicBlock currentBB : func.basicBlocks) {
            if (currentBB.terminator.kind != InstructionKind.ASYNC_CALL
                    || !isObservable((AsyncCall) currentBB.terminator)) {
                continue;
            }

            AsyncCall asyncCallIns = (AsyncCall) currentBB.terminator;
            /*
             * The wrapper function generated below invokes the actual function synchronously, allowing the
             * instrumentation to record the actual start and end times of the function. The wrapper function
             * is invoked asynchronously preserving the asynchronous behaviour.
             */

            
            BType returnType = ((BFutureType) asyncCallIns.lhsOp.variableDcl.type).constraint;
            List<BType> argTypes = asyncCallIns.args.stream()
                    .map(arg -> arg.variableDcl.type)
                    .collect(Collectors.toList());
            Name lambdaName = new Name(String.format("$lambda$observability%d$%s", lambdaIndex++,
                    asyncCallIns.name.value.replace(".", "_")));
            BInvokableType bInvokableType = new BInvokableType(argTypes, null,
                                                               returnType, null);
            BIRFunction desugaredFunc = new BIRFunction(asyncCallIns.pos, lambdaName, 0, bInvokableType,
                                                        func.workerName, 0, null, VIRTUAL);
            desugaredFunc.receiver = func.receiver;
            scopeFunctionsList.add(desugaredFunc);

            
            BIRVariableDcl funcReturnVariableDcl = new BIRVariableDcl(returnType,
                    new Name(String.format("$%s$retVal", lambdaName.value)), VarScope.FUNCTION, VarKind.RETURN);
            BIROperand funcReturnOperand = new BIROperand(funcReturnVariableDcl);
            desugaredFunc.localVars.add(funcReturnVariableDcl);
            desugaredFunc.returnVariable = funcReturnVariableDcl;

            
            BInvokableSymbol invokableSymbol = new BInvokableSymbol(SymTag.FUNCTION, 0, lambdaName,
                                                                    currentPkgId, bInvokableType, functionOwner,
                                                                    desugaredFunc.pos, VIRTUAL);
            invokableSymbol.retType = funcReturnVariableDcl.type;
            invokableSymbol.kind = SymbolKind.FUNCTION;
            invokableSymbol.params = asyncCallIns.args.stream()
                    .map(arg -> new BVarSymbol(0, arg.variableDcl.name, currentPkgId, arg.variableDcl.type,
                                               invokableSymbol, arg.pos, VIRTUAL))
                    .collect(Collectors.toList());
            invokableSymbol.scope = new Scope(invokableSymbol);
            invokableSymbol.params.forEach(param -> invokableSymbol.scope.define(param.name, param));
            if (attachedTypeDef == null) {
                functionOwner.scope.define(lambdaName, invokableSymbol);
            }

            
            List<BIROperand> funcParamOperands = new ArrayList<>();
            Name selfArgName = new Name("%self");
            for (int i = 0; i < asyncCallIns.args.size(); i++) {
                BIROperand arg = asyncCallIns.args.get(i);
                BIRFunctionParameter funcParam;
                if (arg.variableDcl.kind == VarKind.SELF) {
                    funcParam = new BIRFunctionParameter(asyncCallIns.pos, arg.variableDcl.type, selfArgName,
                            VarScope.FUNCTION, VarKind.SELF, selfArgName.value, false);
                } else {
                    Name argName = new Name(String.format("$funcParam%d", i));
                    funcParam = new BIRFunctionParameter(asyncCallIns.pos, arg.variableDcl.type,
                            argName, VarScope.FUNCTION, VarKind.ARG, argName.value, false);
                    desugaredFunc.localVars.add(funcParam);
                    desugaredFunc.parameters.put(funcParam, Collections.emptyList());
                    desugaredFunc.requiredParams.add(new BIRParameter(asyncCallIns.pos, argName, 0));
                    desugaredFunc.argsCount++;
                }
                funcParamOperands.add(new BIROperand(funcParam));
            }

            
            BIRBasicBlock callInsBB = insertBasicBlock(desugaredFunc, 0);
            BIRBasicBlock returnInsBB = insertBasicBlock(desugaredFunc, 1);
            callInsBB.terminator = new Call(asyncCallIns.pos, InstructionKind.CALL, asyncCallIns.isVirtual,
                    asyncCallIns.calleePkg, asyncCallIns.name, funcParamOperands, funcReturnOperand,
                    returnInsBB, asyncCallIns.calleeAnnotAttachments, asyncCallIns.calleeFlags);
            returnInsBB.terminator = new Return(asyncCallIns.pos);

            
            asyncCallIns.name = lambdaName;
            asyncCallIns.calleePkg = currentPkgId;
            asyncCallIns.isVirtual = attachedTypeDef != null;
            if (attachedTypeDef != null) {
                asyncCallIns.args.add(0, new BIROperand(new BIRVariableDcl(attachedTypeDef.type,
                        selfArgName, VarScope.FUNCTION, VarKind.SELF)));
            }
        }
    }

Line commented on: List<BIRFunction> scopeFunctionsList;

Revised code:
private void rewriteAsyncInvocations(BIRFunction func, BIRTypeDefinition attachedTypeDef, BIRPackage pkg) {
        PackageID packageID = pkg.packageID;
        Name org = new Name(IdentifierUtils.decodeIdentifier(packageID.orgName.getValue()));
        Name module = new Name(IdentifierUtils.decodeIdentifier(packageID.name.getValue()));
        PackageID currentPkgId = new PackageID(org, module, packageID.version);
        BSymbol functionOwner;
        List<BIRFunction> scopeFunctionsList;
        if (attachedTypeDef == null) {
            functionOwner = packageCache.getSymbol(currentPkgId);
            scopeFunctionsList = pkg.functions;
        } else {
            functionOwner = attachedTypeDef.type.tsymbol;
            scopeFunctionsList = attachedTypeDef.attachedFuncs;
        }
        for (BIRBasicBlock currentBB : func.basicBlocks) {
            if (currentBB.terminator.kind != InstructionKind.ASYNC_CALL
                    || !isObservable((AsyncCall) currentBB.terminator)) {
                continue;
            }

            AsyncCall asyncCallIns = (AsyncCall) currentBB.terminator;
            /*
             * The wrapper function generated below invokes the actual function synchronously, allowing the
             * instrumentation to record the actual start and end times of the function. The wrapper function
             * is invoked asynchronously preserving the asynchronous behaviour.
             */

            
            BType returnType = ((BFutureType) asyncCallIns.lhsOp.variableDcl.type).constraint;
            List<BType> argTypes = asyncCallIns.args.stream()
                    .map(arg -> arg.variableDcl.type)
                    .collect(Collectors.toList());
            Name lambdaName = new Name(String.format("$lambda$observability%d$%s", lambdaIndex++,
                    asyncCallIns.name.value.replace(".", "_")));
            BInvokableType bInvokableType = new BInvokableType(argTypes, null,
                    returnType, null);
            BIRFunction desugaredFunc = new BIRFunction(asyncCallIns.pos, lambdaName, 0, bInvokableType,
                    func.workerName, 0, null, VIRTUAL);
            desugaredFunc.receiver = func.receiver;
            scopeFunctionsList.add(desugaredFunc);

            
            BIRVariableDcl funcReturnVariableDcl = new BIRVariableDcl(returnType,
                    new Name(String.format("$%s$retVal", lambdaName.value)), VarScope.FUNCTION, VarKind.RETURN);
            BIROperand funcReturnOperand = new BIROperand(funcReturnVariableDcl);
            desugaredFunc.localVars.add(funcReturnVariableDcl);
            desugaredFunc.returnVariable = funcReturnVariableDcl;

            
            BInvokableSymbol invokableSymbol = new BInvokableSymbol(SymTag.FUNCTION, 0, lambdaName,
                    currentPkgId, bInvokableType, functionOwner,
                    desugaredFunc.pos, VIRTUAL);
            invokableSymbol.retType = funcReturnVariableDcl.type;
            invokableSymbol.kind = SymbolKind.FUNCTION;
            invokableSymbol.params = asyncCallIns.args.stream()
                    .map(arg -> new BVarSymbol(0, arg.variableDcl.name, currentPkgId, arg.variableDcl.type,
                            invokableSymbol, arg.pos, VIRTUAL))
                    .collect(Collectors.toList());
            invokableSymbol.scope = new Scope(invokableSymbol);
            invokableSymbol.params.forEach(param -> invokableSymbol.scope.define(param.name, param));
            if (attachedTypeDef == null) {
                functionOwner.scope.define(lambdaName, invokableSymbol);
            }

            
            List<BIROperand> funcParamOperands = new ArrayList<>();
            Name selfArgName = new Name("%self");
            for (int i = 0; i < asyncCallIns.args.size(); i++) {
                BIROperand arg = asyncCallIns.args.get(i);
                BIRFunctionParameter funcParam;
                if (arg.variableDcl.kind == VarKind.SELF) {
                    funcParam = new BIRFunctionParameter(asyncCallIns.pos, arg.variableDcl.type, selfArgName,
                            VarScope.FUNCTION, VarKind.SELF, selfArgName.value, false);
                } else {
                    Name argName = new Name(String.format("$funcParam%d", i));
                    funcParam = new BIRFunctionParameter(asyncCallIns.pos, arg.variableDcl.type,
                            argName, VarScope.FUNCTION, VarKind.ARG, argName.value, false);
                    desugaredFunc.localVars.add(funcParam);
                    desugaredFunc.parameters.put(funcParam, Collections.emptyList());
                    desugaredFunc.requiredParams.add(new BIRParameter(asyncCallIns.pos, argName, 0));
                    desugaredFunc.argsCount++;
                }
                funcParamOperands.add(new BIROperand(funcParam));
            }

            
            BIRBasicBlock callInsBB = insertBasicBlock(desugaredFunc, 0);
            BIRBasicBlock returnInsBB = insertBasicBlock(desugaredFunc, 1);
            callInsBB.terminator = new Call(asyncCallIns.pos, InstructionKind.CALL, asyncCallIns.isVirtual,
                    asyncCallIns.calleePkg, asyncCallIns.name, funcParamOperands, funcReturnOperand,
                    returnInsBB, asyncCallIns.calleeAnnotAttachments, asyncCallIns.calleeFlags);
            returnInsBB.terminator = new Return(asyncCallIns.pos);

            
            asyncCallIns.name = lambdaName;
            asyncCallIns.calleePkg = currentPkgId;
            asyncCallIns.isVirtual = attachedTypeDef != null;
            if (attachedTypeDef != null) {
                asyncCallIns.args.add(0, new BIROperand(new BIRVariableDcl(attachedTypeDef.type,
                        selfArgName, VarScope.FUNCTION, VarKind.SELF)));
            }
        }
    }