session-extend: preempt previous WaitExtendAuthSession on new wait

When the tray "Extend now" notification action and the about-to-expire
dialog both start a flow for the same deadline, the daemon was running
two independent IdP polls and the older one surfaced an InvalidArgument
toast as soon as the second RequestExtend overwrote the pending flow.

Follow the WaitSSOLogin pattern: at the top of WaitExtendAuthSession
cancel the previous wait (the SetWaitCancel/CancelWait pair on
PendingFlow already existed but was unused), then register the new
wait's cancel. Preempted callers exit with codes.Canceled; the
authsession service translates that into ExtendResult{Preempted: true}
so the tray and the React dialog can stay silent on the losing flow
instead of showing a false-failure toast / error dialog.
This commit is contained in:
Zoltán Papp
2026-05-28 19:17:46 +02:00
parent c1db8ab0ab
commit e94a4cbce5
4 changed files with 45 additions and 5 deletions
@@ -73,10 +73,20 @@ export default function SessionAboutToExpireDialog() {
console.debug("OpenURL failed during extend", e);
}
}
await Session.WaitExtend({
const result = await Session.WaitExtend({
deviceCode: start.deviceCode,
userCode: start.userCode,
});
if (result.preempted) {
// Another UI surface (e.g. the tray "Extend now"
// notification action) started a flow for the same
// deadline and took over. Keep the dialog open so the
// user can re-trigger if the other flow also fails;
// a successful extend elsewhere refreshes the deadline
// and this window auto-closes when it's no longer
// relevant.
return;
}
WindowManager.CloseSessionAboutToExpire().catch(console.error);
} catch (e) {
await Dialogs.Error({