fix(opencode): serialize concurrent auth.json writes#7
Conversation
Ported from upstream anomalyco#36362.
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe auth layer now serializes concurrent ChangesAuth mutation safety
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
|
@coderabbitai full review |
✅ Action performedFull review finished. Your plan includes PR reviews subject to rate limits. More reviews will be available in 42 minutes. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/opencode/test/auth/auth.test.ts (1)
77-91: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winCover concurrent
set/removeinteraction.The production change locks both mutations, but this regression only protects
set/set. Add a mixed-operation test so removing the lock fromAuth.removecannot regress unnoticed.Proposed additional coverage
+ it.instance("set and remove are safe under concurrent calls", () => + Effect.gen(function* () { + const auth = yield* Auth.Service + yield* auth.set("anthropic", { type: "api", key: "k1" }) + + yield* Effect.all( + [ + auth.set("openai", { type: "api", key: "k2" }), + auth.remove("anthropic"), + ], + { concurrency: "unbounded" }, + ) + + const data = yield* auth.all() + expect(Object.keys(data)).toEqual(["openai"]) + }), + )🤖 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 `@packages/opencode/test/auth/auth.test.ts` around lines 77 - 91, Add a concurrent mixed-operation test alongside “set is safe under concurrent calls” that invokes Auth.Service set and remove operations together, then verifies the final auth data reflects the expected serialized outcome. Ensure the test would fail if Auth.remove no longer uses the shared mutation lock.
🤖 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.
Nitpick comments:
In `@packages/opencode/test/auth/auth.test.ts`:
- Around line 77-91: Add a concurrent mixed-operation test alongside “set is
safe under concurrent calls” that invokes Auth.Service set and remove operations
together, then verifies the final auth data reflects the expected serialized
outcome. Ensure the test would fail if Auth.remove no longer uses the shared
mutation lock.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 430da695-432d-470c-abaf-d278d35d3b41
📒 Files selected for processing (2)
packages/opencode/src/auth/index.tspackages/opencode/test/auth/auth.test.ts
Addresses CodeRabbit review finding on the anomalyco#36362 port.
e13584f to
8a3ba4b
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Port of upstream anomalyco/opencode#36362.
Wraps
Auth.set/Auth.removeread-modify-write cycles in a single-permit semaphore so concurrent OAuth refreshes cannot interleave and drop credentials from auth.json.Verified:
bun test test/auth/auth.test.ts(5 pass, includes new concurrency regression test) andbun typecheckfrom packages/opencode. Applied cleanly.Summary by CodeRabbit
Bug Fixes
Tests