fix: enable Spock repair mode for service user creation#287
fix: enable Spock repair mode for service user creation#287rshoemaker wants to merge 2 commits intomainfrom
Conversation
Wrap service user role creation in a transaction with Spock repair mode enabled. This prevents "tuple concurrently updated" errors when the same user is being created on multiple instances simultaneously and Spock replicates the changes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactors service user role creation to retry the create flow on transient errors, perform all DDL and grant statements inside a transaction connected to the target database, enable Spock repair mode when available, and add explicit commit error handling. Changes
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
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 `@server/internal/orchestrator/swarm/service_user_role.go`:
- Around line 130-133: The call to postgres.IsSpockEnabled().Scalar silently
hides query errors because Scalar currently returns nil on row.Scan failures;
update the Scalar implementation in the postgres statement (the method that
implements Scalar on the Statement/Query type) so that any row.Scan error is
returned to the caller instead of nil, ensuring postgres.IsSpockEnabled().Scalar
propagates the scan/DB error back to the caller (so the existing error handling
in service_user_role.go around enabled, err := ... Scalar(ctx, tx) works as
intended).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c1ad74e6-e8db-4423-8957-d107629152ec
📒 Files selected for processing (1)
server/internal/orchestrator/swarm/service_user_role.go
Wrap createUserRole in a retry loop (3 attempts, exponential backoff) to handle transient "tuple concurrently updated" errors when multiple service user roles are created concurrently against the same Postgres instance. Also connect to the application database instead of "postgres" so that Spock repair mode is correctly enabled (Spock is installed per-database).
fix: resolve concurrent service user creation failures
Summary
Context
TestProvisionMultiHostMCPService was failing intermittently with:
ERROR: tuple concurrently updated (SQLSTATE XX000)
When a database has multiple MCP service instances (e.g., on host-1, host-2, host-3), each gets its own ServiceUserRole resource. These execute concurrently on the same Postgres instance, and their GRANT statements can conflict at the catalog level. The fix addresses this with two layers:
Verified with 30 consecutive test runs, 0 failures.
Test plan
PLAT-478