Repository navigation
fix: [SDK-5832] hold OpRepo HTTP under SyncJob when backgrounded - #2862
Draft
abdulraqeeb33 wants to merge 2 commits into
Draft
abdulraqeeb33 wants to merge 2 commits into
abdulraqeeb33 wants to merge 2 commits into
Conversation
Property PATCHes were starting on the OpRepo daemon thread after the batching delay while the process was unprotected. Make OperationRepo an IBackgroundService so due work runs inside SyncJob's process hold, and gate the forever loop so background HTTP cannot start without that hold. Co-authored-by: Cursor <cursoragent@cursor.com>
…y test Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
📊 Diff Coverage ReportDiff 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
Overall (aggregate gate)18/23 touched executable lines covered (78.3% — requires ≥ 80%) Per-file detail (informational; gate is aggregate above):
❌ Coverage Check FailedAggregate coverage on touched lines is 78.3% (minimum 80%). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/:idhang 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 afteropRepoExecutionInterval(~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 usesenqueue(..., flush=true)while typically foregrounded. Property ops from model listeners use defaultflush=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:
flush=true; Sync path is JobScheduler-only and does not drain OpRepo HTTP.flush=false, raising unprotected PATCH volume.runBackgroundServices()without waiting on OpRepo HTTP. Peak cancel share ~0.3% of 202s.Scope
OperationRepois now anIBackgroundService(same bridgeSessionServicealready uses):scheduleBackgroundRunIn:0when due work is queued (BackgroundManager clamps to ≥5s), or the retry delay when all ops are backed off.backgroundRun(): arms a hold, force-wakes the loop, awaits drain of executable ops, then returns under the heldSyncJobService.OperationRetryTriggerbinds liveisInForegroundinto OpRepo so focus can resume execution without SyncJob.FAIL_RETRYunchanged.Punted from this PR (separate follow-ups if still wanted):
languagehygiene (volume reduction only; not the disconnect cause)HttpClientwithContext(IO)+ request-body stream close (structure only)Testing
Unit testing
scheduleBackgroundRunInnull when empty /0when due work is queuedbackgroundRunholds the processbackgroundRunOperationRetryTriggerTestsupdated for concreteOperationRepobindManual testing
Not yet.
Affected code checklist
Checklist
Overview
Testing
ensure each time enqueue is called it restarts the delay timealso fails on main.Final pass
Made with Cursor