Tablet never recovers from an expired or logged-out hub token: sync silently stops (counter 1 registrations not reaching counter 2, camp 467)

XMLWordPrintable

    • Type: Bug
    • Resolution: Done
    • Priority: Highest
    • 2.4
    • Affects Version/s: 2.3, 2.3.1

      Summary

      At camp 467 (12 Nov 2026), a beneficiary registered on counter 1 never appeared on counter 2. The changes feed is working. Counter 1 never sent the record to the camp hub, because every hub call from counter 1 has returned HTTP 401 since 11 Nov 14:09. The app has no working way to get a new token, so sync stops and nothing tells the user.

      Evidence (tablet sync logs, counter 1 user KA-197)

      • The beneficiary is SANJAYAKUMAR IHOLE, household 1794395100201, village Eklora 96868.
      • The record is still local (benId=-2, syncState=UNSYNCED).
      • The last login was on 10 Nov at 15:54. The last successful hub call was on 10 Nov at 17:27.
      • From 11 Nov 14:09 to now, every call has returned HTTP 401:
      Endpoint 11 Nov 12 Nov
      flw-api/stoptb/sync/changes 279 44
      flw-api/beneficiary/getBeneficiaryData 259 0
      identity-api/rmnch/syncDataToAmrit (beneficiary push) 32 20
      • The push logs Amrit push beneficiary registration failed: response body is null, httpStatus=401 and the record stays pending.
      • The single refresh attempt (10 Nov 17:00) failed with JSONException: No value for statusCode (UserRepo$refreshTokenTmc).
      • Counter 2, on the same hub, gets 200. Its feed correctly returns 0 items, because the hub never received the record.

      Why the token was rejected

      One of these two; not yet confirmed which:

      • The access token expired (jwt.access.expiration).
      • The same user logged in elsewhere. Common-API's concurrent-session logout puts the earlier token's ID on a deny list (IEMRAdminController, around line 445), after which FLW-API rejects it with 401.

      Either way, the app must recover by itself.

      App defects

      1. HTTP-level 401 is not treated as "authenticate again". Callers only refresh when the response body contains statusCode 401 or 5002. The hub's JWT filter returns a real HTTP 401.
        • ChangesFeedRepo.pull() sends HTTP 401 to else -> IllegalStateException("Changes feed HTTP $code"), then falls back to the full pull, which also gets 401.
        • The BenRepo beneficiary push treats a 401 with a null body as "pending retry" and never refreshes.
        • The TB, OPD and other push paths need the same check.
      2. UserRepo.refreshTokenTmc parses the wrong response shape. It expects {statusCode, data:{jwtToken, refreshToken, key}}. Common-API /user/refreshToken returns plain {
        Unknown macro: { {jwtToken, refreshToken}}}

        on success, and HTTP 401 with a plain-text body on failure. So the refresh can never succeed, and the new tokens the server issues (it rotates the refresh token) are thrown away.

      1. No fallback to a fresh login. The app keeps the username and password but never logs in again silently after a refresh fails. Nothing is shown to the user either; the sync screen keeps retrying.

      Expected behaviour

      • On HTTP 401 (or a body status of 401/5002) from any hub call, refresh the token once and retry the request.
      • Parse the refresh response in the shape Common-API actually returns.
      • If the refresh fails, log in again with the stored username and password, then retry.
      • If that also fails, stop retrying and show a clear "Please log in again" prompt on the sync screen.
      • Records must not be lost through any of this. Unsynced data must survive a forced re-login.

      Workaround in the field

      Log out and log in again on the affected tablet while connected to the hub. 

      Test

      Log in on tablet A, then make its token invalid in one of two ways: log the same user in on another device, or shorten jwt.access.expiration on a test hub. Then:

      • register a beneficiary on A;
      • confirm that A refreshes or logs in again by itself;
      • confirm the record reaches the hub;
      • confirm a second tablet receives it through the changes feed.

              Assignee:
              Brijesh Singh
              Reporter:
              Dr Mithun James
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: