Skip to content

fix: move Argon2id KDF off the main thread in payments send() [AMB-3036] - #43

Merged
bufo24 merged 1 commit into
mainfrom
jesseva/amb-3036-async-argon2-off-main-thread
Aug 20, 2026
Merged

fix: move Argon2id KDF off the main thread in payments send() [AMB-3036]#43
bufo24 merged 1 commit into
mainfrom
jesseva/amb-3036-async-argon2-off-main-thread

Conversation

@bufo24

@bufo24 bufo24 commented Aug 19, 2026

Copy link
Copy Markdown
Member

Context

This is the upstream fix for the temporary @ambosstech/payments@1.1.0 pnpm patch in amboss-internal-api#551. Once this SDK release is available, internal-api can remove that patch.

Problem

Live-wallet sends derive credentials with two memory-hard Argon2id passes. The previous synchronous implementation ran both passes on Node’s main thread, blocking timers, socket I/O, and health probes for several seconds. This caused the internal API to lose its RabbitMQ connection while processing payments.

Fix

  • Move Argon2id work to a lazily created, shared node:worker_threads worker.
  • Keep the cryptographic inputs, parameters, and outputs byte-for-byte compatible.
  • Keep the worker referenced briefly between chained jobs, then unref it while idle so short-lived processes can exit normally.
  • Update the callers for the asynchronous KDF API and keep send preparation sequential to avoid unnecessary memory pressure.
  • Document that preparation no longer blocks the event loop, while still avoiding first-payment KDF latency.

The worker is deliberately single-threaded: the second KDF depends on the first output, and a pool would add lifecycle complexity without helping that dependency.

Validation

  • pnpm test
  • pnpm typecheck
  • pnpm --filter @ambosstech/payments run test:examples
  • pnpm --filter @ambosstech/payments run typecheck:examples

The new Argon2 tests lock the known derivation outputs and assert that a timer remains responsive while hashing.

@bufo24
bufo24 force-pushed the jesseva/amb-3036-async-argon2-off-main-thread branch from de0d27b to 6ae9532 Compare August 20, 2026 13:50
@bufo24
bufo24 marked this pull request as ready for review August 20, 2026 13:52
@bufo24
bufo24 merged commit 15fa460 into main Aug 20, 2026
2 checks passed
@apotdevin apotdevin mentioned this pull request Aug 20, 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