Skip to content

Show the clock error after a minute of skew and recover from startup upload failures - #2163

Open
YeungKC wants to merge 15 commits into
mainfrom
fix/clock-skew-one-minute
Open

YeungKC wants to merge 15 commits into
mainfrom
fix/clock-skew-one-minute

Conversation

@YeungKC

@YeungKC YeungKC commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two parts: when a 401 means "clock error", and what startup does when the first Signal key upload fails.

1. 401 classification (isClockSkewed in lib/utils/auth_token_utils.dart, used by AccountServer._handleApiError)

 on HTTP 401
   if the token was issued more than 60s ago     -> ignore (unchanged)
-  if |x-server-time - request time|  >= 5 min   -> show the clock error
+  if |x-server-time - response time| >  1 min   -> show the clock error
+  if the 401 has no x-server-time               -> show the clock error
   otherwise                                     -> sign out (unchanged)

The response time is taken when the headers arrive, so a slow or failed body read does not shift it. A 401 whose body is not JSON or fails to read keeps its status and headers, so it goes through the same check.

2. Startup (AccountServer.initServer, the first POST /signal/keys)

Before, an error here either signed the user out or was dropped, which left the app signed in with no message worker and no error on screen. Now one AccountStartupState owns the outcome:

POST /signal/keys
  accepted                                -> ready (worker starts)
  401, clock skewed or no server time     -> clockError  (Continue)
  401, clock in sync                      -> signedOut
  401, delayed token                      -> retry once with a fresh token
  transport, timeout, 5xx, 408, 425, 429  -> retry every 2s, same key batch
  other 4xx, badData                      -> retryRequired (Retry button on the loading screen)
  old version                             -> upgradeRequired
  missing local Signal identity           -> signedOut
  stop()                                  -> stopped (no more uploads)

Continue on the clock screen makes one upload attempt. If it fails, it shows the error and the button is available again, the same as the Android and iOS clock screens. Sign-out and upgrade close the clock screen. No new strings: the Retry button uses the existing retry label.

Evidence

  • test/account/account_server_startup_exhaustive_test.dart drives the real AccountServer against a fake HTTP adapter and a fake clock. It covers every sequence of up to 4 responses from 15 kinds, then "accept forever", with Continue, Retry, stop, and a concurrent /me 401 at each step. It checks 10 properties: sign-out only on an in-sync 401 or a missing identity, no silent hang, recovery after the server accepts, one end state, nothing after stop(), and the same key batch on retries.
    • Before (at 092040b): initServer -> badData forever never ends and shows nothing, and Continue followed by an in-sync 401 leaves the clock screen open next to the sign-out.
    • After: 54,241 sequences, 0 violations. 19 of 19 planted single-line bugs fail the check. CI runs 59 witness sequences by default; CLOCK_VERIFY_FULL=1 runs the full bound.
  • test/account/account_server_logout_test.dart adds a test for each case in the table above. Each test failed before its fix.
  • flutter test test/account/ test/utils/ test/workers/: 291 passed, 4 skipped. dart analyze --fatal-infos lib test: no issues.

Merge Danger

Door: two-way

Blast Radius: sign-in and startup.

  • Users whose clock is off by 1 to 5 minutes now see the clock error page on a 401 instead of being signed out.
  • A first Signal key upload that fails no longer signs the user out. The app keeps retrying in the background, or shows Retry on the loading screen if the server rejects the keys.
  • The Dio transformer change applies to every request: a non-2xx response whose body cannot be read or decoded now surfaces as badResponse with its status, instead of a FormatException.
  • The default startup test adds about 3 minutes to CI.

A 401 whose x-server-time is more than one minute away from the request
time now shows the clock error instead of signing out. The mobile clients
use the same one-minute limit.
@YeungKC
YeungKC requested a review from crossle December 3, 2026 08:05
@gaotic

gaotic Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review done for ed914d9 in 15m 07s · 1 comment

Quality: The retry and 401 classification paths have broad automated coverage. A separate response-ordering test confirmed one remaining startup race.

Role Model Status
Reviewer Codex codex/gpt-6.2-sol · effort high ok

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · 1f7afe5

Flutter analysis found no issues in the five changed files. All 23 existing focused tests passed, and a temporary startup regression test reproduced the finding.

Comment thread lib/account/account_server.dart Resolved
Without x-server-time a revoked session cannot be told apart from a clock
error. Show the clock error instead, as the iOS client does; Android does
not sign out either.

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · 017ce38

Flutter analysis passed on all five changed files, and 22 of 23 focused tests passed. The existing logout test made one unexpected /logout request because its mock /me response omits x-server-time. Give that fixture a current server timestamp so it exercises automatic sign-out.

Comment thread lib/account/account_server.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · 31eebf3

Changes requested. Flutter analysis passed on all six changed files, and all 39 related tests passed on a sequential rerun after the initial native-library staging error. A separate startup regression test reproduced the remaining issue.

Comment thread lib/account/account_server.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · ba22df6

Changes requested. Flutter analysis passed on all seven changed files, and all 33 focused tests passed. Two additional scratch tests reproduced the issues below.

Comment thread lib/account/account_server.dart Resolved
Comment thread lib/account/account_server.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · bdcbb23

Changes requested. Flutter analysis passed on all seven changed files, all 38 focused tests passed, and two scratch tests reproduced the remaining defects.

Comment thread lib/account/account_server.dart Resolved
Comment thread lib/workers/isolate_event.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · c941ae7

Changes requested. Flutter analysis passed on all eight changed files, and all 40 focused Flutter tests passed.

Comment thread lib/utils/mixin_api_client.dart Resolved
Comment thread lib/account/account_server.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · e871f4e

Changes requested. Flutter analysis passed on all nine changed files, and all 50 focused tests passed. Two scratch tests reproduced the findings.

Comment thread lib/account/account_server.dart Resolved
Comment thread lib/workers/isolate_event.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · 527c87f

Changes requested. Flutter analysis passed on all nine changed files, and all 47 focused tests passed. A separate scratch test reproduced the remaining defect.

Comment thread lib/account/account_server.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · 092040b

Changes requested. Flutter analysis passed on all nine changed Dart files, and all 46 focused tests passed. Two scratch checks reproduced the reported retry defects.

Comment thread lib/account/account_server.dart Resolved
Comment thread lib/account/account_server.dart Resolved

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · 73c2038

Flutter analysis passed on all 11 changed Dart files. All 69 focused repository tests passed, including the default startup suite with 48 scenarios. Six scratch cases reproduced the four findings.

Comment thread lib/account/account_server.dart Resolved
Comment thread lib/account/account_server.dart Resolved
Comment thread lib/account/account_server.dart Resolved
Comment thread lib/account/account_server.dart Resolved
@YeungKC
YeungKC marked this pull request as draft December 4, 2026 04:45
@YeungKC YeungKC changed the title Show the clock error when server time differs by more than a minute Show the clock error after a minute of skew and recover from startup upload failures Dec 4, 2026
@YeungKC
YeungKC marked this pull request as ready for review December 4, 2026 05:49

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review · Codex · ed914d9

Changes requested. Flutter analysis passed on all 11 changed Dart files, and the focused suites finished with 291 passing tests and four skips. The full depth-four startup check passed using the test’s OpenSSL backend.

Comment thread lib/account/account_server.dart Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant