<!-- XE-1855 · Negative attempt counts make `request()` and `rentLease()` throw `undefined` instead of an error · testnet -->
*Markdown view of <https://bounty.xe.network/XE-1855>. The page is the record; this is the same page for reading.*

XE-1855 · Bounty

# Negative attempt counts make \`request()\` and \`rentLease()\` throw \`undefined\` instead of an error

Triaging
claimed Minor
web
filed 2026-11-09 08:05 UTC
by Darkarmy921

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Minor

Area
:   SDK / docs / web

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-14 22:57 UTC

Told
:   2026-11-10 14:00 UTC

### Patches

None linked.

### History

- [211823](https://bounty.xe.network/log/211823) 2026-11-14 22:57 UTC proposal.adopted
- [211822](https://bounty.xe.network/log/211822) 2026-11-14 22:57 UTC ticket.award
- [84112](https://bounty.xe.network/log/84112) 2026-11-10 14:00 UTC proposal.adopted
- [84111](https://bounty.xe.network/log/84111) 2026-11-10 14:00 UTC reply.sent
- [83974](https://bounty.xe.network/log/83974) 2026-11-10 14:00 UTC proposal.adopted
- [83973](https://bounty.xe.network/log/83973) 2026-11-10 14:00 UTC ticket.status new → triaging
- [83656](https://bounty.xe.network/log/83656) 2026-11-10 14:00 UTC proposal.adopted
- [83655](https://bounty.xe.network/log/83655) 2026-11-10 14:00 UTC proposal.adopted
- [83654](https://bounty.xe.network/log/83654) 2026-11-10 14:00 UTC ticket.facts
- [83653](https://bounty.xe.network/log/83653) 2026-11-10 14:00 UTC proposal.adopted
- [83652](https://bounty.xe.network/log/83652) 2026-11-10 14:00 UTC ticket.facts
- [83651](https://bounty.xe.network/log/83651) 2026-11-10 14:00 UTC proposal.adopted

[Full history](https://bounty.xe.network/log?ref=XE-1855) · [JSON](https://bounty.xe.network/v1/tickets/XE-1855) · [markdown](https://bounty.xe.network/XE-1855.md)

### Report

## Title

Negative attempt counts make `request()` and `rentLease()` throw `undefined` instead of an error

## Summary

Two retry loops share the same shape — `let lastError: unknown` /
loop / `throw lastError` — and neither validates its count. With
`retries: -1`, `XeClient.request()`'s loop body never runs and the
function throws the never-assigned `lastError`, i.e. throws
`undefined`. With `attempts: 0`, `Xe.rentLease()` does the same:
the loop never runs and it throws `undefined`. A caller doing
`catch (err) { err.message }` gets a `TypeError` instead of the
configuration error, and `err instanceof Error` is `false` — the
original mistake (a negative count) is unrecoverable and
undiagnosable from the thrown value.

## Impact

- **Throwing a non-Error.** `throw undefined` breaks every error
  handler downstream: logging, `instanceof` checks, and
  `err.message` reads all fail or misreport. The caller cannot tell
  whether the request failed, was never attempted, or was
  misconfigured.
- **Scope limit (stated plainly).** The trigger is caller
  misconfiguration (a negative count), not attacker input, and no
  request is sent and no funds move. The defect is in the error
  path, not in any success path.

## Severity reasoning

- **Minor, not Low:** throwing `undefined` is a sharp API-contract
  violation in two public functions, and it actively destroys the
  diagnostic information a caller needs. But the trigger is a
  caller error and nothing is sent or spent.

## Root cause

`src/client.ts` `request()`: `for (attempt = 0; attempt <= this.#retries; attempt++)` with `#retries = -1` skips the loop and
falls through to `throw lastError` (still `undefined`).
`src/xe.ts` `rentLease()`: `for (attempt = 1; attempt <= attempts; attempt++)` with `attempts = 0` (or negative) likewise falls through
to `throw lastError` (still `undefined`). Neither constructor/option
validates the count (`retries`/`attempts` accept any number).

## Reproduction

Harness `/tmp/sdk-r5/verify.mjs` (section D), mock fetch only. Run
from the built SDK:

```
cd ~/workspace/xe-bounty/sdk
node /tmp/sdk-r5/verify.mjs
```

Observed output:

```
PASS D-retries-minus1-throws-undefined thrown=undefined
PASS D-rentLease-attempts0-throws-undefined thrown=undefined
PASS D-control-retries0-one-attempt calls=1
```

What the run shows:

1. `new XeClient({retries: -1}).request('/node')` throws `undefined`
   without making any fetch call.
2. `xe.rentLease(opts, {attempts: 0})` throws `undefined` without
   opening any lease.
3. Control: `retries: 0` makes exactly one attempt — the boundary
   below which the loop never runs is exactly the unvalidated one.

## Dedup note

Checked against the public ticket list (186 public tickets, max
XE-1799, snapshot 2026-11-09 \~14:19 WIB; title sweep). No title match
for `throw undefined`, `lastError`, attempt counts, or retries.
Closest reports:

- **XE-0078** — "`rentLease` skips its cancel on a non-retryable
  wait error". Same function, different defect (cancel path, not
  attempt-count validation).
- **XE-0056** — "a 429 rate limit is classified as non retryable".
  Same retry machinery, different defect (classification, not the
  loop bound).

No known report covers this defect. Private/sealed tickets are
invisible, so a sealed duplicate cannot be ruled out.

## Suggested fix direction

- Validate the counts at the boundary (`retries >= 0`,
  `attempts >= 1`) and throw `XeUsageError` for invalid values; and
  never `throw lastError` without a loop iteration having run (throw
  a fresh error instead).

## Payout address

```
052e33e0ed9c43e2bdf07faff9a90d25642b51d53d96f49f5d45b81f6584b3da
```

## References (file:line; sdk @ 605c20a)

| Location | What it shows |
| --- | --- |
| `src/client.ts` (`request`) | `let lastError: unknown` … `throw lastError` after a loop that may never run |
| `src/xe.ts` (`rentLease`) | Same shape: `let lastError: unknown` … `throw lastError` |
| `/tmp/sdk-r5/verify.mjs` (section D) | Verification harness (ephemeral, see "Reproduction") |

### Thread

**Joseph Denne**team2026-11-10 14:00 UTCdesk

Thank you for this report. We have read it against the code and it is being handled. The assessment and any award follow the fix. https://bounty.xe.network/XE-1855
