Skip to content

fix(sdk): prevent expired AuthFetch requests from dispatching after approval - #1043

Closed
BraydenLangley wants to merge 9 commits into
mainfrom
codex/authfetch-deadline-review
Closed

BraydenLangley wants to merge 9 commits into
mainfrom
codex/authfetch-deadline-review

Conversation

@BraydenLangley

@BraydenLangley BraydenLangley commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Program and scope

Supersedes #721 and retains Mitch Burcham’s original commits. Fixes the reported late-dispatch bug: AuthFetch could reject at its existing 30-second deadline while awaiting wallet approval, then send the application request after the user approved. A side-effecting write could therefore succeed after the application had treated it as failed.

AuthFetch now aborts the pending application send when its existing deadline expires. Peer.toPeer checks that signal after asynchronous preparation and immediately before transport handoff. Existing main guards continue preventing certificate-queue dispatch and session recovery after expiry.

Only Peer.toPeer and AuthFetch.fetch change at runtime. Existing timeout values and timer placement are preserved, including time spent approving wallet operations; dispatch does not restart the timer. There is no prompt detection, ten-minute allowance, transport refactor, new timeout setting, or caller cancellation support in AuthFetch.fetch.

Exact source head: da7e043ebbbb04d21446b3f9a2d0ab16bac867f7. Base main: 86072f1f5b264ff7423257291f413678fdf2e663.

Impact

  • Public package source changed: @bsv/sdk, 3.3.0 minor candidate for the additive optional third Peer.toPeer argument { signal, onSend }.
  • Existing calls, constructor options, timeout defaults, wire bytes and wallet data remain compatible.
  • Authenticated-response timeout errors retain the exact message Timed out waiting for authenticated response. and add requestDispatched. False means the application request was never handed to the transport; true means its server-side outcome is unknown. Reconcile possibly dispatched writes before retrying.
  • README, API docs, changelog, release notes and generated migration facts describe the focused fix. Existing unrelated release clauses are retained.

A per-message signal prevents application dispatch before handoff. It does not dismiss a wallet prompt, cancel an existing handshake, or recall an in-flight send. Expiring one request does not cancel other requests sharing the peer. onSend is a synchronous dispatch observer, not confirmation of delivery.

Verification

  • Before-fix proof: two real Peer/ProtoWallet tests run against unmodified main runtime sources observed one application dispatch after expiry versus zero expected, covering late signature approval and late session-store completion. Both pass with the fix.
  • Focused auth regression suite: 4 suites / 96 tests passed, including approval just before expiry, no timer reset at dispatch, expired certificate waits, no late recovery, unknown dispatched outcomes, independent concurrent/subsequent requests, denied approval, existing two-argument calls and abort reasons.
  • Strict legacy declaration consumer compiled existing Peer constructor options, two-argument toPeer, ordinary AuthFetch calls and transport options.
  • Full local qualification: all 95 planned build, root-policy, affected-consumer, packed, browser/mobile, property and documentation commands passed on this source head. SDK coverage: 215 suites / 7,666 tests. Wallet Toolbox: 294 suites / 3,243 tests, with its 2 suites / 7 existing declared skips. SDK properties: 3 suites / 6 tests. Docs build: 135 HTML files checked.
  • pnpm test:mutation --target sdk-auth-http: 89.36% (241 killed, 53 timeout, 35 survived), zero invalid and zero uncovered mutations; 300 property cases with seed 3242026. Source-bound report and execution digest retained.
  • Hosted exact-head qualification passed: CI and merge gate, CodeQL and Conformance. All 40 checks are terminal; expected scope skips are validated by the successful merge gate. The exact-head Sonar gate reports quality=OK, newFindings=0 and unreviewedHotspots=0; the CodeQL PR ref has zero open alerts.
  • Complete diff self-reviewed for correctness, compatibility, public API, trust boundaries, artifacts, dependencies and documentation.
  • All applicable hosted checks terminal and successful on this exact head.

Security and dependencies

  • No dependency or lockfile change, new override, suppression, accepted finding or skipped regression.
  • Exact-head CodeQL has no new alert.
  • Exact-head repository quality gate has zero new Sonar findings and zero unreviewed hotspots.

Release and operations

  • No workstation package publication, deployment or source merge.
  • Source version/release metadata updated; this candidate is not published. No consumer call, wire or wallet-data migration is required.
  • Review conversations resolved and complete exact-head qualification verified before review.

The existing maintainer approval is attached to the previous head 18693e8dd53080b3ac16842674b0a5cf177edf28. The narrowed head da7e043ebbbb04d21446b3f9a2d0ab16bac867f7 is ready for fresh review before merge.

Mitch Burcham and others added 7 commits September 30, 2026 23:08
AuthFetch starts its 30 second response timer and then awaits
Peer.toPeer, which can wait on wallet prompts (the handshake, then the
request signature). If the timer fired while a prompt was open, the
caller was rejected with "Timed out waiting for authenticated
response.", but approving the prompt afterwards still sent the request.
A side-effecting request (an issuance, a payment) could then succeed on
the server after the caller had handled it as failed.

Peer.toPeer takes an optional third argument, { signal, onSend }.
Once the signal is aborted, the message is never handed to the
transport: it is checked before the signature prompt and again with no
await between the check and transport.send. AuthFetch aborts it when
its deadline passes. onSend lets AuthFetch tell a request that was
never sent from one already handed to the transport; the latter now
rejects with "Timed out waiting for authenticated response. The request
was sent; its outcome is unknown." The old message stays a prefix.

Existing two-argument toPeer callers are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@BraydenLangley
BraydenLangley marked this pull request as ready for review October 12, 2026 21:40
@BraydenLangley
BraydenLangley marked this pull request as draft October 12, 2026 22:16
@BraydenLangley BraydenLangley changed the title fix(sdk): preserve wallet approval time without extending HTTP deadlines fix(sdk): prevent expired AuthFetch requests from dispatching after approval Oct 12, 2026
@sonarqubecloud

Copy link
Copy Markdown

@BraydenLangley
BraydenLangley marked this pull request as ready for review October 12, 2026 23:10
@ty-everett ty-everett closed this Oct 12, 2026
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.

2 participants