Wait for Confirmation fails but transaction posts successfully

from algosdk.future import transaction
transaction.wait_for_confirmation(algod_client, tx_id, 4)

I’m having an issue where wait_for_confirmation fails to confirm the transaction. I think the reason for this is because the number of rounds to wait is only set to 4.

I was wondering what everyone’s thoughts were on this and what wait for rounds should be set to to avoid pool error.

Not sure about python, but here is the javascript implementation.

async waitForConfirmation(txId: string): Promise<A_PendingTransactionResponse> {
        const status = await this.client.status().do();
        let lastRound = status["last-round"];
        while (true) {
            const pendingInfo = await this.client.pendingTransactionInformation(txId).do();
            if (pendingInfo["confirmed-round"] !== null && pendingInfo["confirmed-round"] > 0) {
                return pendingInfo as A_PendingTransactionResponse;
            await this.client.statusAfterBlock(lastRound).do();

This will wait for as many blocks until the transaction is confirmed.
you can do the same in python.