fix(harmony): 修复 UpdateContext 多实例状态分裂与版本重置问题#594
Conversation
- 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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesUpdateContext singleton and tracing
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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
harmony/pushy/src/main/ets/PushyTurboModule.tsOops! Something went wrong! :( ESLint: 8.57.1 Error: .eslintrc.js » harmony/pushy/src/main/ets/UpdateContext.tsOops! Something went wrong! :( ESLint: 8.57.1 Error: .eslintrc.js » 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
harmony/pushy/src/main/ets/UpdateContext.ts (1)
45-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake
UpdateContexta true singleton. The constructor is still public, so any futurenew UpdateContext(...)call can split the preferences cache again. Mark itprivateand keep instantiation behindgetInstance().🤖 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
📒 Files selected for processing (3)
harmony/pushy/src/main/ets/PushyFileJSBundleProvider.etsharmony/pushy/src/main/ets/PushyTurboModule.tsharmony/pushy/src/main/ets/UpdateContext.ts
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The branch was updated while autofix was in progress. Please try again. |
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The branch was updated while autofix was in progress. Please try again. |
# Conflicts: # harmony/pushy/src/main/ets/PushyTurboModule.ts
Committed at: 2026-06-30 20:05
Committed by: liuqiang
Summary by CodeRabbit