From e6062ec84e09c713cdac60b428bddba58cb4a9d0 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Wed, 17 Dec 2025 15:16:02 +0100 Subject: [PATCH] Fix agent crashing when account switching (#17868) --- .../autofill/services/ssh-agent.service.ts | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/autofill/services/ssh-agent.service.ts b/apps/desktop/src/autofill/services/ssh-agent.service.ts index d5aed7f3289..a61903a5c82 100644 --- a/apps/desktop/src/autofill/services/ssh-agent.service.ts +++ b/apps/desktop/src/autofill/services/ssh-agent.service.ts @@ -46,8 +46,6 @@ export class SshAgentService implements OnDestroy { private authorizedSshKeys: Record = {}; - private isFeatureFlagEnabled = false; - private destroy$ = new Subject(); constructor( @@ -91,6 +89,7 @@ export class SshAgentService implements OnDestroy { filter(({ enabled }) => enabled), map(({ message }) => message), withLatestFrom(this.authService.activeAccountStatus$, this.accountService.activeAccount$), + filter(([, , account]) => account != null), // This switchMap handles unlocking the vault if it is locked: // - If the vault is locked, we will wait for it to be unlocked. // - If the vault is not unlocked within the timeout, we will abort the flow. @@ -127,7 +126,11 @@ export class SshAgentService implements OnDestroy { throw error; }), - map(() => [message, account.id]), + concatMap(async () => { + // The active account may have switched with account switching during unlock + const updatedAccount = await firstValueFrom(this.accountService.activeAccount$); + return [message, updatedAccount.id] as const; + }), ); } @@ -200,10 +203,6 @@ export class SshAgentService implements OnDestroy { this.accountService.activeAccount$.pipe(skip(1), takeUntil(this.destroy$)).subscribe({ next: (account) => { - if (!this.isFeatureFlagEnabled) { - return; - } - this.authorizedSshKeys = {}; this.logService.info("Active account changed, clearing SSH keys"); ipc.platform.sshAgent @@ -211,20 +210,12 @@ export class SshAgentService implements OnDestroy { .catch((e) => this.logService.error("Failed to clear SSH keys", e)); }, error: (e: unknown) => { - if (!this.isFeatureFlagEnabled) { - return; - } - this.logService.error("Error in active account observable", e); ipc.platform.sshAgent .clearKeys() .catch((e) => this.logService.error("Failed to clear SSH keys", e)); }, complete: () => { - if (!this.isFeatureFlagEnabled) { - return; - } - this.logService.info("Active account observable completed, clearing SSH keys"); this.authorizedSshKeys = {}; ipc.platform.sshAgent @@ -239,10 +230,6 @@ export class SshAgentService implements OnDestroy { ]) .pipe( concatMap(async ([, enabled]) => { - if (!this.isFeatureFlagEnabled) { - return; - } - if (!enabled) { await ipc.platform.sshAgent.clearKeys(); return;