harbor run -t scale-ai/hil-bench-swe_9-ask_humanharbor download scale-ai/hil-bench-swe_9-ask_humanIn the Security Center "PassAliases" view, the aliases drawer can render inconsistently:
These inconsistencies lead to users being unable to see their existing aliases, lacking a clear empty state, or being blocked from starting the alias creation flow.
When the user opens the drawer multiple times, the list and empty-state regions can disagree with each other or with the user's current vault situation—for example, alias rows may appear while empty-state copy is also shown, or the view may jump between partial list and empty layouts on successive opens. Ideally the drawer should preserve previously-loaded alias data across reopens so the user sees a consistent list without unnecessary reloading or flicker.
A module usePassAliasesProviderSetup.ts must exist at packages/components/components/drawer/views/SecurityCenter/PassAliases/ exporting a named hook usePassAliasesSetup. PassAliasesProvider.tsx must import it and expose a context returning the full PassAliasesProviderReturnedValues contract (as defined in interface.ts) with fields for vault state, alias list, limits, loading, error/upsell handling, and modal state.
PassAliasesProvider.tsx must be simplified to ONLY the context definition and provider component. Remove ALL hook logic, state management, effects, and handler functions from this file. It should contain only: the usePassAliasesSetup import from ./usePassAliasesProviderSetup, the createContext/useContext imports from React, the PassAliasesContext creation, and the provider/consumer component exports. The entire hook implementation — all imports, state management, initPassBridge, getAliasOptions, submitNewAlias, the useEffect, and the return object — must be moved to usePassAliasesProviderSetup.ts.
The hook must use useReducer for consolidated state management instead of individual useState calls. Define a PassAliasesModel interface containing passAliasVault, passAliasesItems, totalVaultAliasesCount, passAliasesCountLimit, userHadVault, and loading. Use a simple merge-reducer: (previous, nextValues) => ({ ...previous, ...nextValues }). Initialize with passAliasesItems: memoisedPassAliasesItems || [] to pick up session-cached data on subsequent opens. The module-scoped let memoisedPassAliasesItems: PassBridgeAliasItem[] | null = null; must persist as session cache across component mount/unmount cycles. Because the reducer merges partial updates, each dispatch() call should include ONLY the fields that are actually determined by that operation — omitted fields automatically retain their current values from the previous state.
The PassBridge type in packages/pass/lib/bridge/types.ts must define init(options): Promise<boolean>, vault.getDefault(options): Promise<Share<ShareType.Vault> | undefined>, and vault.createDefaultVault(): Promise<Share<ShareType.Vault>>. Both the type signatures AND the factory implementation in packages/pass/lib/bridge/PassBridgeFactory.ts must be updated. The existing getDefault implementation in the factory currently both resolves vaults AND creates one when none exists (and accepts a hadVaultCallback parameter). This must be refactored: remove the hadVaultCallback parameter entirely, and getDefault must only resolve the oldest active vault or return undefined — it must NOT create a vault or invoke any callback. The vault creation logic must be extracted into a new createDefaultVault method. createDefaultVault must be defined using method syntax (async createDefaultVault() { ... }) NOT arrow function syntax, because it needs to call this.getDefault(...) for the pre-check. It must check for an existing default vault first (via this.getDefault()), return the existing vault if found, or create a new one using createVault with name "Personal" and description "Personal vault (created from Mail)". Also convert init and create from arrow functions to shorthand method syntax for consistency.
IMPORTANT — MaxAgeMemoizedFn<T> behavior: The MaxAgeMemoizedFn<T> type (from @proton/pass/utils/fp/memo) wraps a function type T and adds an optional { maxAge?: number } options object as the last call-site parameter. The inner function passed to maxAgeMemoize() must NOT include maxAge in its own parameter list — the memoization wrapper intercepts and consumes it before forwarding the call. For example, getDefault: maxAgeMemoize(async () => { ... }) means the inner function takes NO arguments, but callers invoke it as getDefault({ maxAge: UNIX_DAY }) because the wrapper adds the options parameter. The correct type for getDefault is MaxAgeMemoizedFn<() => Promise<Share<ShareType.Vault> | undefined>> — note the inner function type is () => Promise<...> with NO parameters. Do NOT add an options, maxAge, or any other parameter to getDefault's inner function signature. Do NOT remove the MaxAgeMemoizedFn wrapper from the type. The same pattern applies to getAllByShareId and getUserAccess.
The hook must initialize by calling PassBridge.init with { user, addresses, authStore }, then vault.getDefault({ maxAge: UNIX_DAY }). If a vault is found, it must fetch aliases and user access using fetchPassAliases with cache options; if no vault exists, the hook should set loading=false and defer vault creation to the getAliasOptions flow. Any previously cached alias data should be reset in this scenario.
The hook's getAliasOptions must create a default vault via createDefaultVault when passAliasVault is undefined. It must then run fetchPassAliases to refresh alias state, counts, and memoization regardless of whether the vault was just created or already existed, before returning alias options. After alias creation, it must refetch aliases with { maxAge: 0 }, update passAliasesItems and alias counts, then refresh the memoized list.
The helpers module PassAliasesProvider.helpers.ts must export filterPassAliases (removes trashed, sorts by lastUseTime/revisionTime desc) and fetchPassAliases (returns aliasesCountLimit, filteredAliases, aliases by calling alias.getAllByShareId and user.getUserAccess with cache options).
The hook must implement required UX flows: copy alias email to clipboard and show a success notification "Alias saved and copied" on success; show "Aliases could not be loaded" on init error; open upsell modal on quota error (CANT_CREATE_MORE_PASS_ALIASES); show "An error occurred while saving your alias" on unexpected alias creation failures.
The creation-limit state (hasReachedAliasesCountLimit) must accurately reflect whether the user has reached their plan's alias creation quota. The plan's alias limit counts only active (non-trashed) aliases, as trashed aliases are pending permanent deletion and do not occupy permanent quota slots.
The following modules are part of the PassAliases feature implementation:
Function
Name: filterPassAliases
Path:'packages/components/components/drawer/views/SecurityCenter/PassAliases/PassAliasesProvider.helpers.ts'
Parameters:
Returns:
Description:
Filters out trashed alias items and returns the remaining ones sorted in descending order by 'lastUseTime' or 'revisionTime'.
Function
Name: fetchPassAliases
Path: 'packages/components/components/drawer/views/SecurityCenter/PassAliases/PassAliasesProvider.helpers.ts'
Parameters:
'PassBridge: PassBridge': Instance of the PassBridge API handler.
'defaultVault: PassAliasesVault': The vault from which aliases should be fetched.
Returns:
Description:
Retrieves all aliases for the specified vault from PassBridge, filters them using 'filterPassAliases', retrieves alias count information from user plan data, and returns all results in a structured object.
Interface
Name: PassAliasesProviderReturnedValues
Path: 'packages/components/components/drawer/views/SecurityCenter/PassAliases/interface.ts'
Properties:
getAliasOptions: () => Promise - Fetches options required to create a new alias.
hasAliases: boolean - Indicates if the user currently has aliases stored in the decrypted vault.
hasUsedProtonPassApp: boolean - Indicates if the user has previously used Proton Pass.
loading: boolean - Whether alias-related data is currently loading.
hadInitialisedPreviously: boolean - Indicates if the aliases drawer has been opened in the current session.
hasReachedAliasesCountLimit: boolean - Indicates if the alias creation limit has been reached.
submitNewAlias: (formValues: CreateModalFormState) => Promise - Submits a new alias creation request.
passAliasesVaultName: string - The name of the current aliases vault.
passAliasesItems: PassBridgeAliasItem[] - List of filtered alias items.
passAliasesUpsellModal: ModalStateReturnObj - Modal controller for alias upsell prompts.
Description:
Defines the shape of the data and actions returned by the aliases provider hook for managing alias-related state and operations.
Function
Name: usePassAliasesSetup
Path:'packages/components/components/drawer/views/SecurityCenter/PassAliases/usePassAliasesProviderSetup.ts'
Returns:
Description:
Custom React hook that initializes and manages the state for Pass aliases in the Security Center view, including vault resolution, optional default-vault provisioning when required by the flow, alias retrieval, alias creation, and modal handling.