Keep syncing automatically after a rejected sign-in

When two sign-ins of one account overlapped right after an account was
attached, the server rejected one, and Inner Breeze stopped syncing until the
person reconnected by hand: the username and new sessions stayed on the
device. A rejected sign-in is now retried with a fresh challenge on the usual
schedule while the account key exists, and the sync status still shows the
failure until a sync succeeds.
This commit is contained in:
waozi committed 2026-10-04 20:33:10 -03:00
1 parent 47b13958c1
commit f07f0e16c9
5 files changed
+24 -7

No files matched your search

+8 -1
View File
@@ -29,13 +29,20 @@ retry_is_temporary :: (result: s32) -> bool {
result == cast(s32) SyncResult.SYNC_REQUEST_FAILED
}
// A rejected sign-in is retried with a fresh challenge while the account key
// exists: overlapping sign-ins and server restarts reject one attempt without
// anything being wrong with the account.
retry_after_sign_in :: (result: s32) -> bool {
return result == cast(s32) SyncResult.SYNC_AUTH_FAILED
}
#program_export
sync_retry_decision :: (result: s32, attempt: s32) -> RetryDecision {
attempt = retry_attempt_index(attempt)
if result == cast(s32) SyncResult.SYNC_OK {
return RetryDecision.{0, 0, 0}
}
if retry_is_temporary(result) {
if retry_is_temporary(result) || retry_after_sign_in(result) {
next := retry_attempt_index(attempt + 1)
return RetryDecision.{next, retry_delay_seconds(next), 0}
}
+6 -4
View File
@@ -44,17 +44,19 @@ ExpectedClamp :: (attempt: s32) -> s32 {
#law NoAccountStops forall attempt: -2..6 => sync_retry_decision(2, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law PayloadFailureStops forall attempt: -2..6 => sync_retry_decision(3, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law SigningFailureStops forall attempt: -2..6 => sync_retry_decision(5, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law AuthenticationFailureStops forall attempt: -2..6 => sync_retry_decision(7, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
// A rejected sign-in retries on the same schedule; the owner chose automatic
// sync over waiting for the user after a failed sign-in (2026-10-04).
#law AuthenticationFailureRetries forall attempt: -2..6 => sync_retry_decision(7, attempt) == RetryDecision.{ExpectedNext(ExpectedClamp(attempt)), ExpectedDelay(ExpectedNext(ExpectedClamp(attempt))), 0};
// Any other code, including extremes of the persisted integer, stops retry.
#law UnknownResultStops forall result: 8..40, attempt: -2..6 => sync_retry_decision(result, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law NegativeResultStops forall result: -40..-1, attempt: -2..6 => sync_retry_decision(result, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law SavedDelayMatches forall attempt: -2..6 => app_sync_retry_delay(attempt) == cast(float64) ExpectedDelay(ExpectedClamp(attempt));
// Success and the two temporary failures need no user action; everything
// else does.
// Success, the two temporary failures and a rejected sign-in need no user
// action; everything else does.
ExpectedNeedsAction :: (result: s32) -> s32 {
if result == 0 || result == 4 || result == 6 { return 0 }
if result == 0 || result == 4 || result == 6 || result == 7 { return 0 }
return 1
}
+2
View File
@@ -78,6 +78,8 @@ mutate $sync app/sync_retry_laws.zi \
mutate $sync app/sync_retry_laws.zi \
's/return RetryDecision.{attempt, 0, 1}/return RetryDecision.{attempt, 0, 0}/' \
InvalidUrlStops
mutate $sync app/sync_retry_laws.zi \
's/ || retry_after_sign_in(result)//' AuthenticationFailureRetries
lifecycle=app/practice_lifecycle.zi
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/if auto_paused == 0 \&\& session_paused == 0 {/if auto_paused == 0 {/' \
+5 -1
View File
@@ -24,7 +24,11 @@ Answer :: () -> s32 {
if reset.attempt != 0 || reset.delay != 0 || reset.needs_action != 0 {
return 0
}
stop: RetryDecision = sync_retry_decision(7, 2)
signin: RetryDecision = sync_retry_decision(7, 2)
if signin.attempt != 3 || signin.delay != 30 || signin.needs_action != 0 {
return 0
}
stop: RetryDecision = sync_retry_decision(5, 2)
if stop.attempt != 2 || stop.delay != 0 || stop.needs_action != 1 {
return 0
}
+3 -1
View File
@@ -7,9 +7,11 @@ int
main(void)
{
RetryDecision retry = sync_retry_decision(SyncResult_SYNC_REQUEST_FAILED, 0);
RetryDecision stop = sync_retry_decision(SyncResult_SYNC_AUTH_FAILED, INT_MAX);
RetryDecision signin = sync_retry_decision(SyncResult_SYNC_AUTH_FAILED, INT_MAX);
RetryDecision stop = sync_retry_decision(SyncResult_SYNC_SIGN_FAILED, INT_MAX);
return retry.attempt == 1 && retry.delay == 5 && !retry.needs_action &&
signin.attempt == 4 && signin.delay == 60 && !signin.needs_action &&
stop.attempt == 4 && stop.delay == 0 && stop.needs_action &&
app_sync_retry_delay(INT_MIN) == 5.0 ? 0 : 1;
}