diff --git a/src/app/sync_retry.zi b/src/app/sync_retry.zi index 77c88a3d5..f35f969ae 100644 --- a/src/app/sync_retry.zi +++ b/src/app/sync_retry.zi @@ -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} } diff --git a/src/app/sync_retry_laws.zi b/src/app/sync_retry_laws.zi index 0b6b23324..478ccc403 100644 --- a/src/app/sync_retry_laws.zi +++ b/src/app/sync_retry_laws.zi @@ -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 } diff --git a/tests/law_mutation_test.sh b/tests/law_mutation_test.sh index fe9a546d6..57b29ae98 100755 --- a/tests/law_mutation_test.sh +++ b/tests/law_mutation_test.sh @@ -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 {/' \ diff --git a/tests/sync_retry_behavior.zi b/tests/sync_retry_behavior.zi index 49cab35b0..3b926468f 100644 --- a/tests/sync_retry_behavior.zi +++ b/tests/sync_retry_behavior.zi @@ -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 } diff --git a/tests/sync_retry_c_boundary_test.c b/tests/sync_retry_c_boundary_test.c index a2a1d3e75..7fbe0bdb9 100644 --- a/tests/sync_retry_c_boundary_test.c +++ b/tests/sync_retry_c_boundary_test.c @@ -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; }