AuthRecipe user lookups: run them on the transaction connection inside recipe flows

Author: tamassolteszCreated Sep 28, 2026Updated Sep 28, 2026
Labelsagent-wip

Part of PLAN-018, Unit 3 (core caller + in-memory impl). Full design: agent-plans PLAN-018.

Cross-repo dependency (wired by append-cross-deps.sh): needs the PLAN-018 pi contract (listPrimaryUsersByEmail_Transaction / listPrimaryUsersByPhoneNumber_Transaction) and the pg impl merged / available. Build against the pi + pg bases (same branch name -> CI pairs).

Problem. AuthRecipe.getUserById (AuthRecipe.java:243), getUsersByAccountInfo (:534), and loadAuthRecipeUserInfosByVariousIds (:627) each borrow their own connection (-> Start.getPrimaryUser* -> GeneralQueries.getPrimaryUserInfoForUserId(s)[_new]), and recipe code calls them inside a startTransaction — e.g. EmailPassword.consumeResetPasswordToken (EmailPassword.java:597, :633, lambda :664), account-info lookups, and pagination.

Fix — keep the lookup in the SAME transaction (do NOT hoist). Thread con so the read runs on the transaction's own connection:

  • by-id path: use the existing getPrimaryUserById_Transaction;
  • third-party account-info: use the existing listPrimaryUsersByThirdPartyInfo_Transaction;
  • email / phone account-info: use the NEW listPrimaryUsersByEmail_Transaction / listPrimaryUsersByPhoneNumber_Transaction from the pi ticket, and implement them in the in-memory (sqlite) Start mirroring the pg impl (this is the core-side half of the Unit-3 contract);
  • where an AuthRecipe helper has no _Transaction form yet, CREATE it (e.g. AuthRecipe.getUserById_Transaction) rather than hoisting the read before startTransaction.
  • loadAuthRecipeUserInfosByVariousIds: run the batch on con (loop the single-id _Transaction read, or add a batch _Transaction if the query is a single round-trip) — no second connection either way.

Hoisting stays acceptable ONLY for a stable external->internal id translation that needs no transactional consistency with the body, never for a live user-record read.

Acceptance.

  • No AuthRecipe lookup borrows a second pooled connection when called inside a recipe transaction.
  • EmailPasswordTest, GetUserByAccountInfoTest, UserPaginationTest, RecoverAccountFlowTest pass with no nested-acquisition warning.
  • In-memory impls of the two new _Transaction reads added and behaviour identical to the non-tx forms.
  • CHANGELOG line under the topmost unreleased section: Fix: recipe user lookups ran on a second pooled connection inside transactions.
  • No version bump in the PR.

Plan: PLAN-018

Depends-on: supertokens/supertokens-plugin-interface#227

Depends-on: supertokens/supertokens-postgresql-plugin#413

Source: supertokens/supertokens-core