Skip to content

fix: [SDK-5832] hold OpRepo HTTP under SyncJob when backgrounded - #2861

Closed
abdulraqeeb33 wants to merge 0 commit into
mainfrom
fix/SDK-5832-patch-user-disconnect
Closed

abdulraqeeb33 wants to merge 0 commit into
mainfrom
fix/SDK-5832-patch-user-disconnect

Conversation

@abdulraqeeb33

@abdulraqeeb33 abdulraqeeb33 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Run due OpRepo HTTP under a held SyncJob when the app is backgrounded, so property user PATCHes are not started on an unprotected daemon thread.

Details

Motivation

SDK-5832: Turbine sees Android PATCH /apps/:id/users/by/:alias/:id hang up during GetUser within ~1–3ms (~650k/day). Server cancel is a client TCP close, not an SDK HTTP timeout (timeouts are 120s+). p50 ≈ 1.6ms. Android is ~100–200× iOS.

The queue is not cleared in background. Ops stay on disk until SUCCESS. What fails is the in-flight TCP: OpRepo still starts HTTP after opRepoExecutionInterval (~5s) on a daemon thread with no process hold, Android kills the socket, Turbine logs a cancel, and the SDK retries (status 0 → FAIL_RETRY).

Property-only PATCHes (refresh_device_metadata=false) cancel ~46× more often than session-start refreshes. Session start uses enqueue(..., flush=true) while typically foregrounded. Property ops from model listeners use default flush=false, so the 5s batching window often ends after backgrounding.

When this started

Not a single-line regression. The unprotected OpRepo path existed in mid-5.1; later releases increased how often HTTP starts while killable:

Band Errors / 10k What changed
5.0–5.1 3.8 Baseline. OpRepo already had ~5s batching/buckets; login/refresh stopped using flush=true; Sync path is JobScheduler-only and does not drain OpRepo HTTP.
5.6–5.8 18.3 Session timezone writes on start/active enqueue property ops with flush=false, raising unprotected PATCH volume.
5.9 21.1 Background-threading feature flag rolling out (HTTP/lifecycle on SDK dispatcher pools).
5.10–5.11 32.9 Background-threading FF removed; async init default. SyncJob finishes after runBackgroundServices() without waiting on OpRepo HTTP. Peak cancel share ~0.3% of 202s.

Scope

Make OperationRepo an IBackgroundService (same bridge SessionService already uses):

  1. scheduleBackgroundRunIn: time until the next due op (or 0 if a batch is ready).
  2. When the batch delay ends while backgrounded, do not start HTTP on the naked OpRepo daemon thread.
  3. backgroundRun(): wake the queue, execute the due batch, await in-flight HTTP, then return under the held SyncJobService.
  4. Foreground behavior stays as today. Queue persistence / FAIL_RETRY unchanged.
JobScheduler
  └── SyncJobService          ← OS process hold
        └── BackgroundManager
              ├── SessionService.backgroundRun()
              └── OperationRepo.backgroundRun()   ← this PR

Punted from this PR (separate follow-ups if still wanted):

  • Blank language hygiene (volume reduction only; not the disconnect cause)
  • HttpClient withContext(IO) + request-body stream close (structure only)

Testing

Unit testing

TBD with the OpRepo / BackgroundManager changes (backgrounded due-batch defers to SyncJob; backgroundRun drains HTTP before return).

Manual testing

Not yet. Draft while the OpRepo lifetime gate is implemented.

Affected code checklist

  • Notifications
  • Outcomes
  • Sessions
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • OpRepo background process hold only; language / HttpClient punted
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
    • Tests land with the implementation
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible
    • Not yet; draft for the OpRepo approach

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP: description/scope set; OpRepo IBackgroundService implementation still to land. Blank-language / withContext commit dropped from the branch.

@abdulraqeeb33
abdulraqeeb33 requested a review from a team December 1, 2026 18:30
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

📊 Diff Coverage Report

Diff Coverage Report (Changed Lines Only)

Gate: aggregate coverage on changed executable lines must be ≥ 80% (JaCoCo line data for lines touched in the diff).

Changed Files Coverage

  • HttpClient.kt: 101/110 touched executable lines (91.8%) (153 touched lines in diff)
  • LanguageContext.kt: 1/1 touched executable lines (100.0%) (1 touched lines in diff)
  • LoginProfileApplier.kt: 1/1 touched executable lines (100.0%) (1 touched lines in diff)
  • PropertyOperationHelper.kt: 1/1 touched executable lines (100.0%) (1 touched lines in diff)
  • RefreshUserOperationExecutor.kt: 2/2 touched executable lines (100.0%) (2 touched lines in diff)
  • PropertiesModelStoreListener.kt: 1/2 touched executable lines (50.0%) (4 touched lines in diff)
    • 1 uncovered touched lines in this file

Overall (aggregate gate)

107/117 touched executable lines covered (91.5% — requires ≥ 80%)

Per-file detail (informational; gate is aggregate above):

  • PropertiesModelStoreListener.kt: 50.0% (1 uncovered touched lines)

📥 View workflow run

@abdulraqeeb33 abdulraqeeb33 changed the title fix: [SDK-5832] blank-language PATCHes and HttpClient IO structure fix: [SDK-5832] hold OpRepo HTTP under SyncJob when backgrounded Dec 1, 2026
@abdulraqeeb33
abdulraqeeb33 force-pushed the fix/SDK-5832-patch-user-disconnect branch from 97e4607 to 40f471f Compare December 1, 2026 20:04
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