v8 stack 3/5: Android durable journal and TurboModule conversion - #25
Closed
dmurphy5 wants to merge 1 commit into
Closed
v8 stack 3/5: Android durable journal and TurboModule conversion#25dmurphy5 wants to merge 1 commit into
dmurphy5 wants to merge 1 commit into
Conversation
UploaderModule now extends the generated NativeRNFileUploaderSpec and the
package registers it through BaseReactPackage with isTurboModule = true, so it
runs as a real TurboModule instead of a legacy module behind the interop shim.
Events go out through the generated emitters rather than RCTDeviceEventEmitter.
Terminal outcomes are journaled to disk before they are emitted, so an outcome
that lands while JS is dead is not lost — getUnacknowledgedEvents replays it
and ackEvents drains it. EventJournal is the store; UploadOutcome classifies a
response into a typed errorKind ('http', 'network', 'file') and honors a
request's acceptStatus instead of treating every non-2xx as a failure.
Two correctness fixes worth reviewing closely:
WorkManager decides whether to reschedule before it stops a worker and ignores
the Result the worker returns. The old code journaled a terminal cancel on
every stop, so a system stop — doze, low memory, constraint loss — looked
identical to a user cancel, and the rescheduled work then uploaded the same
file again. checkAndHandleCancellation now journals only when
UserCancellations.consume confirms the cancel came from JS.
cancelUpload used to resolve true unconditionally, having thrown a
fire-and-forget cancel at WorkManager. It now queries
getWorkInfosForUniqueWork, resolves false when nothing is active, and when the
work was still ENQUEUED — never started, so no worker will ever run to report
it — journals and emits the cancel itself.
Also: @volatile on the module instance, an identity check in invalidate so a
replacement module is not torn down by its predecessor, safeEmit distinguishing
a missing emitter from a real failure, a null guard on decoded journal entries,
and consumer ProGuard rules keeping the Signature attribute the Gson-persisted
models need under a host app's R8.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Jul 27, 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.
The stack
Five PRs, each based on the one before it. This is 3/5.
ai.openspacerenamemaster#22 stays open and untouched as the single-diff view of the same change.
Its tree and this stack's tip are byte-identical (tree
f8404b0), so mergingeither one produces exactly the same
master. Review whichever is easier tofollow; merge one and close the other.
Converts the Android module to a real TurboModule and makes terminal outcomes
durable.
UploaderModulenow extends the generatedNativeRNFileUploaderSpec, and thepackage registers it through
BaseReactPackagewithisTurboModule = true, soit runs as a TurboModule rather than a legacy module behind the interop shim.
Events go out through the generated emitters instead of
RCTDeviceEventEmitter.Terminal outcomes are journaled to disk before being emitted, so an outcome
that lands while JS is dead isn't lost —
getUnacknowledgedEventsreplays it andackEventsdrains it.EventJournalis the store;UploadOutcomeclassifies aresponse into a typed
errorKind(http,network,file) and honors arequest's
acceptStatusinstead of treating every non-2xx as a failure.The two fixes worth reviewing closely
A system stop was journaling a terminal cancel — and that caused duplicate
uploads. WorkManager decides whether to reschedule before it stops a worker,
and it ignores the
Resultthe worker returns. The old code journaled a cancelon every stop, so doze, low memory, or constraint loss looked identical to a user
cancel; the rescheduled work then uploaded the same file again.
checkAndHandleCancellationnow journals only whenUserCancellations.consumeconfirms the cancel came from JS.
cancelUploadalways resolvedtrue, having thrown a fire-and-forget cancelat WorkManager. It now queries
getWorkInfosForUniqueWork, resolvesfalsewhennothing is active, and when the work was still
ENQUEUED— never started, so noworker will ever run to report it — journals and emits the cancel itself.
Smaller hardening
@Volatileon the module instance; an identity check ininvalidateso areplacement module isn't torn down by its predecessor;
safeEmitdistinguishinga missing emitter from a real failure; a null guard on decoded journal entries;
and consumer ProGuard rules keeping the
Signatureattribute the Gson-persistedmodels need under a host app's R8 — without which a minified build fails
silently.
Verified
:react-native-background-upload:testDebugUnitTest— 15/15 pass (7 EventJournal,8 UploadOutcome). Exercised on a physical Android device inside Diana: field note
create online and offline, and update.