The scenario: a successful response arrives after sign-out
The user signs out while a session refresh is waiting on a response. If the response later succeeds and the client applies it without checking current state, the application can undo the user’s sign-out by restoring credentials in memory or storage. Cancelling the task is useful, but the client should not assume every transport or asynchronous dependency immediately cooperates.
The reviewed Movo-X Swift core combines cancellation with a state check before applying the refresh response. In addition to the selected existing tests, a supplemental research test was added only to the isolated snapshot to force a late response after logout despite cancellation. That test passed; no application source or production account was changed.
Capture the session the operation belongs to
The inspected refresh operation begins with the current session context and awaits the refresher. After the await, it compares that context with the manager’s live state before persisting or publishing the response. The operation therefore has an ownership condition beyond “the network request succeeded.”
This is the essential model for the race. An asynchronous result belongs to the session that initiated it. A user action can invalidate that relationship while the operation is waiting. The implementation needs a defined response to a signed-out state or a different current session, rather than treating the old response as a new sign-in instruction.
Clear local state when sign-out is accepted
The source sign-out method captures the prior token context for the caller, cancels the recorded refresh, clears the live and pending-save state and asks the store to clear. It emits a local sign-out event. The returned prior context allows a separate best-effort server-revocation step without keeping the application signed in while that network work is attempted.
Those are related but separate responsibilities. A local session transition does not itself prove that every server session was revoked, and a server request should not be the only thing that makes the interface stop presenting the old local session. The operating contract must identify the responsibilities of the core manager, caller and authoritative service.
Do not rely on cancellation alone
The existing source test covers a delayed refresher and sign-out. Its fake refresher uses a cancellable wait. That is useful, but a stronger targeted case can ask what happens when a dependency still returns a response after the cancellation request. The supplemental test was designed specifically for that distinction.
Its fake refresher holds a continuation, signals that refresh has started and waits until the test deliberately releases the response. The test signs out first, then releases the response. No real network request or credential is involved. This makes the ordering deterministic without using a patient account or trying to produce a timing accident on a live device.
Assert the final state, not just the thrown error
The supplemental case checks that the late work does not restore a signed-in manager, a current token set or the in-memory stored session. An error response from the refresh task would be insufficient by itself if state had already been repopulated before the error was returned. The test therefore inspects the resulting state after the controlled completion.
The source guard is the implementation element under examination; the test observes the expected behaviour through the manager and store interfaces. The added test is research evidence, not an upstream test that was already part of the pinned repository. Its source and hash are retained privately with the test log so that distinction remains reviewable.
Keep a newer session distinct from the old operation
The inspected implementation also accounts for the possibility that the manager has moved to a different live session while the earlier operation was waiting. It does not simply persist the old response over the new current state. The in-flight task cleanup likewise checks task ownership before clearing the recorded task.
That source behaviour suggests a separate useful acceptance case: sign into a new session before an earlier refresh completes. The supplemental test reported here covers logout and a late response, not every account-replacement or overlapping-task sequence. Keep additional cases explicit instead of expanding a single successful race test into a guarantee about all asynchronous state transitions.
Understand the limits of the test environment
The selected existing core suites passed 42 tests on Linux, and the added late-response case passed separately. They use the portable Foundation-based package, fake refreshers and an in-memory store. No iOS interface, actual Keychain clear failure, physical-device background state or server-side revocation was exercised by these runs.
A release acceptance plan still needs those relevant platform and integration checks. In particular, a storage adapter that cannot clear durable state is a different case from the in-memory store used here. The technical evidence should be precise enough that a reviewer knows which assumption the core race result depends on and what remains to be verified elsewhere.
A focused race-condition review deliverable
Deliver the asynchronous state map, operation ownership check and a deterministic late-completion test. Record the sign-out event, final live/store state and the separate service-revocation responsibility. Keep the experiment synthetic and isolated, with no production session mutation used merely to demonstrate the case.
For a CTO, this turns a hard-to-reproduce lifecycle concern into a bounded engineering question. The client does not accept an old operation’s success as permission to reverse a later user decision. The result is useful because the sequence is controlled and the final state is inspected, rather than because the application happened not to show a failure during an ordinary sign-in demonstration.
Illustrative control flow
Pseudocode summarizing the decision boundary. It is not copied production code or a deployment instruction.
captured_session = current_session
response = await refresh(captured_session)
if current_session no_longer_matches captured_session:
return current_session_or_signed_out_result()
apply_response(response)
# A successful old response is not a new sign-in instruction.About this engineering series
Written by Omer Muneer Qazi from a review of Movo-X implementation and dated engineering records. This article explains source behaviour and historical observations; current production, clinical outcomes and store availability require their own verification. Examples are synthetic and proposed test cases are identified as such.
Explore the Movo-X engineering series → · Related implementation experience →
Discuss a similar engineering problem
Send the workflow, current platform and the decision your team needs to make. I can help define an implementation or review scope with concrete acceptance evidence.
Discuss your project on WhatsApp ↗