<!-- This issue tracker is only for technical issues related to Bitcoin Core.

General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com.

For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/.

If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->

<!-- Describe the issue -->

Starting with the following unsigned transaction:

```
cHNidP8BAHMCAAAAAXg6mTOjO3d9K0RiVOr87oYRYhYB/Bpomi66nXc85ebsAAAAAAD9////Avs+EQAAAAAAF6kU4lwd88Ejsg5sG0iVOiL2/c05MHKHoIYBAAAAAAAXqRSxG32ZtPml0iJQGDVxp82wjHBD+4cs7RUAAAEBIHZOFQAAAAAAF6kUP2yi0rx2ke1Lmdk5gsR+WIvukb+HAQQWABSL8jhHTVLizeYj0cS1ClE18i8jbCIGAnwLKYOB2pXhdmi+i21xj17Np67DQdv7RPiIVKqOrp++ENZSlGkAAACAAQAAgAAAAIAAAQAWABSLPsswJus4oRP6Zq1BmWcxI5hNQiICAgi7iTon5Hy59yU96uKT12AU4/bhxQy7CeEdkfg5sZLoENZSlGkAAACAAQAAgAEAAIAAAQAWABQ6Ram/bbw29IPN92ylIqYKhU1ThyICA3oH7xQc22oDM2dG6g/VZ05JLscr/hEQKUI4fTMKvUjRENZSlGkAAACAAAAAgAAAAIAA
```

I first call:

```
walletprocesspsbt "cHNidP8BAHMCAAAAAXg6mTOjO3d9K0RiVOr87oYRYhYB/Bpomi66nXc85ebsAAAAAAD9////Avs+EQAAAAAAF6kU4lwd88Ejsg5sG0iVOiL2/c05MHKHoIYBAAAAAAAXqRSxG32ZtPml0iJQGDVxp82wjHBD+4cs7RUAAAEBIHZOFQAAAAAAF6kUP2yi0rx2ke1Lmdk5gsR+WIvukb+HAQQWABSL8jhHTVLizeYj0cS1ClE18i8jbCIGAnwLKYOB2pXhdmi+i21xj17Np67DQdv7RPiIVKqOrp++ENZSlGkAAACAAQAAgAAAAIAAAQAWABSLPsswJus4oRP6Zq1BmWcxI5hNQiICAgi7iTon5Hy59yU96uKT12AU4/bhxQy7CeEdkfg5sZLoENZSlGkAAACAAQAAgAEAAIAAAQAWABQ6Ram/bbw29IPN92ylIqYKhU1ThyICA3oH7xQc22oDM2dG6g/VZ05JLscr/hEQKUI4fTMKvUjRENZSlGkAAACAAAAAgAAAAIAA" true ALL true
```

Which generates:

```
cHNidP8BAHMCAAAAAXg6mTOjO3d9K0RiVOr87oYRYhYB/Bpomi66nXc85ebsAAAAAAD9////Avs+EQAAAAAAF6kU4lwd88Ejsg5sG0iVOiL2/c05MHKHoIYBAAAAAAAXqRSxG32ZtPml0iJQGDVxp82wjHBD+4cs7RUAAAEBIHZOFQAAAAAAF6kUP2yi0rx2ke1Lmdk5gsR+WIvukb+HAQcXFgAUi/I4R01S4s3mI9HEtQpRNfIvI2wBCGsCRzBEAiBRE2oCVM2cMWAjt9c17fFUkhcDQmc4aQVDGHp1wnvHbwIgGrV1hMs6ZAbOQL1Dqn06rWOFV3LKzVDglS3v2BQswsABIQJ8CymDgdqV4XZovottcY9ezaeuw0Hb+0T4iFSqjq6fvgABABYAFIs+yzAm6zihE/pmrUGZZzEjmE1CIgICCLuJOifkfLn3JT3q4pPXYBTj9uHFDLsJ4R2R+DmxkugQ1lKUaQAAAIABAACAAQAAgAABABYAFDpFqb9tvDb0g833bKUipgqFTVOHIgIDegfvFBzbagMzZ0bqD9VnTkkuxyv+ERApQjh9Mwq9SNEQ1lKUaQAAAIAAAACAAAAAgAA=
```

Which is "complete: true" and parses fine. But then if I run `walletprocesspsbt` on the result AGAIN (don't ask why ... or do, but this should be idempotent):

```
walletprocesspsbt "cHNidP8BAHMCAAAAAXg6mTOjO3d9K0RiVOr87oYRYhYB/Bpomi66nXc85ebsAAAAAAD9////Avs+EQAAAAAAF6kU4lwd88Ejsg5sG0iVOiL2/c05MHKHoIYBAAAAAAAXqRSxG32ZtPml0iJQGDVxp82wjHBD+4cs7RUAAAEBIHZOF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AgAEAAIAAAQAWABQ6Ram/bbw29IPN92ylIqYKhU1ThyICA3oH7xQc22oDM2dG6g/VZ05JLscr/hEQKUI4fTMKvUjRENZSlGkAAACAAAAAgAAAAIAA
```

Which is still reported as "complete: true", but when I try to decode or finalize it:

```TX decode failed PSBT is not sane.: unspecified iostream_category error (code -22)```

I would expect `walletprocesspsbt [foo] true ALL true` to be idempotent, or at least produce output that's parseable.

This is all testnet and I have attached the wallet.dat in case it's useful (it only has two UTXOs and very few keys.).

I am going to continue trying to debug this, but I figured since I haven't gotten it yet I should document it. Please let me know if someone else starts looking into it.

"1. \"dummy\"    (string, optional) If set, should be \"*\" for backwards compatibility.\n"
            "2. count          (numeric, optional, default=10) The number of transactions to return\n"
            "3. skip           (numeric, optional, default=0) The number of transactions to skip\n"
            "4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n"
            "\nResult:\n"
            "[\n"
            "  {\n"
            "    \"address\":\"address\",    (string) The bitcoin address of the transaction.\n"
            "    \"category\":\"send|receive\", (string) The transaction category.\n"
            "    \"amount\": x.xxx,          (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
            "                                        for the 'receive' category,\n"
            "    \"label\": \"label\",       (string) A comment for the address/transaction, if any\n"
            "    \"vout\": n,                (numeric) the vout value\n"
            "    \"fee\": x.xxx,             (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
            "                                         'send' category of transactions.\n"
            "    \"confirmations\": n,       (numeric) The number of confirmations for the transaction. Negative confirmations indicate the\n"
            "                                         transaction conflicts with the block chain\n"
            "    \"trusted\": xxx,           (bool) Whether we consider the outputs of this unconfirmed transaction safe to spend.\n"
            "    \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction.\n"
            "    \"blockindex\": n,          (numeric) The index of the transaction in the block that includes it.\n"
            "    \"blocktime\": xxx,         (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
            "    \"txid\": \"transactionid\", (string) The transaction id.\n"
            "    \"time\": xxx,              (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).\n"
            "    \"timereceived\": xxx,      (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT).\n"
            "    \"comment\": \"...\",       (string) If a comment is associated with the transaction.\n"
            "    \"bip125-replaceable\": \"yes|no|unknown\",  (string) Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
            "                                                     may be unknown for unconfirmed transactions not in the mempool\n"
            "    \"abandoned\": xxx          (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
            "                                         'send' category of transactions.\n"
            "  }\n"