Repository navigation
Conversation
…request A stop at the job's time limit added one backoff step every time, up to 2 hours, also for a run that only waited for the network or for a transmit slot and sent nothing. - EntryRun sets a flag when a cancel reaches a request after its write-ahead. Only a time-limit stop with the flag takes a backoff step. Every other stop goes back to queued with no step. - TransferHost.send is split into withSlot and send. The attempt is written ahead inside the slot, so a wait for a slot counts no attempt. - stoppedByTimeout() becomes stopKind(). The foreground-service timeout counts as a time limit. Quota, standby, background restriction, device state and user stops write one persisted warning. API 29 and 30 cannot read stop reasons and keep the plain path. - A time-limit release with a wait of 30 s or less schedules no wake. The stopped row runs again and waits out the rest. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review fixes for "a system stop counts as a failed attempt only when it cut a request". - After every time-limit stop, schedule a fresh wake row (REPLACE, run count 0): at once after an idle stop, or at the backoff time after a cut request, also for a short wait. WorkManager 2.12.0 runs a stopped row again only after its own backoff, which grows with each start of that row (up to 5 hours), and schedule() adds no row while it waits. This drops the "no wake for a wait of 30 s or less" rule. - Write one diagnostic record per stop kind, with no entry id in the message, the latest entry id and a count in data, and the replace-if-untaken rule. Many stops can no longer push older warnings and errors out of the 50-record log. - Save the state change before the diagnostic record. - Record the slot's highPriority argument in FakeHost and test it. Remove TransferRequest.highPriority: nothing reads it now. - An in-worker backoff saves its step at once, so a stop during the wait keeps it. - A stop clears a nextAttemptAt that is already past. - Test a chunked part cut by a time-limit stop. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Follow-ups from the delta review. - A run that finds its entry queued with a wait too long to sleep out schedules the wake with KEEP. A wake lost to a failed enqueue or a process death is made again; a pending one stays. A release that saved the entry but failed to schedule its wake now logs that, not "could not release". - A chunked run checks that every pending part was accepted before it settles completed. A part that ended with its own CancellationException no longer lets the entry complete: the run throws PartsNotAcceptedException (an IOException), the entry goes back to queued with no outcome, and the worker returns retry. - Tests for the highest-part-streak rule and for a failed wake in an idle stop. - CHANGELOG: exact WorkManager backoff numbers, and the other stop kinds also wait for WorkManager's own backoff. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 18, 2026
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.
What was wrong
When Android stopped an upload job at its time limit, the library counted the stop as a failed send and added one backoff step. The wait grows with each step, up to 2 hours. It did this for every time-limit stop, also when the run sent nothing:
attempts + 1) before it took the slot, so this wait also counted one attempt.Smaller problems in the same code:
takeDiagnostics()could not show why a queue did not move.What changes
All changes are Android only.
EntryRunsets a flag when a cancel reaches a request after its write-ahead. On a time-limit stop with the flag set, the run takes one backoff step, as before. Every other stop moves the entry back toqueuedwith no backoff step.nextAttemptAtit still had. Both useREPLACEon<id>#wake, so the row's run count starts at 0. The reason: WorkManager 2.12.0 also runs the stopped row again, but only after its own backoff. That backoff doubles with each start of that row: by the 2.12.0 code it is 64 minutes at the 8th start and 128 minutes at the 9th, up to 5 hours. While that row waits,schedule()adds no row. Other stop kinds keep today's behavior: no new row, and the stopped row runs again when the system allows it and after WorkManager's own backoff.TransferHost.sendis split intowithSlotandsend.attempt()takes the slot first, then callsops.recordAttempt, then sends. A wait for a slot counts no attempt.TransferRequest.highPriorityis removed. The slot argument is now the only source of the priority.stoppedByTimeout()becomesstopKind(). The table below shows the mapping. On API 29 and 30,getStopReason()is not available (@RequiresApi(31)), so every stop maps toOTHER, which is today's path.run stopped by the system: QUOTA.dataholds the latestentryIdand acount. The record replaces its untaken copy, as the boot snapshot does, so many stops cannot push older records out of the 50-record log. The state change is saved before the record.nextAttemptAtthat is already past.queuedwith a wait too long to sleep out schedules the wake withKEEP. A wake lost to a failed enqueue or a process death is made again, and a pending one stays. Master had this gap too.completed, a chunked run checks every pending part. If a part ended with its ownCancellationExceptionwhile the run was not cancelled, the run throwsPartsNotAcceptedException(anIOException). The entry goes back toqueuedwith no outcome, and the worker returns retry. No production path to this case is known.The plan proposed no wake for a wait of 30 s or less, and the first commit built it. The review found that rule depends on WorkManager's backoff of the stopped row, so the second commit removes it.
TIMEOUTTIME_LIMITFOREGROUND_SERVICE_TIMEOUTTIME_LIMITTIMEOUTCONSTRAINT_CONNECTIVITYNETWORKqueued, never a failureQUOTA,APP_STANDBY,BACKGROUND_RESTRICTION,DEVICE_STATE,USERqueued, then one counted record per kindOTHERqueuedflowchart TD A[System stops the run] --> B{API 31 or later?} B -- no --> Q[Back to queued, no backoff step] B -- yes --> C{Stop reason} C -- network or other --> Q C -- quota, standby, restriction, device state, user --> Q2[Back to queued, no backoff step] --> W[Update the counted record for that kind] C -- time limit or FGS time limit --> D{Did the stop cut a request?} D -- yes --> S[One backoff step] --> K[Fresh wake row when the backoff ends] D -- no, it only waited --> I[Back to queued, no backoff step] --> N[Fresh wake row now, or at the nextAttemptAt still due]Files:
EntryRun.kt,TransferHost.kt,EntryWorker.kt,WorkerOps.kt,EntryTransitions.kt,ChunkedUploadWorker.kt,Diag.kt,DiagnosticLog.kt,UploadUtils.kt, tests,CHANGELOG.md. Main-chain rows, the transmit gate's rotation, the journal and iOS are unchanged.Behavior change
attempts, and theattemptfield of later attempt events, are lower for uploads that only waited for a slot. The number of attempt events does not change. That is the correct count.takeDiagnostics(). A record is written only when the run had already taken the entry.Tests
New or changed in
EntryRunTest, withFakeHostandFakeScheduler(which now records each wake'sreplaceargument):queued, streak 0, 0 attempts, one fresh wake row at once.a timeout stop takes one more backoff step instead of restarting at oncekeeps its original numbers: streak 2 to 3 and a fresh wake row at +4 s.attemptsand the cut request's id are kept.nextAttemptAt.KEEP. A wake lost after a time-limit release is made again by the stopped row's re-run, and the error record names the failed wake.queued, ends as a stop, and writes one error record.New
StopKindTest: each WorkManager constant has its documented value, and each maps to its kind.Each fix was broken on purpose and at least one test failed each time. Local runs:
yarn lint:ci,yarn typecheck,yarn test(305 passed), AndroidtestDebugUnitTest --no-daemon(445 passed),swift testinios/(383 executed, 1 skipped, 0 failures).Ships together with the change that makes a run with no foreground mode wait for the network on a constrained wake. Without it, an offline run with no foreground mode starts again at once after each stop.
Two independent reviews were applied. The WorkManager numbers come from reading the 2.12.0 classes.
🤖 Generated with Claude Code