[claude] Fix crash on /sync-harmony when request scope already has project context - #2516
[claude] Fix crash on /sync-harmony when request scope already has project context#2516myieye wants to merge 1 commit into
Conversation
The /api/merge/sync-harmony handler ran the SyncWorker in the HTTP request scope, which the ProjectContextFromIdService middleware had already called SetupProjectContext on. The worker's own OpenCrdtProject then tried to set up a second (different) CrdtProject instance in the same scope and hit the reference-equality guard in CurrentProjectService.SetupProjectContext: "Can't setup project context for crdt when already in context of project crdt". Run the worker in its own DI scope, matching the queued sync path (SyncHostedService.ExecuteAsync), so the middleware's request-scoped context no longer collides. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 58 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: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
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 |
[Claude, autonomous]
POST /api/merge/sync-harmonythrowsInvalidOperationException: Can't setup project context for crdt when already in context of project crdt.The
ProjectContextFromIdServicemiddleware runs first on every request carryingprojectIdand (when the crdt file exists) callsSetupProjectContexton the request-scopedCurrentProjectService. The handler then ranSyncWorkerin that same request scope, so the worker'sOpenCrdtProjecttried to set up a second, differentCrdtProjectinstance and tripped the reference-equality guard. Both instances carry the hardcoded name"crdt", hence the self-referential-looking message.The queued path (
/execute→SyncHostedService.ExecuteAsync) never hits this because it runs the worker in a fresh scope. Fix:/sync-harmonynow does the same.Only reproduces on a previously-synced project (the middleware's
File.Existsgate) — i.e. exactly the "restore a reset project" case this endpoint serves.Test:
SyncWorkerTests.SyncHarmonyRoute_SucceedsWhenRequestScopeAlreadyHasProjectContextinvokes the real handler on a pre-populated request scope; it fails with the exact production exception on the old code and passes with the fix.