[Crashlytics][2.4] ForegroundServiceDidNotStartInTimeException from WorkManager still crashing in 2.3 (250 events / 155 users in 30 days)

XMLWordPrintable

      Summary

      ForegroundServiceDidNotStartInTimeException from WorkManager's SystemForegroundService is still crashing in release 2.3 and affects 155 users in 30 days. Investigation and fix are required in 2.4.

      Background / Context

      • Source: Firebase Crashlytics, project stoptb-8e404, app org.piramalswasthya.stoptb, 30-day crash view (Oct 12 – Nov 10, 2026).
      • Existing ticket: STOP-781 (RCA-07, fix version 2.5). This ticket tracks the 2.4 work because the crash persists from 2.0 through 2.3.
      • The draft RCA status is "Root Cause Not Conclusively Established".

      Problem Statement

      The app crashes because a foreground service started by WorkManager does not call startForeground() within the platform timeout.

      Current Behaviour (Actual)

      • Crash: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException - Context.startForegroundService() did not then call Service.startForeground(): androidx.work.impl.foreground.SystemForegroundService.
      • 250 events / 155 users in 30 days. 2 variants. Affected versions: 2.0 – 2.3.
      • Not tagged "Repetitive crashes" by Crashlytics.
      • RCA-07: PullAshaWorker and PullFilariaFromAmritWorker call setForeground(); nothing in code explains the delay. Hypothesis H7 (workers are slow to reach setForeground() under memory or CPU pressure from RCA-01) is unresolved and unproven. Only two workers were found; other workers and the stack-trace variants were not examined.

      Expected Behaviour / Requirement

      • Workers that run as foreground work do not trigger this exception.
      • Root cause identified and documented. [TBD/CLARIFICATION REQUIRED: the fix approach depends on the root cause]

      User Story

      As a field user running background sync, I want background work to complete without the app crashing, so that my data syncs reliably.

      Acceptance Criteria

      • Given the stack-trace variants are reviewed, When the investigation is complete, Then the root cause is documented on this ticket.
      • Given the fix is released in 2.4, When Crashlytics is checked, Then no new events for this issue appear on 2.4.
      • Given a worker uses setForeground(), When it starts, Then the foreground notification is established without crashing. [TBD/CLARIFICATION REQUIRED: validate once root cause is known]

      Business Rules / Validations

      • None identified.

      Dependencies

      • Related: STOP-781 (RCA-07), STOP-778 (RCA-01, possible contributor, unproven). Proposed action CAPA-16 in StopTB_Crashlytics_RCA.xlsx: investigate the SystemForegroundService variants, call setForeground() first in doWork, review expedited work usage.

      Impact / Affected Areas

      • WorkManager workers using foreground info (PullAshaWorker, PullFilariaFromAmritWorker confirmed; others TBD).
      • Background sync flows.

      Out of Scope

      • Fixing OOM from HTTP body logging (STOP-778).

      QA / Testing Considerations

      • Run affected workers on low-memory devices (e.g. Lenovo TB336ZU, Android 16, seen in the OOM samples).
      • Verify in Crashlytics after the 2.4 rollout.

      Open Questions / Clarifications

      • Which workers produce the two crash variants? [TBD/CLARIFICATION REQUIRED]
      • Is the delay related to memory pressure from the OOM issue? Re-check after the logging fix ships. [TBD/CLARIFICATION REQUIRED]

              Assignee:
              Brijesh Singh
              Reporter:
              Shivani Garg
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: