Skip to content

fix: harden continuation resume guard - #215

Merged
hyochan merged 1 commit into
hyodotdev:mainfrom
offline-first:codex/harden-continuation-resume-guard
Jul 9, 2026
Merged

hyochan merged 1 commit into
hyodotdev:mainfrom
offline-first:codex/harden-continuation-resume-guard

Conversation

@offline-first

@offline-first offline-first commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • use CancellableContinuation.tryResume/completeResume in ContinuationResumeGuard so late callbacks cannot throw Already resumed
  • add a regression test for a late product-query failure after a continuation was already completed

Verification

  • env JAVA_HOME=/Users/arian/Library/Java/JavaVirtualMachines/jbr-17.0.14/Contents/Home ./gradlew :openiap:testPlayDebugUnitTest --tests dev.hyo.openiap.helpers.ContinuationResumeGuardTest --tests dev.hyo.openiap.QueryPurchasesRaceTest
  • env JAVA_HOME=/Users/arian/Library/Java/JavaVirtualMachines/jbr-17.0.14/Contents/Home ./gradlew :openiap:compileHorizonDebugKotlin :openiap:compileAmazonDebugKotlin

Summary by CodeRabbit

  • Bug Fixes
    • Improved coroutine completion handling so late or duplicate resume attempts are safely ignored.
    • Increased stability around asynchronous operations that may complete more than once.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1420122e-ffd2-4cca-b708-88bfacc14b69

📥 Commits

Reviewing files that changed from the base of the PR and between f628a9b and 7ab57ca.

📒 Files selected for processing (2)
  • packages/google/openiap/src/main/java/dev/hyo/openiap/helpers/ContinuationResumeGuard.kt
  • packages/google/openiap/src/test/java/dev/hyo/openiap/helpers/ContinuationResumeGuardTest.kt

📝 Walkthrough

Walkthrough

ContinuationResumeGuard's resume and resumeWithException methods are rewritten to use kotlinx.coroutines internal APIs (tryResume/tryResumeWithException with completeResume) instead of compareAndSet-guarded direct resume calls. A new unit test validates late/duplicate resume attempts after the continuation has already completed.

Changes

ContinuationResumeGuard resume rewrite

Layer / File(s) Summary
Guard implementation using internal completeResume APIs
packages/google/openiap/src/main/java/dev/hyo/openiap/helpers/ContinuationResumeGuard.kt
Imports switch to InternalCoroutinesApi, and resume/resumeWithException now use tryResume/tryResumeWithException with completeResume instead of compareAndSet plus direct resume/resumeWithException calls.
Late/duplicate resume test
packages/google/openiap/src/test/java/dev/hyo/openiap/helpers/ContinuationResumeGuardTest.kt
New test captures a CancellableContinuation, installs a resumeGuard, resumes normally, then attempts late guard resumes (exception and value) to verify no failure occurs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • hyodotdev/openiap#159: Introduces the ContinuationResumeGuard/resumeGuard mechanism itself, which this PR modifies internally.

Suggested labels: ⌚️ regression, 🛠 bugfix, 🧪 test

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change to harden the continuation resume guard against late completion issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors ContinuationResumeGuard to use Kotlin's InternalCoroutinesApi for resuming continuations, specifically utilizing tryResume and tryResumeWithException to safely handle atomic completion. Additionally, a new unit test file ContinuationResumeGuardTest.kt has been added to verify that late completions are ignored after a continuation is already resumed. No review comments were provided, and there is no further feedback.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@hyochan hyochan added 🤖 android Related to android 🛠 bugfix All kinds of bug fixes labels Jul 9, 2026

@hyochan hyochan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Android continuation guard change. No blocking findings: using tryResume/completeResume makes late external completions a no-op, and the new regression test covers the already-completed continuation path. Remote Android CI is green.

@hyochan
hyochan merged commit f085352 into hyodotdev:main Jul 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 android Related to android 🛠 bugfix All kinds of bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants