Skip to content

fix(backend): retry playground mess steps on stale-sequence rejection#38

Merged
miguelnietoa merged 1 commit into
mainfrom
fix/playground-bad-seq
Jun 29, 2026
Merged

fix(backend): retry playground mess steps on stale-sequence rejection#38
miguelnietoa merged 1 commit into
mainfrom
fix/playground-bad-seq

Conversation

@miguelnietoa

Copy link
Copy Markdown
Member

Problem

The playground still showed "The transaction was rejected by the network" on a random mess step (after the account-not-found fix landed). Captured the raw rejection from the Soroban RPC:

result: { _switch: { name: "txBadSeq", value: -5 } }   // mess step TRUST_LWDEMO

Root cause is the same RPC ingestion lag, but on the sequence number: consecutive mess steps submit from the same demo account in quick succession; when the RPC serves a sequence that lags a just-confirmed tx, the next step builds with an already-used sequence → txBadSeq. It's intermittent and hits whichever step reads the lagging sequence. The previous retry only covered the "account not found" first-read case.

Also found a second issue: translateRpcError returned the generic "ERROR" message before decoding the result XDR, so the real reason (tx_bad_seq) never surfaced to users or callers.

Changes

  • buildSignSubmit retries on tx_bad_seq: re-reads the source account after a short backoff (picks up the advanced sequence), rebuilds and resubmits (BAD_SEQ_MAX_ATTEMPTS / BAD_SEQ_RETRY_DELAY_MS). Deps are injectable so the loop is unit-tested without a live RPC.
  • submitAndWait throws a typed TxSubmitError carrying the decoded result code, so callers branch on tx_bad_seq instead of string-matching messages.
  • translateRpcError decodes the TransactionResult XDR before the generic ERROR/FAILED fallback, so the specific code (e.g. tx_bad_seq) surfaces app-wide.
  • unit tests for the retry loop and the corrected error translation.

Verification

  • bun type-check ✅ · bun lint ✅ · bun test tests/unit ✅ (246 pass)
  • Reproduced end-to-end on testnet: a mess step hit txBadSeq twice, the retry re-read the account and resubmitted, and the step confirmed (200). The full Standard run (trustlines, airdrops, data entries, DEX offers, signer) completed with every step returning 200.

Consecutive playground mess steps submit from the same demo account in quick
succession. When the Soroban RPC serves a sequence number that lags a
just-confirmed tx, the next step builds with an already-used sequence and the
network rejects it as txBadSeq - surfacing as "The transaction was rejected by
the network" on a random step. This is the same RPC ingestion lag as the
account-not-found case, but on the sequence number, so it slips past the
existing not-found retry.

- buildSignSubmit now retries on tx_bad_seq, re-reading the source account
  after a short backoff so it picks up the advanced sequence, then rebuilds and
  resubmits (BAD_SEQ_MAX_ATTEMPTS / BAD_SEQ_RETRY_DELAY_MS); deps are injectable
  so the loop is unit-testable without a live RPC
- submitAndWait throws a typed TxSubmitError carrying the decoded result code,
  letting callers branch on tx_bad_seq instead of string-matching messages
- fix translateRpcError to decode the TransactionResult XDR before the generic
  ERROR/FAILED fallback - those codes had map entries that short-circuited the
  lookup and hid the real reason (e.g. tx_bad_seq) from users and callers
- unit tests for the retry loop and the now-specific error translation

Verified end-to-end on testnet: a mess step hit txBadSeq twice, the retry
re-read and resubmitted, and the step confirmed - the full Standard run
completed with every step returning 200.
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lumenwipe Ready Ready Preview, Comment Jun 29, 2026 6:26pm

@miguelnietoa miguelnietoa merged commit c13fdb0 into main Jun 29, 2026
4 checks passed
@miguelnietoa miguelnietoa deleted the fix/playground-bad-seq branch June 29, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant