Skip to content

feat(sdk-api,sdk-core): cooperatively yield during password rotation - #10322

Open
noegutierrez5 wants to merge 1 commit into
masterfrom
noegutierrez/wcn-2084-yield-during-password-rotation
Open

noegutierrez5 wants to merge 1 commit into
masterfrom
noegutierrez/wcn-2084-yield-during-password-rotation

Conversation

@noegutierrez5

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in cooperative-yielding boundary to account-password rotation (WCN-2084).

BitGoAPI.changePassword() runs the v1 (SJCL) and v2 (Argon2) keychain loops in long, synchronous-event-loop stretches. Progress UI exists, but the callbacks are only observed between those stretches; a large enterprise can still lock the browser tab. Running the rotation in a dedicated worker (retail work in bitgo-retail PR #10191) removes the lockup, and this SDK change makes each worker event-loop turn process a bounded number of keychains.

Changes

  • ChangePasswordOptions (sdk-api) and UpdatePasswordOptions (sdk-core) gain yieldEvery?: number.
    • JSDoc: positive safe integer; after every N listed keychain records, yield to a new macrotask.
    • undefined preserves current behavior exactly; invalid values (0, negatives, fractions, NaN, unsafe integers, non-numbers) are rejected at every independently callable public entry with yieldEvery must be a positive safe integer.
  • BitGoAPI.changePassword validates and forwards yieldEvery to the sdk-api v1 keychains call and the sdk-core coin keychains call.
  • Cooperative yield added to all three per-record loops:
    • sdk-api v1 Keychains.updatePassword
    • sdk-core legacy v2 Keychains.updatePassword
    • sdk-core safeId mode updateSafePassword (still progress-silent, but the boundary applies so the option is never silently ignored)
    • Every listed record counts — updated, skipped, and missing-envelope alike. Progress outcome is emitted before the yield. No timer/promise is allocated on non-boundary records.
  • requestPatch sets User-Agent only when XMLHttpRequest is unavailable (Node), instead of when window is unavailable. Dedicated workers expose XHR without window; the old detection made worker requests attempt to set User-Agent, which browsers reject.

Tests

  • Timer-interleaving tests for v1, legacy v2, and safe mode: a zero-delay timer scheduled from the first progress/re-encryption callback runs before the second record begins when yieldEvery: 1 (deterministic FIFO timer ordering).
  • Missing-envelope records count toward the boundary (safe mode and legacy mode).
  • Invalid yieldEvery values reject at each public entry before any rotation/network work.
  • Omitted option forwards yieldEvery: undefined and preserves behavior.
  • User-Agent detection: Node sets it; browser (window + XHR) does not; dedicated-worker runtime (no window, XHR present) does not.
  • Existing change-password batching, progress, retry, session, and safe-mode suites re-run and pass.

Verification

  • yarn workspace @bitgo/sdk-core build and yarn workspace @bitgo/sdk-api build pass.
  • yarn workspace @bitgo/sdk-api unit-test 'test/unit/bitgoAPI.ts' 'test/unit/v1/keychains.ts' → 318 passing.
  • yarn workspace @bitgo/sdk-core unit-test --grep 'Keychains\b' → 47 passing.
  • lint and check-fmt pass for both workspaces.

Ticket: WCN-2084

Add an opt-in `yieldEvery` boundary to every password-rotation loop:

- BitGoAPI.changePassword, sdk-api v1 keychains, sdk-core legacy v2, and
  sdk-core safeId mode accept `yieldEvery?: number`, validated as a positive
  safe integer at each independently callable public entry.
- After every N listed keychain records (updated, skipped, and
  missing-envelope alike), the loop yields to a new macrotask so the host
  event loop can process I/O, worker messages, or repaints between bounded
  stretches of keychain crypto. Omitted/undefined preserves the existing
  behavior exactly (no timer is ever allocated).
- Safe mode stays progress-silent but honors the same record boundary,
  so the option is never silently ignored on safeId rotations.
- Make requestPatch worker-safe: set User-Agent only when XMLHttpRequest is
  unavailable (Node), not merely when `window` is unavailable. Dedicated
  workers expose XHR but not window and must never attempt to set User-Agent.

WCN-2084

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@linear-code

linear-code Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

WCN-2084

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ Compatibility checks are failing on Node.js 27-nightly (experimental, non-blocking). This does not block merge, but it signals an incompatibility to fix before this release becomes supported.

View run

This branch has not been deployed

No deployments
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