fix: return isolated copies from readLock cache#58
Conversation
readLock returned the cached object directly on cache hits but a shallow copy on first parse. Callers like removeLockEntry that delete keys from the result were mutating the internal cache. Align with readConfig which already returns copies consistently.
📝 WalkthroughWalkthroughModified Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/lockfile.ts`:
- Line 77: The current return in readLock (return { skills: { ...cached.skills }
}) only shallow-copies the skills map so SkillInfo objects remain shared; update
readLock to deep-clone each SkillInfo entry from cached.skills before returning
(e.g., iterate keys of cached.skills and clone each SkillInfo object and any
nested arrays/objects) so mutations to the returned skills do not affect
lockCache; reference the symbols readLock, SkillInfo, cached.skills, and
lockCache when implementing the deep clone.
🪄 Autofix (Beta)
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: 7ac130d9-d5c8-4a12-b2b5-f7d4b6fe9bb5
📒 Files selected for processing (2)
src/core/lockfile.tstest/unit/lockfile.test.ts
|
About coderabbit: Checked all |
readLockreturned the cachedSkilldLockdirectly on cache hits but a shallow copy on first parse.removeLockEntrydoesdelete lock.skills[name]on the result - on cached path, that mutated the internallockCachemap.readConfigin the same module already copies consistently. One-line fix to alignreadLockwith the same pattern, plus a test proving cache isolation across multiple reads.Summary by CodeRabbit