Skip to content

fix(harmony): 修复 UpdateContext 多实例状态分裂与版本重置问题#594

Merged
sunnylqm merged 3 commits into
reactnativecn:masterfrom
liusanhong:master
Jul 1, 2026
Merged

fix(harmony): 修复 UpdateContext 多实例状态分裂与版本重置问题#594
sunnylqm merged 3 commits into
reactnativecn:masterfrom
liusanhong:master

Conversation

@liusanhong

@liusanhong liusanhong commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
  • UpdateContext 改为单例模式,避免 bundle provider 与 TurboModule 各自持有 preferences 缓存导致读写分裂
  • binary 版本变更时不再 clearExisting,避免清除 uuid/firstLoadMarked/hash_* 等无关 KV,修复 isFirstTime 为 false 导致 markSuccess 永不执行
  • 增加 trace/logStateSnapshot 诊断日志,用于定位多实例与状态分裂问题
  • PushyFileJSBundleProvider 与 PushyTurboModule 统一改用 getInstance 单例

Committed at: 2026-06-30 20:05
Committed by: liuqiang

Summary by CodeRabbit

  • Bug Fixes
    • Improved app update state handling to make version changes more reliable, including safer reset/persistence behavior when updates detect a binary version change.
    • Added additional runtime state tracking to help prevent inconsistent update behavior during version switching and first-load handling.
  • Diagnostics
    • Enhanced runtime diagnostics during update initialization, bundle URL resolution, and constants retrieval to improve troubleshooting and overall startup reliability.

- UpdateContext 改为单例模式,避免 bundle provider 与 TurboModule 各自持有 preferences 缓存导致读写分裂
- binary 版本变更时不再 clearExisting,避免清除 uuid/firstLoadMarked/hash_* 等无关 KV,修复 isFirstTime 为 false 导致 markSuccess 永不执行
- 增加 trace/logStateSnapshot 诊断日志,用于定位多实例与状态分裂问题
- PushyFileJSBundleProvider 与 PushyTurboModule 统一改用 getInstance 单例

Committed at: 2026-06-30 20:05
Committed by: liuqiang

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 30, 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: a05f32b6-ec0a-4b7e-b56b-842c22f09c65

📥 Commits

Reviewing files that changed from the base of the PR and between 2648f6c and cb90854.

📒 Files selected for processing (2)
  • harmony/pushy/src/main/ets/PushyTurboModule.ts
  • harmony/pushy/src/main/ets/UpdateContext.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • harmony/pushy/src/main/ets/PushyTurboModule.ts
  • harmony/pushy/src/main/ets/UpdateContext.ts

📝 Walkthrough

Walkthrough

UpdateContext now exposes a shared instance and diagnostic snapshot logging. The bundle provider and turbo module use that shared instance, getConstants() records an entry snapshot and revised result log, and binary-version resets persist state without clearing existing preferences.

Changes

UpdateContext singleton and tracing

Layer / File(s) Summary
Singleton pattern and diagnostic API
harmony/pushy/src/main/ets/UpdateContext.ts
Adds singleton instance tracking, getInstance(), instanceId, trace(), and logStateSnapshot(), plus the logger import needed for tracing.
Caller updates and constants logging
harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets, harmony/pushy/src/main/ets/PushyTurboModule.ts
Replaces direct UpdateContext निर्माण with getInstance(), adds a getConstants() state snapshot, and changes the constants result log shape.
State tracing and reset behavior
harmony/pushy/src/main/ets/UpdateContext.ts
Adds trace calls around version switching, first-load marker consumption, bundle URL resolution, and current-version lookup; changes binary-version reset persistence to omit clearExisting.

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

Possibly related PRs

Poem

🐇 One shared context, bright and neat,
With traces hopping through the beat.
I sniff the state, then bound away,
And logs go мяг?—no, clear today!
A binky for the singleton tree.

🚥 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 标题准确概括了本次修复的核心:UpdateContext 单例化以避免多实例状态分裂,并修正版本重置逻辑。
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

harmony/pushy/src/main/ets/PushyTurboModule.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: .eslintrc.js » @react-native/eslint-config#overrides[4]:
Environment key "jest/globals" is unknown

at /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23
at Array.forEach (<anonymous>)
at ConfigValidator.validateEnvironment (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2073:34)
at ConfigValidator.validateConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2223:18)
at CascadingConfigArrayFactory._finalizeConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3985:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3791:21)
at FileEnumerator._iterateFilesWithFile (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
at FileEnumerator._iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
at FileEnumerator.iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)
at iterateFiles.next (<anonymous>)
harmony/pushy/src/main/ets/UpdateContext.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: .eslintrc.js » @react-native/eslint-config#overrides[4]:
Environment key "jest/globals" is unknown

at /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23
at Array.forEach (<anonymous>)
at ConfigValidator.validateEnvironment (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2073:34)
at ConfigValidator.validateConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2223:18)
at CascadingConfigArrayFactory._finalizeConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3985:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3791:21)
at FileEnumerator._iterateFilesWithFile (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
at FileEnumerator._iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
at FileEnumerator.iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)
at iterateFiles.next (<anonymous>)

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
harmony/pushy/src/main/ets/UpdateContext.ts (1)

45-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make UpdateContext a true singleton. The constructor is still public, so any future new UpdateContext(...) call can split the preferences cache again. Mark it private and keep instantiation behind getInstance().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@harmony/pushy/src/main/ets/UpdateContext.ts` at line 45, UpdateContext is not
a true singleton because its constructor is still publicly accessible, allowing
additional instances to bypass the shared preferences cache. Make the
constructor in UpdateContext private and keep all creation logic inside
getInstance() so every caller receives the same instance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@harmony/pushy/src/main/ets/UpdateContext.ts`:
- Around line 69-80: The trace() method in UpdateContext is logging the
persisted uuid directly in the info-level diagnostic output, which should be
avoided. Update the logger call inside trace() so it no longer emits the raw
value from readString('uuid'); instead log only a redacted form or a
presence/absence indicator while keeping the rest of the snapshot details
unchanged.

---

Nitpick comments:
In `@harmony/pushy/src/main/ets/UpdateContext.ts`:
- Line 45: UpdateContext is not a true singleton because its constructor is
still publicly accessible, allowing additional instances to bypass the shared
preferences cache. Make the constructor in UpdateContext private and keep all
creation logic inside getInstance() so every caller receives the same instance.
🪄 Autofix (Beta)

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bcfca33d-b4e5-4908-8530-ffe11d3322bc

📥 Commits

Reviewing files that changed from the base of the PR and between efe638e and 2648f6c.

📒 Files selected for processing (3)
  • harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets
  • harmony/pushy/src/main/ets/PushyTurboModule.ts
  • harmony/pushy/src/main/ets/UpdateContext.ts

Comment thread harmony/pushy/src/main/ets/UpdateContext.ts
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

⚠️ Branch updated during autofix.

The branch was updated while autofix was in progress. Please try again.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

⚠️ Branch updated during autofix.

The branch was updated while autofix was in progress. Please try again.

@sunnylqm sunnylqm merged commit 4a5fa6f into reactnativecn:master Jul 1, 2026
1 check passed
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.

2 participants