Guidance required on generating Companies House submission Transaction IDs

Hello everyone,
We are integrating our software with the Companies House accounts-submission service and would appreciate guidance on how to generate the transaction_id correctly.
Our software currently creates a 22-digit numeric ID, for example:
20XXXXXXXXXXXXXXXXXXX1

We increment this value by 1 for each submission. Submissions generally succeed, but we receive the following error for customers who have previously filed using other software:

Error Number: 503
Error Type: fatal
Error Location: Accounts
Error Text: Repeat/non-incremental Transaction ID sent with request - Reject

Could you please clarify:

  1. What format and generation rules must a transaction_id follow?
  2. Is the ID required to be unique and incrementing for each company, each software product, or each submitter?
  3. How should we determine the correct next ID when a company’s previous submission was made using different software?
  4. Can we retrieve the previous submission’s transaction ID through an API? The IDs shown in filing history appear encoded, and we are unsure whether they represent the same value.
  5. Is there a recommended way to handle this error and safely retry a submission?

We want to ensure our software generates IDs that comply with the submission requirements and avoid duplicate or non-incremental transaction IDs.